Skip to content
Memory corruption Write-up Advanced

Java4Shell: RCE in OpenJDK when processing Base64

An out-of-bounds write exists in OpenJDK's x86-64 Base64 intrinsic when decoding malformed input ending in padding, letting an attacker overwrite heap memory. With heap grooming the authors turned this into a heap disclosure and, in some applications, remote code execution.

calif.io

Published on calif.io

Story by the New York Times

The author, on calif.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the padded-tail handling subtracts padding from an already-zero output length, underflowing it so the store mask becomes all-ones and a full 64-byte write occurs.

Impact

An attacker could leak heap contents such as keys and tokens, and in several tested applications achieve remote code execution, though exploitation needs a bespoke profile per target and is sensitive to network conditions; nginx request buffering can block some chains.

What the attacker needed

X86-64 CPU with AVX-512 VBMI; OpenJDK 17.0.6 or newer; attacker can send Base64 input; application-specific exploit profile

How it was found

  1. Warm up the Base64 decoder with valid input until the JIT compiles it and the vulnerable intrinsic is used.
  2. Optionally rehearse a safe round to calibrate timing against the target.
  3. Send the malformed input ending in padding so the fixed spill enlarges the writer buffer.
  4. Continue writing through the enlarged writer to enlarge a reader buffer and collect leaked heap bytes from the response.
  5. Repair damaged objects using the disclosed originals to keep the JVM running.
  6. Perform the application-specific action and verify it through a live request.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Java normally manages memory for you, but some speed-critical parts are written in low-level code that can write past the end of a buffer. Here a fast Base64 decoder (Base64 turns binary data into text) miscounts how many bytes to write when the input ends in padding characters, so it spills extra bytes into neighbouring memory. An attacker who can send such input may be able to read or corrupt other data in the program.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.