Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Information Security
18 min read

Java4Shell: Critical RCE in JDK Base64 Intrinsic on AVX-512 CPUs

Analysis of CVE-2026-114938 (Java4Shell), a critical remote code execution vulnerability in Oracle JDK and OpenJDK 17.0.6+ on x86-64 CPUs with AVX-512VBMI, caused by a bounds-check bypass in the Base64 decoding intrinsic, enabling heap overflow, memory leakage (JavaBleed), and RCE in default configurations of Keycloak, Jira, Jenkins, and other Java applications.

Overview

On November 17, security research group Calif disclosed CVE-2026-114938, dubbed Java4Shell . The vulnerability allows an attacker to send a 65-character Base64 payload to a Java application, triggering a heap buffer overflow in the JVM's Base64 decoding intrinsic. This leads to reading tokens and private keys, and ultimately remote code execution. Oracle and OpenJDK released patches the same day, and CISA issued an immediate remediation advisory.

Affected Versions and Hardware Requirements

The vulnerability only affects JVM builds version 17.0.6 and later that include the AVX-512VBMI Base64 intrinsic (added in JDK 18 via JDK-8268276 and backported to Java 17). The following conditions must all be met:

JDK version: Oracle JDK 17.0.6–17.0.21, 21.0.13 and earlier, 25.0.5 and earlier, 27.0.1 and earlier (corresponding fixed versions: 17.0.21.1, 21.0.13.1, 25.0.5.1, 27.0.1.1).

Architecture: x86-64 with AVX-512VBMI support (Intel Ice Lake or later Xeon, AMD Zen 4 or later EPYC/Ryzen). Cloud instances such as AWS c6i, m6i, c7i, c7a, m7a are affected.

Attacker-controlled Base64 data reaches java.util.Base64 decoder.

Java 8, 11, and ARM64 (e.g., AWS Graviton) are not affected because they lack this intrinsic.

Root Cause: Intrinsic Bounds-Check Bypass

HotSpot replaces frequently used Java methods with hand-written assembly stubs called intrinsics . The Base64 decoder uses an AVX-512VBMI stub that processes 64 bytes per instruction. The bounds check is performed in Java code, but the assembly stub writes directly to memory without knowing the actual destination array size.

The bug occurs in the tail-handling logic when the input length is not a multiple of 4. For a 65-character payload (64 'A' + '='), the decoder calculates an output buffer of 50 bytes ( ceil(65/4)*3-1). After processing the first 64 characters, the remaining '=' triggers the tail logic. Due to a signed integer underflow ( output_len becomes -1), the store mask becomes all ones, causing the stub to write 64 bytes starting at offset 48 — overflowing the 50-byte array by 62 bytes.

// HotSpot x86-64 Base64 intrinsic tail handling, simplified pseudocode
// bzhiq(src, n): keep low n bits of src; n >= 64 returns src unchanged
uint64_t input_mask = bzhiq(~0ULL, input_len); // input_len = 1
int output_len = (input_len / 4) * 3; // 1/4*3 = 0
if (input[input_len - 1] == '=') {
  output_len -= 1; // 0 - 1 = -1, signed underflow
  input_mask >>= 1;
  if (input[input_len - 2] == '=') {
    output_len -= 1;
    input_mask >>= 1;
  }
}
// -1 as uint64_t is 0xFFFF..., far larger than 64, bzhiq does no truncation
uint64_t output_mask = bzhiq(~0ULL, output_len); // result all ones
// mask all ones means write 64 bytes, not 0
evmovdqub(Address(dest, dp), k1 /* == output_mask */, tmp, true, AVX_512bit);

The write starts at dest + 48 and writes 64 bytes, but the array is only 50 bytes long — a fixed 62-byte overflow ( 64 - (50 - 48)). After the overflow, the stub detects invalid input and returns early; the Java layer throws

IllegalArgumentException: Input byte array has wrong 4-byte ending

. The exception masks the fact that adjacent heap objects have already been corrupted.

Exploitation Chain: From Fixed Overflow to JavaBleed and RCE

Initially the overflow appears limited to fixed bytes (bytes 48-63 are always 0x9a). However, by overwriting the length field of an adjacent array, attackers turn it into a controlled writer . A second array's length is then corrupted to become a reader , leaking heap contents — tokens, private keys, sessions, PII. Calif named this step JavaBleed .

With read/write primitives, attackers repair corrupted objects to avoid JVM crashes, then target Code Cache and JVM hooks for arbitrary code execution. The exploit requires Heap Feng Shui to position target objects after the buffer, using TLAB leftovers, G1 region allocation, and chunked HTTP bodies.

Not a single payload works everywhere. Keycloak, Jira, Confluence, Artifactory, Jenkins, and PingFederate are vulnerable in default configurations without authentication. Kafka, Solr, Elasticsearch, Gerrit, Spinnaker require authentication first. Each product needs a tailored exploit chain. A client-side variant also exists: a Java program connecting via TLS to a malicious server can be compromised without opening any ports.

Detection and Verification

Three command groups to check exposure:

# 1. Process executable, JVM version, and startup flags
readlink -f /proc/<PID>/exe
jcmd <PID> VM.version
jcmd <PID> VM.command_line

