# CVE-2026-114938 ("Java4Shell") — Vulnerability Description

**Class:** Integer underflow leading to out-of-bounds heap write (CWE-191/122) in HotSpot's
AVX-512 Base64 decode intrinsic.

**Affected:** OpenJDK / Oracle JDK 17.0.6–17.0.21 (introduced by commit `8268276`,
Nov 2022, first shipped 17.0.6 GA Jan 2023). The same code exists in the 21 and 25 lines.
**Not affected:** Java 8 and 11 (no Base64 intrinsic), ARM CPUs, x86 CPUs without AVX-512
VBMI+BW (pre-Ice Lake Intel / pre-Zen 4 AMD), MIME decoders (different code path).

**Impact:** Unauthenticated, no user interaction. Any attacker-controlled input reaching a
basic or URL-safe `java.util.Base64` decoder — HTTP Basic auth headers, JWTs, data URIs,
SAML, cookies — can corrupt the JVM heap remotely. The written bytes are the
decoded/permuted stream: attacker-influenced but constrained, so the realistic outcome is
JVM crash / DoS; RCE possible in principle but unproven. No exploitation in the wild
reported as of Nov 17, 2026.

**Fixed in:** Oracle/OpenJDK November 17, 2026 CSPU builds (e.g. 17.0.21.1, 21.0.13.1).
Apply the patched build and restart every JVM.

**Interim mitigation:** `-XX:-UseBASE64Intrinsics` (falls back to the pure-Java decoder,
which is not affected).

**Status caveat:** Version range (OpenJDK 17.0.6+), CVSS 4.0 score 9.2, and the
CVE-to-component mapping originate from early, partially unconfirmed reports
(watchTowr / Datadog / Equixly; attributed secondhand to Korea's NCSC). The root cause
below was independently verified against the OpenJDK `jdk17u` source; Oracle's official
risk matrix was not yet published at the time of writing.

---

## Root cause

The Java caller passes the untrimmed range to the intrinsic (`decode0` → `decodeBlock`,
`Base64.java:814`), so the AVX-512 stub's tail handler can receive a 1–2 byte fragment
ending in the padding character `=`. In that case `output_size = 3*(len/4)` is 0; seeing
the `=`, the padding branch decrements it to **-1**. The negative size is passed to a BZHI
instruction used to build the store mask; BZHI with index ≥ 64 returns the source unmasked,
so the mask becomes **all 64 bits** instead of zero/error. Meanwhile the `=` byte has been
masked out of the input load, so the stub's own error check never fires. The 64-byte
masked store then executes — but the destination array is sized 2 bytes short of that
position (`decodedOutLength`, `Base64.java:737`), so **~62 bytes are written past the end
of the heap array**, before any Java-side validation runs.

## Vulnerable code — `src/hotspot/cpu/x86/stubGenerator_x86_64.cpp` @ `jdk-17.0.21-ga`

```cpp
// L_finalBit: tail fragment, 1..63 bytes remain
6177:  __ BIND(L_finalBit);
6184:  __ bzhiq(rax, rax, length);        // input mask: low `length` bits
6186:  __ movl(output_size, length);
6187:  __ shrl(output_size, 2);            // len/4   -> 0 when tail is 1..3 bytes
6188:  __ lea(output_size, Address(output_size, output_size, Address::times_2, 0));
                                           // output_size = 3*(len/4) = 0

6194:  __ jcc(Assembler::equal, L_padding); // last tail byte is '='

6271:  __ BIND(L_padding);
6272:  __ decrementq(output_size, 1);      // * UNDERFLOW: 0 -> -1 (never checked for <0)
6273:  __ shrq(rax, 1);                    // * masks '=' out of the input load
                                           //   -> error check below never sees the pad char
6276:  __ jcc(Assembler::notEqual, L_donePadding);

6196:  __ BIND(L_donePadding);
6202:  __ bzhiq(output_mask, output_mask, output_size);
                                           // * BZHI with index >= 64 returns src unchanged
                                           //   -> output_mask = 0xFFFFFFFFFFFFFFFF (all 64 bits)

6228:  __ evmovdqub(input_initial_valid_b64, input_mask, Address(source, start_offset, ...), true, ...);
                                           // loads only the masked ('='-free) bytes -> passes error check

6249:  __ evmovdqub(Address(dest, dp), k1, tmp, true, Assembler::AVX_512bit);
                                           // * k1 = all-ones -> writes ALL 64 bytes at dst+dp,
                                           //   but dst has only 2 bytes left -> ~62 bytes OOB
6251:  __ addptr(dest, output_size);      // also returns length -1 to the caller
```

## Caller side — `src/java.base/share/classes/java/util/Base64.java` @ `jdk-17.0.21-ga`

```java
 814:  int dl = decodeBlock(src, sp, sl, dst, dp, isURL, isMIME);
       // full untrimmed range sp..sl — tail may be 1-2 bytes, reaching the stub's L_finalBit

 700:  private int decodedOutLength(byte[] src, int sp, int sl) {
 ...
 737:  return 3 * (int) ((len + 3L) / 4) - paddings;
       // dst sized by this — for a 1-2 byte '=' tail it ends exactly 2 bytes
       // past dp, so the 64-byte store runs ~62 bytes past the array end
```

## Enabling commit — `8268276` (backport `07050b000c`, first shipped in 17.0.6)

```cpp
+  __ BIND(L_finalBit);                       // tail handling introduced here
+  __ movl(output_size, length);
+  __ shrl(output_size, 2);                   // (len/4)*3, no floor guard for len<4
+  ...
+  __ BIND(L_padding);
+  __ decrementq(output_size, 1);             // can go negative — same code as today
```

## Failure chain

`len%4 < 4` -> `output_size = 0` -> `=` tail decrements it to **-1** -> BZHI(-1) silently
yields an **all-ones mask** -> 64-byte store where dst has **2 bytes** of room ->
**~62 bytes of heap corruption**, attacker-influenced decoded bytes, before any Java-side
validation runs.

## Version boundary (verified from `jdk17u` git history)

- `jdk-17.0.5-ga` -> `jdk-17.0.6-ga`: 280 commits, 587 files, +46,359/−5,087 lines.
- The AVX-512 Base64 **decode** intrinsic entered the 17 line in this window:
  `8268276` (12 files, +749/−18; 657-line assembly stub), authored Nov 9, 2022.
- 17.0.5 does not contain the code; the code path is absent. Last clean 17.x = 17.0.5.

## Recommended actions

1. Inventory every JVM (incl. JDKs bundled in apps/containers): `java -version`.
2. Apply the November 17, 2026 CSPU build (or your OpenJDK vendor's fixed build) and
   **restart every JVM** — runtime bug, restart mandatory.
3. Where patching must wait, set `-XX:-UseBASE64Intrinsics` on internet-facing JVMs.
4. Restrict internet exposure of Java services until patched.
