Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When Java source code is compiled, it is converted into bytecode, saved in one or more class files, and executed by the Java Virtual Machine (JVM). Java class files may be compiled on one machine and executed on another machine. A properly - generated class file is said to be conforming. When the JVM loads a class file, it has no way of knowing if whether the class file is conforming. The class file could have been created by some other process, or a malicious hacker could tamper an attacker may have tampered with a conforming class file.

The Java bytecode verifier is an internal component of the JVM and that is responsible for detecting non-conforming nonconforming Java bytecode. It ensures that the class file is in the proper Java class format, that illegal type casts are not performed, and operand stack overflows or underflows can not occuravoided, that operand stack underflows are impossible, and that each method eventually removes from the operand stack everything pushed by that method.

Users often assume that Java class files that have been obtained from a trustworthy source will be conforming and, consequently, safe for execution. They might then misconstrue This belief can erroneously lead them to see bytecode verification as a superfluous activity in for such cases andclasses. Consequently, they may might disable bytecode verification, severely undermining Java's safety and security guarantees. The bytecode verifier must not be suppressed.

Noncompliant Code Example

The bytecode verification process is automatically initiated unless the runs by default. The -Xverify:none flag is specified on the JVM command line that invokes suppresses the JVMverification process. This  This noncompliant code example uses this the flag to disable bytecode verification.:

Code Block
bgColor#FFcccc

java -Xverify:none ApplicationName

Compliant Solution

Bytecode Most JVM implementations perform bytecode verification happens by default in most JVM implementations. Bytecode verification ; it is also performed automatically when a class loader loads a class dynamically.during dynamic class loading.

Specifying If a JVM has bytecode verification disabled, the -Xverify:all flag can be specified on the command line requires the JVM to enable bytecode verification (even when it would otherwise have been suppressed), as shown in this compliant solution.:

Code Block
bgColor#ccccff

java -Xverify:all ApplicationName

Exceptions

ENV10ENV04-J-EX1EX0: On Java 2 systems, classes that are loaded by the primordial class loader (that loads classes is permitted to omit bytecode verification of classes loaded from the boot class path) are not required to perform bytecode verification. These system classes are protected through platform and file system protections rather than by the bytecode verification process.

Risk Assessment

Code that is not subject to bytecode verification can bypass security checks that are normally expected to be performed by Java code.

Bytecode verification ensures that the bytecode contains many of the security checks mandated by the Java Language Specification. Omitting the verification step could permit execution of insecure Java code.

Rule

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

ENV10

ENV04-J

high

High

likely

Likely

low

Low

P27

L1

Automated Detection

TODO

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this guideline on the CERT website.

Bibliography

Wiki Markup
\[[Oaks 2001|AA. Bibliography#Oaks 01]\] The Bytecode Verifier
\[[Pistoia 2004|AA. Bibliography#Pistoia 04]\] Section 7.3, The Class File Verifier

Static checking of this rule is not feasible in the general case.

Android Implementation Details

Under the default settings, bytecode verification is enabled on the Dalvik VM. To change the settings, use the adb shell to set the appropriate system property: for example, adb shell setprop dalvik.vm.dexopt-flags v=a or pass -Xverify:all as an argument to the Dalvik VM.

Bibliography

[Oaks 2001]

"The Bytecode Verifier"

[Pistoia 2004]

Section 7.3, "The Class File Verifier"


...

Image Added Image Added Image AddedENV09-J. Limit remote uses of JVM Monitoring and Managing      01. Runtime Environment (ENV)      02. Platform Security (SEC)