# 2. Check intrinsic and AVX flags
jcmd <PID> VM.flags -all | grep -E 'UseBASE64Intrinsics|UseAVX'

# 3. Verify CPU flags (all four required)
grep -m1 '^flags' /proc/cpuinfo | tr ' ' '
' | grep -E '^(avx512f|avx512bw|avx512vbmi|bmi2)$'

All four flags present indicates a vulnerable CPU (Ice Lake+ Intel or Zen4+ AMD). If the version is vulnerable but the CPU lacks flags, the intrinsic is not used. For custom OpenJDK builds, check for fix commit JDK-8393212.

Reproduction Test

The following Java program triggers the overflow on a vulnerable JVM. It first warms up the decoder (≈20,000 calls) to ensure C2 compilation with the intrinsic, then sends the malicious payload.

import java.util.Base64;

public class Base64TailCheck {
  public static void main(String[] args) {
    // JDK 21/25/27 use 64 'A'; JDK 17 requires 128
    String payload = "A".repeat(64) + "=";
    // Warm up decoding path so C2 compiles intrinsic version
    byte[] valid = Base64.getEncoder().encode(new byte[48]); // 64 chars, valid
    for (int i = 0; i < 20_000; i++) {
      Base64.getDecoder().decode(valid);
    }
    try {
      // Overflow occurs inside this call; exception thrown after memory corruption
      Base64.getDecoder().decode(payload);
    } catch (IllegalArgumentException e) {
      System.out.println("Exception: " + e.getMessage());
      System.out.println("Note: exception only means input rejected; 62 bytes already written on heap");
    }
  }
}

Run again with -XX:-UseBASE64Intrinsics — the exception still occurs but no overflow happens. Absence of a crash does not prove safety; corrupted object headers may cause failures later during GC.

Mitigations

Patching

Fixed versions per Oracle's schedule:

Oracle JDK 17: 17.0.21.1

Oracle JDK 21: 21.0.13.1

Oracle JDK 25: 25.0.5.1

Oracle JDK 27: 27.0.1.1

Third-party distributions (Temurin, Zulu, Corretto, Liberica, SapMachine) have varying release timelines; check vendor advisories. Container images must be rebuilt; changing JAVA_HOME alone is insufficient because the vulnerable JRE layer remains in the image.

Workarounds (if patching not immediately possible)

# Disable only the Base64 intrinsic (minimal impact; may require unlocking diagnostic options)
JAVA_TOOL_OPTIONS="-XX:+UnlockDiagnosticVMOptions -XX:-UseBASE64Intrinsics"

# Fallback: force AVX2 on x86-64 (do not use on ARM64)
JAVA_TOOL_OPTIONS="-XX:UseAVX=2"

These flags bypass the vulnerable code path but do not eliminate the underlying bug; patching is still required.

Input Validation

Add a strict character-level check before any Base64 decoding. This validation must not call Base64.decode itself, or the attack surface returns.

// Pure character validation: length multiple of 4, '=' only at end, max two
public static boolean looksLikeBase64(String s) {
  if (s == null || s.isEmpty() || s.length() % 4 != 0) return false;
  int pad = 0;
  for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (c == '=') {
      pad++;
      if (i < s.length() - 2) return false; // '=' appears too early
    } else if (pad > 0) {
      return false; // characters after '='
    } else if (!(
        (c >= 'A' && c <= 'Z') ||
        (c >= 'a' && c <= 'z') ||
        (c >= '0' && c <= '9') ||
        c == '+' || c == '/'
    )) {
      return false; // non-Base64 character
    }
  }
  return pad <= 2;
}

Apply at entry points: Basic Auth headers, JWT (base64url uses - and _ instead of + / /), file upload Base64 fields, etc. This is defense-in-depth; it cannot block all vectors (multipart, WebSocket, SAML may bypass).

Detection Signatures

Monitor for:

Base64 tokens not a multiple of 4, ending with =, length > 32.

The exact error message:

IllegalArgumentException: Input byte array has wrong 4-byte ending

. hs_err_pid*.log files containing SIGSEGV.

Container exits with code 134 (SIGABRT) and unexpected JVM restarts.

Unknown child processes spawned by java or anomalous outbound connections.

WAF or nginx request buffering is not a reliable solution; Calif's Elasticsearch chain uses a single complete request, and WebSocket bypasses body buffering entirely.

Author's Assessment

The key lesson: Java memory safety guarantees only apply to Java code, not to the JVM itself. JIT, intrinsics, FFM, JNI — performance-oriented escape hatches — are the most valuable attack surface and are enabled by default.

Calif reported using AI to find the vulnerability in one hour and build the first exploit chain in two hours, costing under $200 in token usage. This low cost means rapid weaponization after patch release; relying on secrecy of exploit chains is futile.

Recommended immediate actions: inventory all running JVMs, prioritize identity and supply-chain systems (Keycloak, Jira, Confluence, Artifactory, Jenkins), apply patches where possible, otherwise add -XX:-UseBASE64Intrinsics and restart, and deploy the input validation at all decoding entry points. Teams on AVX-512 hardware running Java 17+ should act tonight.

Vulnerability illustration
Vulnerability illustration

For attribution, corrections or content rights, contactadmin@besthub.dev

Report an issue with this article

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion