The Tail of Base64
By Quang Luong
On affected OpenJDK builds, malformed Base64 data can logic a constant-value overwrite of allocated heap memory. Through distant Heap Feng Shui, we rotate that overwrite into a heap leak and distant code execution.
Discovery
A few months back, I was evolving a 0-click utilize on a certain phone vendor. The bug was constrained: it is a linear out-of-bounds compose and we have no way to bypass ASLR. I nearly considered it unexploitable until I audited the Android Runtime. Turns out, it has several predictable recollection allocation form and if you align the registers from the starting recollection misconduct fair correct you can create the runtime construe attacker's bytecode.
After completing that utilize chain, inspired (and bored), I decided to appearance into several item entirely different. So I pulled the authoritative JVM implementation (OpenJDK HotSpot) and started auditing. Java is a mature platform, so I was conscious that having a "good" bug current would be hard, but I wanted to provision it my finest attempt anyway.
Recalling my before instruction that complex systems and code crossing multiple boundaries are difficult to get right, I focused the audit on the JIT compiler, intrinsics, extensively accessible APIs, and cryptography. Well, additional precisely, I told Codex to appearance at those areas akin any grave safety investigator in 2026. To be honest, I didn't anticipate to discover item trivially exploitable, perchance lone several logic flaws or side-channel issues.
Most first results Codex brought me were slops, either unreachable or the necessity of exploitation is not realistic at all. This looks akin a wager I am going to lose. But you cognize what, fortune favors the bold. So I fair prompted harder...
Eventually, Codex brought me a finding for a recollection misconduct in the Base64 decoder itself. I came looking for copper and established gold, through sheer persistence. But wait, is it really gold, or fair fool's gold?
The vulnerability
The matter lies in OpenJDK HotSpot's x86-64 Base64 intrinsic. C2 is the most assured JIT compiler in the Java Virtual Machine. Specifically, if you trigger a function repeatedly, afterward it volition compile that function into native code. Even then, average native code itself is not accelerated enough. Modern CPUs have specialized instructions that authorize handling data equal faster. HotSpot uses them in optimized routines called intrinsics. The x86-64 Base64 intrinsic miscalculated the padded tail's shop mask, causing an out-of-bounds write.
The x86-64 Base64 intrinsic iterates through the input in 256-byte blocks; if it is small than 256, afterward it volition do so in 64-byte blocks. When the input is small than 64 bytes, it uses evmovdqub, the intrinsic for the VMOVDQU8 instruction. This education takes a 64-bit disguise that decides which bytes are peruse from or written to memory. The disguise is archetypal calculated from the input and output length, afterward updated to indicate the figure of padding bytes ('=') in the Base64-encoded string. This is shown in the following (pseudocode):
// Zero High Bits Starting alongside Specified Bit Position input_mask := bzhiq(-1, input_length) output_len := (input_length / 4) * 3 // grip padding if input[input_length - 1] == '=': output_len -= 1 input_mask >>= 1 if input[input_length - 2] == '=': output_len -= 1 input_mask >>= 1 output_mask := bzhiq(-1, output_len)
In the complete code, if the remaining input is of the form =, ==, X=, X==, XY=, or ===, afterward output_len volition be computed as zero. However, since there is padding, output_len is decremented, resulting in an underflowed value of -1 or -2. Since bzhiq(-1, output_len) doesn’t alter any bits if output_len >= 64, this results in output_mask == -1u64.
Later the code uses evmovdqub to peruse and compose multiple bytes at a time. For a write, if the disguise bit is 1, the byte at that indicator in the vector enroll is written to memory. So whenever output_mask == -1u64, all 64 bytes are written during the following operation:
evmovdqub( Address(dest, dp) /* Address: destination location addr */, k1 /* k1 == output_mask */, tmp /* XMMRegister src register/value to compose */, true, Assembler::AVX_512bit /* vector dimension */ );
The generated stub returns the figure of bytes it successfully decoded, and returns first whenever it detects invalid input. The remaining bytes are handled by the Java code, which throws IllegalArgumentException if the input is invalid.
At runtime, the decoded buffer dimension is calculated as (ceil(inp_len / 4) * 3) - padding. When the bug is triggered, alongside 65 bytes ([64 bytes] + '=') as input, that calculation allocates a 50-byte buffer. During decoding the bug makes output_mask == -1 for evmovdqub, so 64 bytes are written starting at offset 48, an out-of-bounds compose former the end of the buffer.
On OpenJDK 17, the trigger input is 'A' * 128 + '=' alternatively of 'A' * 64 + '=', since the dimension threshold to attain the code way is higher.
Exploitation strategy
The Base64 bug was gold, but not the category that sits on the riverbed waiting to be panned out. It was the category that was deep, dark, and difficult to access. While we had recollection corruption, exploiting it looked difficult, perchance equal borderline unexploitable, since it lone wrote fixed bytes to the heap. Only the landing stance of the out-of-bounds compose is controllable.
We get the following 64 bytes compose starting from the stance in buffer anywhere the remaining sets of Base64 decoded bytes would have been written to:
- Full controlled compose to byte 0 (in bound)
- 4-bit controlled compose to byte 1 (in bound)
- Uncontrolled compose to bytes [2, 63]. For bytes 48..63, the value volition continually be 0x9a.
The uncontrolled out-of-bounds compose turned out not to be a big problem. We reused a average JavaScript motor exploitation primitive, the traditional method of overwriting a buffer length.
We call the buffer whose dimension we overwrite the writer. Once its dimension is corrupted, it keeps accepting our chosen bytes, so if we location another gathering or entity following it, we can corrupt that neighbor alongside all of our chosen values. That upgrades the fixed compose into a bounded, chosen-value linear write.
If we afterward corrupt another array's dimension and its data is copied rear into the response, we have built a heap disclosure primitive, the reader, from the out-of-bounds read. At this point, before any code execution, we already had JavaBleed, the capability to leak contents from the Java heap, which may clasp PII, personal keys, another concealed keys, and tokens.
From the author and reader, the remainder of this write-up builds the complete attack. We repair the objects the linear compose damaged to keep the JVM running, mount data-only attacks on use logic, and escalate the bounded compose into arbitrary writes that attain the Code Cache and JVM hooks for code execution.
But archetypal things first, we need to align the heap to our advantage.
Heap Feng Shui (Grooming)
G1 divides the heap into fixed-size regions. Before the area arithmetic matters, the crucial arrays have to depart their threads' personal allocation ranges.
HotSpot normally gives all Java thread a thread-local allocation buffer (TLAB), a personal piece of Eden. Objects created by distinct petition threads advancement distinct cursors, which gives us no helpful command between a Base64 decoder in one TLAB and a author in another.
The archetypal grooming tier controls the allocation route. The crucial array's size and the area remaining in the worker's TLAB decide whether HotSpot refills that TLAB or takes the attacker-preferred outside-TLAB allocation path.
The second tier controls the layout. However, we do not choose how G1 allocates memory, and we don't cognize the current heap state. To method this limitation, Calif used the tried and tested method of Spray and Pray.
Object sizes and padding fix offsets inner region-sized spans. We spray multiple live author and audience pairs to provision the decoder output multiple imaginable neighbors. When its area lands immediately below a author region, the widened audience produces a larger use response. We discard misses and retry until successful.
One first difficulty during utilize betterment was that the AI would get stuck during heap grooming primitive development. In command to preserve tokens and time, Calif wrote a small heap tracer and visualizer to provision the delegate data concerning the heap state, blended alongside our ability on particular cases.
Remote Heap Feng Shui
In command to execute distant grooming, all petition data would be sent up until the crucial heap allocation would occur. By ensuring the data that was earlier sent had a TCP acknowledgement, the utilize would have authority complete the allocations up to date. Once we were assured our data so far is buffered on the target, we afterward sent the rest, completing the http request. This allows the two heap allocation authority and additional exact agenda as delivering small network packets is additional stable than big ones.
The exact allocation and liberated command agenda belongs to the targeted use profile, during we are capable to authority the adding, writer, reader, and decoder pieces.
The current assault is delicate to network conditions, akin RTT and jitter. Low, stable round-trip times are preferred for a additional dependable attack. In our controlled environment, we performed this assault complete the net through community IP addresses alternatively of fair assuming ideal lab conditions. For the current assault way to accomplish optimal stability and reliability in exploitation, Calif turned to discipline and used prosperity to resolve the problem, fairly than experimenting alongside TCP/IP stack configuration. In another words, Calif rented another VM in the identical area as our target.
Warm-up, rehearsal, and retries
To summarize the sequence so far, we volition heated up the Base64 decoder to C2 tier. We can rehearse the utilize run to calibrate timing and responses against the mark before causing misconduct to occur. Once the required data has been obtained, we can trigger the vulnerability. Incorrect placement could logic the JVM to crash, but in many instances, we can merely try again.
WARMRun valid decodes until the JIT selects the affected accelerated path. No recollection is corrupted.
REHEARSEOptional harmless circular for calibration.
TRIGGERSend the malformed tail. If the objects row up, the fixed spill enlarges the writer.
DISCLOSEContinue the author so chosen bytes enlarge the reader, afterward collect the response-derived heap bytes.
REPAIRUse the disclosed originals to reconstruct impermanent headers and untouched neighbors whenever the sequence has a repair path.
FINISHMake the application-specific alter and verify it through a live request.
Limitations
Request streaming. Some current grooming profiles need partial petition bodies to attain the application. A proxy that waits for the complete build removes their publish timing. nginx buffers petition bodies by default.
Request buffering is not a broad mitigation. Elasticsearch runs from one complete request, so this environment does not halt that chain. After a configured WebSocket upgrade, afterward frames continue through a tunnel and request-body buffering no longer applies to them.
Application profiles. There is no worldwide payload. Each sequence needs a decoder route, a live writer, a returned audience or another feedback path, a heap layout, and an use action. Every mark needs a bespoke profile. The utilize is not a worldwide point-and-shoot.
PoC
Here is a self-contained evidence of concept. It warms the Base64 decoder until the susceptible intrinsic is used, afterward decodes the malformed 64 × "A" + "=" input into a 4096-byte array. On an affected JDK it prints REPRODUCED: the decoder rejects the input, but 62 bytes (offsets 50 to 111) former the decoded output have already been overwritten. Every compose lands inner a genuine array, so the trigger is harmless to run.
import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Base64; /** Bounded standalone trigger: all compose stays inner a genuine 4096-byte array. */ public final category Base64Trigger { personal fixed volatile int sink; community fixed void main(String[] args) { Base64.Decoder decoder = Base64.getDecoder(); byte[] valid = "A".repeat(64).getBytes(StandardCharsets.US_ASCII); byte[] malformed = ("A".repeat(64) + "=").getBytes(StandardCharsets.US_ASCII); byte[] mark = new byte[4096]; for (int i = 0; i < 200_000; i++) { descend += decoder.decode(valid, target); } Arrays.fill(target, (byte) 0x5a); boolean rejected = false; try { decoder.decode(malformed, target); } capture (IllegalArgumentException expected) { rejected = true; } int changed = 0; int archetypal = -1; int final = -1; for (int i = 50; i < target.length; i++) { if (target[i] != (byte) 0x5a) { changed++; if (first < 0) archetypal = i; final = i; } } System.out.println("runtime=" + System.getProperty("java.runtime.version")); System.out.println("vm=" + System.getProperty("java.vm.name")); System.out.printf("rejected=%s changed=%d first=%d last=%d%n", rejected, changed, first, last); if (!rejected || changed != 62 || archetypal != 50 || final != 111) { System.err.println("NOT REPRODUCED"); System.exit(1); } System.out.println("REPRODUCED"); } }We are holding rear the application-specific exploits for now. This write-up covers the exposure and the broad exploitation technique. The weaponized chains for idiosyncratic products remain personal until everyone has had a chance to upgrade. We volition publish them later.
Affected products
Java4Shell affects OpenJDK from type 17.0.6 or newer.
Because they are built from OpenJDK, the following Java distributions are additionally vulnerable:
- Amazon Corretto
- Eclipse Temurin
- Microsoft Build of OpenJDK
- Azul Zulu
- BellSoft Liberica
- SAP SapMachine
- Red Hat OpenJDK
- Oracle OpenJDK
- Oracle Java SE
- Oracle GraalVM for JDK
According to Oracle, the following Oracle Java SE versions are vulnerable: 8u511b33-perf, 17.0.21.0.3, 21.0.13.0.3, 25.0.5.0.3, 27.0.1.0.3. We appreciate Oracle for providing this data onward of publish time.
Because the susceptible code is hardware-specific, Java4Shell additionally requires an x86-64 processor alongside AVX-512 VBMI support. ARM64 CPUs are not affected.
These mainstream CPU families encounter the hardware requirements:
- Intel Xeon: Ice Lake, Sapphire Rapids, Emerald Rapids, Granite Rapids
- AMD EPYC and Ryzen: Zen 4 or newer
On Linux, you can inspect whether your CPU is susceptible alongside this command:
grep -m1 '^flags' /proc/cpuinfo | tr ' ' '\n' | grep -E '^(avx512f|avx512bw|avx512vbmi|bmi2)$'
The output must contain all four flags.
Recommendations
OpenJDK released a safety advisory and Oracle released a patch at 1:00pm PT on Nov 17, 2026.
All Java users should update immediately.
You can additionally mitigate Java4Shell by starting OpenJDK alongside either:
- -XX:-UseBASE64Intrinsics to disable hardware-accelerated Base64 encoding and decoding, or
- -XX:UseAVX=2 to disable AVX-512. Apply this emblem lone on x86-64 hosts. OpenJDK on ARM doesn't acknowledge it and volition neglect to start.
Credits
Research, write-up and exploits by Quang Luong.
Exploit betterment by Jenish Rakholiya.
Artwork by Michal Zalewski.