Skip to content

Commit

Permalink
Fix potential security exploit in generated Java classes
Browse files Browse the repository at this point in the history
  • Loading branch information
wsfulton committed Aug 2, 2015
1 parent 130834a commit a1771cb
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
15 changes: 15 additions & 0 deletions CHANGES.current
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.7 (in progress)
===========================

2015-08-02: wsfulton
[Java] Fix potential security exploit in generated Java classes.
The swigCPtr and swigCMemOwn member variables in the generated Java
classes are now declared 'transient' by default. Further details of the exploit
in Android is being published in an academic paper as part of USENIX WOOT '15:
https://www.usenix.org/conference/woot15/workshop-program/presentation/peles.

In the unlikely event that you are relying on these members being serializable,
then you will need to override the default javabody and javabody_derived typemaps
to generate the old generated code. The relevant typemaps are in the Lib directory
in the java.swg, boost_shared_ptr.i and boost_intrusive_ptr.i files. Copy the
relevant default typemaps into your interface file and remove the 'transient' keyword.

*** POTENTIAL INCOMPATIBILITY ***

2015-07-30: wsfulton
Fix #440 - Initialise all newly created arrays when using %array_functions and %array_class
in the carrays.i library - bug is only relevant when using C++.
Expand Down
22 changes: 11 additions & 11 deletions Doc/Manual/Java.html
Original file line number Diff line number Diff line change
Expand Up @@ -2390,8 +2390,8 @@ <H3><a name="Java_proxy_classes"></a>25.4.3 Java proxy classes</H3>
<div class="code">
<pre>
public class Foo {
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected Foo(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand Down Expand Up @@ -2641,8 +2641,8 @@ <H4><a name="Java_inheritance_mirroring"></a>25.4.3.2 Inheritance</H4>

<div class="code"><pre>
public class Base {
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected Base(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand Down Expand Up @@ -2682,7 +2682,7 @@ <H4><a name="Java_inheritance_mirroring"></a>25.4.3.2 Inheritance</H4>

<div class="code"><pre>
public class Derived extends Base {
private long swigCPtr;
private transient long swigCPtr;

protected Derived(long cPtr, boolean cMemoryOwn) {
super(exampleJNI.SWIGDerivedUpcast(cPtr), cMemoryOwn);
Expand Down Expand Up @@ -2960,8 +2960,8 @@ <H4><a name="Java_multithread_libraries"></a>25.4.3.5 Single threaded applicatio

<div class="code"><pre>
public class Test {
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected Test(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand Down Expand Up @@ -3034,7 +3034,7 @@ <H3><a name="Java_type_wrapper_classes"></a>25.4.4 Type wrapper classes</H3>

<div class="code"><pre>
public class SWIGTYPE_p_int {
private long swigCPtr;
private transient long swigCPtr;

protected SWIGTYPE_p_int(long cPtr, boolean bFutureUse) {
swigCPtr = cPtr;
Expand Down Expand Up @@ -5900,8 +5900,8 @@ <H3><a name="Java_code_typemaps"></a>25.9.9 Java code typemaps</H3>
<div class="code">
<pre>
%typemap(javabody) SWIGTYPE %{
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand Down Expand Up @@ -5929,7 +5929,7 @@ <H3><a name="Java_code_typemaps"></a>25.9.9 Java code typemaps</H3>
<div class="code">
<pre>
%typemap(javabody) SWIGTYPE *, SWIGTYPE &amp;, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
private long swigCPtr;
private transient long swigCPtr;

protected $javaclassname(long cPtr, boolean bFutureUse) {
swigCPtr = cPtr;
Expand Down
8 changes: 4 additions & 4 deletions Examples/test-suite/java_typemaps_proxy.i
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import java.lang.*; // for Exception

// Create a new getCPtr() function which takes Java null and is public
%typemap(javabody) NS::Greeting %{
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand All @@ -46,8 +46,8 @@ import java.lang.*; // for Exception

// Make the pointer constructor public
%typemap(javabody) NS::Farewell %{
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

public $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand Down
2 changes: 1 addition & 1 deletion Examples/test-suite/java_typemaps_typewrapper.i
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import java.lang.*; // for Exception
// Create a new getCPtr() function which takes Java null and is public
// Make the pointer constructor public
%typemap(javabody) Farewell * %{
private long swigCPtr;
private transient long swigCPtr;

public $javaclassname(long cPtr, boolean bFutureUse) {
swigCPtr = cPtr;
Expand Down
8 changes: 4 additions & 4 deletions Lib/java/boost_intrusive_ptr.i
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@

// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private transient long swigCPtr;
private boolean swigCMemOwnBase;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
Expand All @@ -278,7 +278,7 @@

// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private transient long swigCPtr;
private boolean swigCMemOwnDerived;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
Expand Down Expand Up @@ -413,7 +413,7 @@

// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private transient long swigCPtr;
private boolean swigCMemOwnBase;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
Expand All @@ -428,7 +428,7 @@

// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private transient long swigCPtr;
private boolean swigCMemOwnDerived;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
Expand Down
6 changes: 3 additions & 3 deletions Lib/java/boost_shared_ptr.i
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@

// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private boolean swigCMemOwn;
private transient long swigCPtr;
private transient boolean swigCMemOwn;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand All @@ -160,7 +160,7 @@

// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private transient long swigCPtr;
private boolean swigCMemOwnDerived;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
Expand Down
8 changes: 4 additions & 4 deletions Lib/java/java.swg
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%define SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
protected boolean swigCMemOwn;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
Expand All @@ -1163,7 +1163,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {

// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private transient long swigCPtr;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGUpcast(cPtr), cMemoryOwn);
Expand All @@ -1179,7 +1179,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%define SWIG_JAVABODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Typewrapper classes
%typemap(javabody) TYPE *, TYPE &, TYPE &&, TYPE [] %{
private long swigCPtr;
private transient long swigCPtr;

PTRCTOR_VISIBILITY $javaclassname(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
Expand Down

0 comments on commit a1771cb

Please sign in to comment.