DEV Community

GUIDANCE WHITE
GUIDANCE WHITE

Posted on Edited on

[CVE-2026-114938] Java4Shell Deep Dive - How a Single '=' Turns Into a 64-Byte Heap Overflow

On November 17, 2026, security firm Calif disclosed a memory-corruption vulnerability in OpenJDK's Base64 decoder that can escalate to pre-authentication remote code execution. It's called Java4Shell, tracked as CVE-2026-114938. CISA issued a same-day alert urging immediate patching.

This post walks through why a single trailing = character turns into a 64-byte out-of-bounds write, building up from the Base64 and AVX-512 basics you need.

TL;DR

  • Root cause: HotSpot's hand-written AVX-512 VBMI assembly stub for java.util.Base64 decoding miscalculates the output size for a short padded tail, underflowing it to -1. That -1 gets read as 255 by the bzhiq instruction, which turns the "write 0 bytes" mask into "write all 64 bytes" — spilling into the next heap object.
  • Affected: OpenJDK 17.0.6+ and the 18–27 line on unpatched builds, only on x86-64 CPUs with AVX-512 VBMI (Intel Ice Lake+, AMD Zen 4+)
  • Severity: CVSS 4.0 9.2 (Calif), CVSS 3.1 8.1 (Oracle, high attack complexity)
  • CWE: Not yet assigned. Closest fit is an integer underflow (CWE-191) leading to an out-of-bounds write (CWE-787).
  • Fix: JDK-8393212, committed under embargo on Oct 14 as the deliberately bland "Base64 optimization improvements," released Nov 17.
  • Status: No in-the-wild exploitation reported as of Nov 17. RCE has only been demonstrated by Calif in specific products; no weaponized chain is public.
Scope Status Notes
OpenJDK 17.0.6 – 17.0.21 Vulnerable Fixed in 17.0.21.1
OpenJDK 21 / 25 / 27 Vulnerable Fixed in 21.0.13.1 / 25.0.5.1 / 27.0.1.1
Oracle Java SE 8 Enterprise Performance Pack Vulnerable Uses a 17-based VM; 8u511-perf → 8u513-perf
≤17.0.5, standard Java 8 / 11 Not affected No AVX-512 decode stub exists
ARM64 (Graviton, Apple Silicon, etc.) Not affected The x86 stub is never generated
x86-64 without AVX-512 VBMI (Skylake-SP, Cascade Lake, pre-Zen4 AMD) Not affected The vulnerable tail logic lives only in the VBMI path
18–20, 22–24, 26 (end-of-life) No fix planned Move to a supported line

1. Background: Base64 padding

Base64 turns 3 bytes into 4 characters. When the input isn't a multiple of 3 bytes, = padding is appended so the total length is always a multiple of 4.

Input Encoded Padding
Man (3 bytes) TWFu 0
Ma (2 bytes) TWE= 1
M (1 byte) TQ== 2

The required output size is:

output bytes = (char count ÷ 4) × 3 − padding count
Enter fullscreen mode Exit fullscreen mode

The key fact: valid Base64 is always a multiple of 4 characters long. This bug's trigger is a length that is not a multiple of 4 but still ends in = — an input that should be rejected outright. The problem is it gets rejected after the vulnerable write already happened.

2. Background: JIT intrinsics and AVX-512 masked stores

Intrinsics: "hot methods get replaced with hand-tuned assembly"

java.util.Base64.Decoder.decode0() calls decodeBlock() internally. Once that method gets hot enough, HotSpot's C2 compiler swaps out the Java bytecode for a hand-written assembly stub — an intrinsic. Any server that decodes Base64 continuously (auth headers, JWTs, file uploads) will hit this state quickly.

The stub is only generated on CPUs with both AVX-512 VBMI and BW support. Otherwise the slower-but-safe scalar Java path is used. The MIME decoder always uses the scalar path, regardless of CPU.

AVX-512: "64 bytes at a time"

AVX-512 registers are 512 bits — 64 bytes. The stub decodes input 64 characters at a time.

