Java4Shell: OpenJDK Base64 Intrinsic RCE Vulnerability

Overview

A critical vulnerability, dubbed "Java4Shell," has been identified in the OpenJDK HotSpot JVM that allows for remote code execution (RCE) through a heap buffer overflow in the Base64 decoding intrinsic. The flaw is triggered by malformed Base64 data processed on x86-64 systems utilizing AVX-512 instructions, leading to an out-of-bounds memory write that can be weaponized for heap manipulation and arbitrary code execution.

Technical Root Cause

The vulnerability resides in the x86-64 Base64 intrinsic used by the C2 JIT compiler. When the input length is less than 64 bytes, the JVM uses the evmovdqub instruction to process data. A logic error in the calculation of the output mask—specifically when handling Base64 padding characters—causes an underflow that results in an output_mask of -1u64.

This incorrect mask forces the evmovdqub instruction to write 64 bytes of data regardless of the actual buffer size, leading to an out-of-bounds write past the allocated heap buffer. On OpenJDK 17 and newer, this path is reachable with specifically crafted malformed input, such as 128 bytes of data followed by a padding character.

Exploitation and Impact

While the vulnerability provides a fixed-byte out-of-bounds write, researchers have demonstrated that it can be upgraded to a powerful exploitation primitive. By employing "Heap Feng Shui" to groom the JVM heap, an attacker can position sensitive objects—such as array lengths or object references—adjacent to the vulnerable buffer.

Corrupting these objects allows for:

  • Heap Disclosure: Creating a "reader" primitive to leak PII, private keys, or session tokens.
  • Arbitrary Write: Upgrading the fixed write into a bounded, chosen-value write to corrupt JVM internal structures, eventually leading to code execution in the Code Cache or via JVM hooks.

Exploitation is highly environment-dependent, requiring specific heap layouts and network conditions. It is not a "point-and-shoot" exploit and requires a bespoke profile for each target application.

Affected Systems and Requirements

Java4Shell affects OpenJDK versions 17.0.6 and newer. Because the vulnerability is tied to hardware-specific optimizations, it is limited to:

  • Architecture: x86-64 processors.
  • Hardware: CPUs supporting AVX-512 with VBMI (e.g., Intel Ice Lake/Sapphire Rapids, AMD Zen 4 or newer).
  • Runtime: JVMs using the HotSpot engine (including Oracle JDK, Amazon Corretto, Eclipse Temurin, and others).

ARM64-based systems and JVMs that do not utilize the affected intrinsic are not vulnerable.

Mitigation and Remediation

Users are advised to apply the official security patches released by OpenJDK and Oracle immediately. If patching is not immediately feasible, the following JVM flags can be used to disable the vulnerable code path:

  • -XX:-UseBASE64Intrinsics: Disables hardware-accelerated Base64 encoding/decoding.
  • -XX:UseAVX=2: Disables AVX-512 support on x86-64 hosts (note: this flag is not recognized by ARM versions and will cause startup failures).

Security researchers note that while these mitigations are effective, they may impact performance for applications heavily reliant on Base64 processing. Additionally, using a proxy to buffer and sanitize request bodies can provide a layer of defense by preventing the delivery of the malformed payloads required to trigger the vulnerability.

Sources

Related