Wiki Markup |
---|
Native methods are defined in Java and written in traditional languages such as C and C++ \[[JNI 2006|AA. Bibliography#JNI 06]\]. The added extensibility comes at the cost of flexibility and portability asbecause the code no longer conforms to the policies enforced by Java. In the past, native methods were used for performing platform -specific operations, interfacing with legacy library code, and improving program performance \[[Bloch 2008|AA. Bibliography#Bloch 08]\]. Although this is no longer completely true --- because of poor portability, security, and (ironically) performance issues --- native code is still used to interface with legacy code. |
Defining a wrapper method facilitates installing appropriate security manager checks, performing input validation before passing the arguments to the native code or when obtaining return values, defensively copying mutable inputs, and sanitizing untrusted data. As a result Consequently, every native method must be private , and must be invoked only by a wrapper method.
...
This example includes the doOperation()
wrapper method, which invokes the nativeOperation()
native method but fails to provide input validation or security checks.
...
This compliant solution declares the native method private. The doOperation()
wrapper method performs routine permission checking to determine whether the succeeding operations are permitted to continue. The method also creates a defensive copy of the mutable input array data
, as well as performs performing range checking of the arguments. The nativeOperation()
method is consequently called with safe inputs. Note that the validation checks must produce outputs that conform to the input requirements of the native methods.
...
SEC08-EX00: Native methods that do not require security manager checks, validation of arguments or return values, defensively or defensive copying of mutable inputs do not need to be wrapped — for example, (the standard C function int rand(void)
, for example).
Risk Assessment
Failure to define wrappers around native methods can allow unprivileged callers to invoke them and consequently exploit inherent vulnerabilities such as those resulting from invalid inputs.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9f567d8135b7345b-ba997ba4-4b9d4200-808f9b5e-b9cc1ba78ee5cb2d211f0768"><ac:plain-text-body><![CDATA[ | [[Fairbanks 2007 | AA. Bibliography#Fairbanks 07]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9d9dc7a7fdfdbf36-ab735486-4b2b4056-aa39aaaa-698942413ad25188539a0512"><ac:plain-text-body><![CDATA[ | [[JNI 2006 | AA. Bibliography#JNI 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8241dca3f376b287-7bc0293d-468446ea-aa1f8612-7c8ef758fd281665f3050d5d"><ac:plain-text-body><![CDATA[ | [[Liang 1997 | AA. Bibliography#Liang 97]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d4f1eae370cf3006-396f3020-41a44836-8831b335-0e67c7f2645743e2a1948629"><ac:plain-text-body><![CDATA[ | [[Macgregor 1998 | AA. Bibliography#Macgregor 98]] | Section 2.2.3, Interfaces and Architectures | ]]></ac:plain-text-body></ac:structured-macro> |
...