Masked stores: "a stencil with only some holes punched"

When writing results to memory, the stub provides a 64-bit mask alongside the data. Only bytes where the mask bit is 1 get written; bytes where it's 0 are left untouched — like a stencil where only some holes are cut.

The mask is built from "number of bytes to write" via bzhiq, which keeps the low N bits and zeroes the rest. Critically, bzhiq only reads the low 8 bits of its index, and if that value is 64 or higher, nothing gets cleared at all.

bzhiq index Resulting mask Meaning
3 low 3 bits set write 3 bytes
0 all zero write nothing
255 (low byte of -1) all 64 bits set write all 64 bytes

That last row is the entire bug.


3. The vulnerable flow

Per public write-ups, the chain looks like this:

  1. java.util.Base64$Decoder.decode0() calls decodeBlock()
  2. Once hot, C2 swaps in the HotSpot-generated stub (generate_base64_decodeBlock in stubGenerator_x86_64.cpp)
  3. Entry gate: avx512_vbmi && avx512bw, plus UseAVX=3 and UseBASE64Intrinsics=true (both defaults on qualifying CPUs)
  4. Input is processed in 256-char, then 64-char chunks
  5. The remaining 1–63 character tail is handled at label L_finalBit, finishing with a masked store

Step 5 is where it breaks. Below is a reconstructed pseudocode for understanding the flow — not literal assembly; exact registers and ordering vary by build.

// The 64-char-chunk passes are done; a 1–3 char tail (including "=") remains
int out_size = (tail_len / 4) * 3;          // tail < 4 chars, so this is 0
out_size -= padding_count;                  // subtract '=' count → 0 - 1 = -1 (underflow)

uint64_t mask = bzhi(~0ULL, out_size & 0xFF);   // only low 8 bits used: -1 → 255
masked_store_64B(dst, decoded_vector, mask);    // mask is all-ones → full 64-byte write
Enter fullscreen mode Exit fullscreen mode

A tail with 0 bytes to write should produce a mask of all zeros. Instead, subtracting padding underflows the size to -1, bzhiq reads that as 255, and the mask stays all-ones. The result is the exact opposite of intent: a full 64-byte write.

Walking the numbers: "A"×64 + "=" (65 characters)

Step What happens Value
① Java pre-computes the output array size 3 × ⌈65/4⌉ − 1 = 50 bytes
② The 64-char chunk decodes normally 64 ÷ 4 × 3 = 48 bytes written (up to offset 48)
③ Remaining 1-char = tail hits L_finalBit tail length 1
④ Output size computed 0 − 1 = −1
⑤ bzhiq index low 8 bits of −1 = 255 → mask all-ones
⑥ 64-byte masked store, starting at offset 48 48 + 64 = 112
⑦ Compared against array end (50) 62 bytes land past the array, in the next heap object
⑧ Input validation finally rejects it IllegalArgumentException — but the write already happened

Reports place the overflow at 62 bytes for a = tail and 63 bytes for a == tail. The same logic applies to a 3-char A== tail: output size becomes 0 − 2 = −2, giving index 254 — mask still all-ones.

Diagram 1 walkthrough

  1. ① Crafted input: The payload is "64 valid chars + =" sent somewhere the server Base64-decodes before authentication (a Basic auth header, SAML assertion, upload field, etc.). Length 65 isn't a multiple of 4, so it should be rejected outright.
  2. ② JIT handoff: The vulnerable path only exists once decodeBlock is hot enough for C2 to swap in the assembly stub — which is why an attacker warms the server up with valid Base64 first.
  3. ③ Tail miscalculation: the four boxes trace the chain: a 1-char = tail → output size 0 − 1 = -1 → bzhiq index 255 → mask all 64 bits set. The code box below condenses this to three lines.
  4. ④ Out-of-bounds write: the bar shows blue for the 48 valid output bytes, a dashed line for the 50-byte array boundary, and red for the 62 bytes that spill past it. The masked store starts at offset 48 and writes 64 bytes, so 48 + 64 = 112 — 62 bytes beyond the array.
  5. ⑤ Result: on its own, this corrupts the next object's header and typically crashes the JVM during garbage collection (denial of service). RCE is what Calif claims to have built per-product on top of this primitive.

4. Trigger conditions: not every = input qualifies

Several conditions have to line up to actually reach the vulnerable tail logic:

  • Length threshold: the vector path only engages above a certain length.
    • 17u: above 128 characters. For a =-terminated 1–3 char tail, valid lengths are 64k+1 to 64k+3 (k ≥ 2) — i.e. 129–131, 193–195, 257–259…
    • 21 / 25 / 27: threshold is 31 bytes, so 65 characters (one full 64-char block plus a short padded tail) is enough.
  • Decoder type: Basic or URL decoder only. MIME always takes the scalar path.
  • Valid characters: any = or invalid character inside a 64-char chunk bails out to the Java path early, so every character before the tail must be valid Base64.
  • Warm-up: the stub must already be JIT-compiled.

Because valid encoders never produce lengths like these, this input pattern simply doesn't show up in normal traffic. Unpadded Base64 (like JWT segments) doesn't end in = either, so it's distinguishable from that too.


5. The fix: keep short tails out of the vector path entirely

The patch adds a single length check at the top of L_finalBit:

+    // A padded Base64 tail shorter than one complete block is handled by Java.
+    __ cmpl(length, 4);
+    __ jcc(Assembler::less, L_bruteForce);
Enter fullscreen mode Exit fullscreen mode

If fewer than 4 characters remain, execution jumps to L_bruteForce — the scalar (Java) path. The important detail is that this check runs before the output-size and mask computation.

  • A tail of 4+ characters gives a starting size of (length ÷ 4) × 3 ≥ 3
  • Padding subtracts at most 2, so size is always ≥ 1
  • So the bzhiq index is always in valid range
  • A tail made entirely of = fails validation anyway and falls to the scalar loop

This is a minimal fix for the one underflow — it doesn't touch whether the vector path correctly decodes every 4–63 character tail otherwise.


6. Exploitation: what's public, and what isn't

What the bug gives you on its own

  • The spilled bytes are a fixed value, independent of attacker-controlled data. The attacker can influence where the write lands (via length and heap layout), not what gets written.
  • The overflow corrupts the next object's header, typically crashing the JVM with a SIGSEGV during GC. Standalone, this is a pre-auth denial of service.

Calif's claimed path to code execution

Calif states there's no universal exploit — each target needs its own work. The publicly described outline has five stages:

  1. Corrupt one array's length, so the application's own subsequent writes into it go out of bounds with attacker-chosen bytes
  2. Corrupt a second array that gets echoed back in a response, leaking heap memory (Calif calls this "JavaBleed")
  3. Repair the damaged object headers so the JVM keeps running
  4. Groom the heap remotely into a usable layout
  5. Steer the resulting writes at the JVM's Code Cache

Every target needs its own decoder entry point, a writable buffer, a readable feedback channel, a workable heap layout, and the right application behavior — which is why the claimed impact is product-specific. Calif says it demonstrated pre-auth RCE against default configurations of Keycloak, Jira, Confluence, Artifactory, Jenkins, and PingFederate, and post-auth RCE against Kafka, Solr, Elasticsearch, Gerrit, and Spinnaker. No shell code or weaponized chain has been published, and this post does not reconstruct one. There are also reports that a Java client making a TLS connection to a malicious server can be exposed.


7. Checking your exposure

All four conditions must be true for the vulnerable path to actually execute:

  1. x86-64 CPU with AVX-512 VBMI (Windows x64 gets the same generated code)
  2. An affected, unpatched build
  3. UseAVX=3 and UseBASE64Intrinsics=true (defaults on qualifying CPUs)
  4. Attacker input reaches java.util.Base64's Basic or URL decoder

/proc/cpuinfo doesn't exist outside Linux, and an empty result can look misleadingly "safe." Ask the JVM itself instead — and check each binary separately if a host runs more than one Java install:

java -Xlog:os+cpu -version 2>&1 | grep -oE 'avx512f|avx512bw|avx512_vbmi|bmi2' | sort -u
java -XX:+PrintFlagsFinal -version 2>/dev/null | grep -E ' (UseAVX|UseBASE64Intrinsics) '
Enter fullscreen mode Exit fullscreen mode

If all four CPU features show up and UseAVX = 3, UseBASE64Intrinsics = true, that JVM is exposed. Products like Jenkins, Jira, Confluence, Keycloak, and Elasticsearch often bundle their own JRE, so check the actual running process, not just java -version:

jcmd <PID> VM.version
Enter fullscreen mode Exit fullscreen mode

Diagram 2 walkthrough

  1. ① Four exposure conditions: CPU, version, flags, and input reachability all have to line up. Miss any one (ARM, a non-VBMI CPU, the MIME decoder) and the vulnerable path never runs.
  2. ② The patch: adding cmpl(length, 4) and jcc(less, L_bruteForce) keeps 1–3 character tails out of the vector path entirely. With 4+ characters, the output size is always at least 1, so the bzhiq index stays in valid range.
  3. ③ Response priority: patch first (17.0.21.1 / 21.0.13.1 / 25.0.5.1 / 27.0.1.1, or any vendor build containing JDK-8393212). If that's not immediate, -XX:-UseBASE64Intrinsics disables the stub (just restart the JVM; Base64 decoding gets slower). The last resort is -XX:UseAVX=2, which disables AVX-512 entirely — a bigger performance hit, and it won't let the JVM start on ARM.
  4. ④ Detection signals: input patterns, logs, and crash dumps — detailed in Section 8.

8. Mitigation and detection

Patch

Distribution Fixed build
OpenJDK / Oracle Java SE 17.0.21.1, 21.0.13.1, 25.0.5.1, 27.0.1.1
Oracle Java SE 8 EPP 8u513-perf
Amazon Corretto 17.0.21.1.2, 21.0.13.1.2, 25.0.5.1.2, 27.0.1.1.4

Release timing and version labels vary by vendor — check each vendor's own advisory for the actual fixed build. If you build from source, confirm JDK-8393212 is in your tree; a distro package whose version number looks current can still predate the fix. After patching, rebuild container images, restart every Java process, and confirm the running build with jcmd.

Stopgap mitigation before patching

Not an official Oracle workaround, but widely recommended. Requires a JVM restart; for containers, set it in the image or pod spec (JAVA_TOOL_OPTIONS).

Flag Impact Notes
-XX:-UseBASE64Intrinsics Low Base64 decoding falls back to Java, runs slower. Try this first.
-XX:UseAVX=2 High Also works (VBMI decoder never gets built), but disables all AVX-512 optimizations. JVM won't start on ARM.
-XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_base64_decodeBlock Low Requires the diagnostic-options flag alongside it to work.

Since the vulnerable decode happens pre-auth, network ACLs or a VPN in front of the service are also effective. Input size limits are not: the trigger is as short as 65 characters on newer lines — shorter than a typical Basic auth value or JWT.

Detection signals

  • The input itself: Base64 ending in = with a length that isn't a multiple of 4. On 17u, length mod 64 being 1–3 while ending in = is a tighter signal; on mixed fleets, use 65 characters as the floor.
  • Logs: a spike in java.util.Base64 throwing IllegalArgumentException from request-handling code (the trigger always throws after the write).
  • Responses: unusually large or binary-looking responses from endpoints that normally echo back decoded input.
  • Crashes: repeated hs_err files showing a SIGSEGV inside a GC copy routine with a compiled Base64$Decoder.decode0 frame on the stack — especially clustered by source IP, since a failed heap-grooming attempt crashes the JVM and the attacker retries.
  • Traffic: high-frequency Base64-decode-triggering requests from a single source (the warm-up and precise heap-grooming phases).

Top comments (0)