Writing past the end of an array with a Base64 string: how CVE-2026-114938 turns into code execution

Next up: le coupable idéal
Every few years the industry picks a usual suspect. For the longest stretch it was PHP: the
language we loved to perp-walk, the one where a single ?cmd= and a sloppy include handed you a
webshell and everyone nodded along: of course it was PHP. We practically built a genre around it.
php2shell. The perfect culprit. Easy to arrest, easy to convict.
But if you’ve seen the documentary that lends this section its title, you know the trap: the obvious suspect, the one who looks guilty, is the one the whole system railroads, while the real killer walks out the front door because nobody could believe someone that respectable did it. So after all the years we spent squinting at PHP, let me put the next defendant in the line-up. The one with the alibi. The one wearing the suit that says memory-safe, enterprise-grade, runs-your-bank:
Java.
Not Java-the-deserialization-circus you already know. This time there’s no gadget chain, no
readObject, no Runtime.exec hiding in a library three dependencies deep. The murder weapon is a
Base64 decoder, the most boring, most audited, most obviously innocent function in the
entire standard library. You send an HTTP request with a Base64 string that’s one character too
long, and a few requests later you’re running arbitrary commands as the user the service runs
as. Just arithmetic: a decoder that does subtraction in the wrong order and writes 62 bytes it
had no business writing. The rest of this post is the long version of turning those 62 bytes into a
shell, with the wrong turns left in, because the wrong turns are most of what I actually did.
A note on that “as the user the service runs as,” because it matters and I want to be precise:
the bug does not escalate privileges. It gives you code execution inside the JVM process, so
your shell inherits whatever account that process already had. On the lab box the service happened
to be launched as root, so the shell came back as root. That’s an operational sin (don’t run
your app as root), not something the exploit earns. Run the same vulnerable service as an
unprivileged appuser and you get a shell as appuser. The primitive is pre-auth remote code
execution as the service account; the privilege level is whatever that account was.
I’ll keep the moralising to one line: everything here ran on a box I was paid to break, behind a firewall. Don’t point this at things that aren’t yours.
Part 0: how I ended up here
The engagement handed me a Java service that decodes auth tokens. Nothing exotic: it takes a Base64 blob off the wire, decodes it, checks it. The kind of thing that exists in ten thousand apps. The twist was a line in the scoping notes: “the JVM is pinned to an AVX-512 profile.” That’s a weird thing to write down, and weird things in scoping notes are usually there for a reason.
AVX-512 matters because java.util.Base64 has a hand-written SIMD intrinsic for the decode
path. HotSpot ships assembly stubs for hot library methods, and Base64 decode is one of them.
On a CPU with AVX-512 VBMI (the variant with vpermb, arbitrary byte-shuffle across a 512-bit
register), the JIT swaps the plain Java loop for a stub that chews 64 input characters at a time.
It’s genuinely fast. It is also, it turns out, wrong at the edges.
The VPS I was given didn’t have AVX-512. Most cloud silicon doesn’t. So before I could even look at the bug I had to fake the hardware, which is its own little saga (Part 2). But the shape of the thing was already interesting: a vectorized decoder only misbehaves on inputs the scalar decoder handles fine, which means the bug is invisible on every machine that can’t run the intrinsic. You could fuzz this for a year on a laptop and never see it.
Part 1: what’s actually broken
Base64 packs 3 bytes into 4 characters. So a valid encoded string’s length is always a multiple
of 4 (padding with = makes up the difference). Decode takes groups of 4 chars → 3 bytes.
The question that breaks everything is: what does the decoder do when the length isn’t a
multiple of 4? A string whose length mod 4 is 1 is nonsense: you can’t have a leftover of a
single Base64 character, there aren’t enough bits to form even one output byte. The scalar
decoder notices and throws IllegalArgumentException. Correct, boring, safe.
The AVX-512 stub takes a different route. It processes the bulk of the input in 64-char vector chunks and then has a tail handler for the last partial group. The tail computes how many bytes are left to emit, and here’s the sin, paraphrased:
remaining = outputLength - bytesAlreadyWritten
When you feed it a length ≡ 1 (mod 4), the bookkeeping makes bytesAlreadyWritten larger than
outputLength. So remaining goes negative. In a signed world that’s just a small negative
number; nobody cares. But this value gets turned into an AVX-512 store mask, a 64-bit
bitmap where each set bit says “write this lane of the vector to memory.” The code builds the
mask with something morally equivalent to (1 << remaining) - 1, expecting a handful of low bits
set. Feed it a negative remaining and the shift/mask collapses to all ones. Every lane
enabled.
So instead of writing the 1 or 2 tail bytes it should, the stub executes a full 64-byte masked vector store, starting at offset 48 of the output buffer. The output buffer, for my malformed token, is 50 bytes. 48 + 64 = 112. That’s 62 bytes written past the end of the array.
The token that does it is almost insultingly simple:
"A"*64 + "="
Sixty-four As (one clean vector chunk to make sure the intrinsic is actually engaged) and a
single = to push the length to 65, and 65 mod 4 = 1. That’s the whole exploit input. Everything
after this is just me being greedy about what those 62 bytes land on.
One thing that cost me a day: you don’t control the bytes
My first instinct was the obvious one: if I’m writing 62 bytes off the end, let me write a pointer off the end, groom an object there, classic heap overflow. I spent a good while trying to steer the contents of the overflow.
You can’t. I tested token after token (A..., QUJD, Z...) and dumped what actually landed
past the array. The bytes that come from in-bounds input positions (offset ≤ 47) reflect my
data, sure. But everything from offset 48 onward, the part that’s actually out of bounds, is a
fixed 0x9a-ish fill pattern regardless of input. It’s whatever garbage the vector register
held, and it’s constant. I don’t get to pick it.
That reframes the whole exploit. I’m not writing a value I choose. I’m writing a fixed, large, junk value at a location I choose (by sizing the output buffer so the overflow lands exactly where I want). The only degree of freedom is alignment. Which, as it happens, is enough, because of what sits next to a Java array.
Part 2: making a laptop pretend to be a server CPU
Quick detour, because without this nothing runs. The target silicon has no AVX-512, so the intrinsic never activates on real hardware. I used Intel SDE (Software Development Emulator) to emulate an Ice Lake server core:
./sde64 -icx -- ./jdk/bin/java ...
-icx tells SDE to present Ice Lake’s CPUID, AVX-512 VBMI included, and to emulate any
instruction the real chip can’t run. HotSpot does its CPUID probe at startup, believes it’s on a
fancy chip, and installs the AVX-512 Base64 stub. From there the bug is live.
Two JVM flags earned their place through pain:
-Xbatch+-XX:-TieredCompilationforce C2 to compile the decode method synchronously. Under SDE on a single vCPU, the background compiler is so starved it basically never gets around to the decoder on its own, so the intrinsic never installs and you sit there wondering why your “working” exploit does nothing. Make compilation blocking and the problem disappears.- A no-op / Epsilon garbage collector, or at least a heap big enough that no collection fires mid-exploit. This matters more than it sounds and bit me hard (see Part 6).
Part 3: from “62 junk bytes” to a read/write primitive
Here’s the fact that makes Java heap overflows delicious. A Java array header stores its
length inline, right before the elements. The JVM trusts that length for every bounds check.
So if my 62-byte spray lands on the length field of a neighbouring array and overwrites it with
0x9a... (a huge number), that array now believes it is billions of elements long. Every
arr[i] after that is an unchecked read or write into whatever memory follows it.
I don’t control the junk value, but I don’t need to: any large value turns a bounded array
into an unbounded window. The fixed 0x9a69a69a-flavoured fill is, if anything, perfect: it’s
enormous.
So the groom is just: get a victim array allocated immediately after my decode buffer, size the buffer so offset-50-onward overflow lands on the victim’s length word, fire the token once. In the lab app that’s three lines:
byte[] payload = new byte[outLen]; // overflow source (decode target)
long[] meta = new long[8]; // victim: length gets smashed
Object[] anchor = new Object[]{ App.class }; // a mirror to leak with, later
The bump allocator lays those out back-to-back in order, so payload sits right before meta.
Here’s the whole trick in one picture. The decode writes forward out of payload and lands on
the one field that matters, the length word of meta:
payload (byte[50]) meta (long[8])
┌───────┬──────────────────────┐ ┌────────┬────────┬──────────────┐
│ hdr │ 0 .. 47 │ 48 ... 49 │ │ klass │ LENGTH │ meta[0..7] │
└───────┴──────────┴────────────┘ └────────┴────────┴──────────────┘
└──── valid ─────┘└───── 62-byte OOB spray ──────▶ ...
in-bounds (echo │ ▲
of my input) │ │
the AVX-512 store starts here │
(offset 48) and runs 64 bytes ─────┘
clobbers meta.LENGTH with 0x9a69a69a
→ meta now "2.5 billion" elements long
After the malformed decode, meta.length reads back as something like 2.5 billion. Now
meta[i] for large i is an out-of-bounds read/write across the heap. That’s my primitive.
The server exposes it as two endpoints, peek(id, i) and poke(id, i, v), which just do
meta[i] / meta[i] = v. Perfectly innocent code; the app is supposed to let a client index
its own cache. The corrupted length is what makes “its own cache” mean “all of memory.”
Part 4: turning a relative window into an absolute one
A giant array gets me heap-relative read/write: I can reach anything at a positive offset from
meta. That’s not yet “read address X.” I need two upgrades: find out where things are
(addrOf), and reach addresses the array can’t (absolute R/W).
addrOf, the free way
Compressed oops are the gift here. On a sub-4 GB heap, HotSpot stores object references as 32-bit “narrow oops,” and, crucially on this build, with base = 0 and shift = 0. That means a narrow oop is the object’s absolute heap address, no decoding. So:
- Put a target object into my
Object[] anchorslot. - Use the corrupted
metawindow to read the raw 32-bit word of that slot. - That word is the object’s address. Done.
addrOffor free, noUnsafe, no leak gadget.
DirectByteBuffer: the absolute R/W pivot
The meta window can only reach forward through the heap; it can’t touch libjvm’s high-mapped
addresses. For that I borrow a DirectByteBuffer. A DBB has a native address field (a plain
long at a known object offset) pointing at its off-heap backing. getLong/putLong read and
write relative to that field.
So: use the meta window to overwrite the DBB’s address field with any pointer I want, then
call region.getLong(0) / putLong(0, v) to read or write that address. The buffer becomes a
movable aperture over the entire 64-bit space. The server exposes this as region/get and
region/put. Two endpoints, arbitrary absolute read, arbitrary absolute write. The memory-safety
story of the whole process is now over; the rest is navigation.
The aastore trap (half a day, gone)
One genuinely nasty snag. My first corruption target was the Object[] itself, and I tried to
aastore into the corrupted array to plant references. Instant crash. Why: an aastore
triggers a store-type-check, which walks the array’s klass pointer, and my overflow had
smashed the bytes around the header, klass included. The type-check dereferences garbage and
faults.
The fix is to never write through the smashed object as a typed store. Do your addrOf against
a clean companion array, and compute the smashed object’s address arithmetically
(writerAbs = addrOf(payload) + headerDelta) instead of asking the JVM to touch its poisoned
header. Obvious in hindsight. It was not obvious at 1 a.m.
Part 5: finding libjvm, and the global nobody guards
Absolute R/W is great but I’m firing blind until I know where libjvm.so is mapped, since ASLR
moves it every launch. I need one reliable pointer into libjvm that I can find from an object I
already hold.
The trick: a class’s runtime Class mirror (e.g. App.class, the thing already sitting in my
anchor) carries a hidden Klass* field at a fixed, build-known offset. Follow it to the
InstanceKlass, and the first word of a C++ InstanceKlass is its vtable pointer, which
points at a vtable inside libjvm. One known constant later:
libjvm_base = leaked_vtable_ptr − VTABLE_OFFSET
and I know where the whole library lives. (VTABLE_OFFSET is specific to the exact JDK build.
I pulled it by dumping the InstanceKlass vtable offset once under a debugger. Different JDK,
re-derive it.)
Now, the payoff. HotSpot has a diagnostic flag called OnError: a string the VM runs via
/bin/sh -c when it hits a fatal error, so operators can auto-collect diagnostics on a crash.
It’s stored as a char* global in libjvm’s flag table. If I can write that pointer, I control a
command that the JVM will cheerfully execute as itself (i.e. as whatever account the service
process is running under) the next time it crashes. And I have an arbitrary crash on tap: just
point the DBB at an unmapped address and read.
So the endgame is three writes and a nudge:
- Write my command string (
id, or a reverse-shell one-liner) into some memory I know the address of. The DBB’s own backing works. - Overwrite
&OnError(=libjvm_base + ONERROR_OFFSET) with a pointer to that string. - Trigger a segfault. HotSpot’s fatal-error handler fires, reads
OnError, and runs/bin/sh -c "<my string>".
# Executing /bin/sh -c "id" ...
uid=0(root) gid=0(root) groups=0(root)
There it is: the command runs. (On this box the process was running as root, so id prints
root; see the note at the top. The exploit grabs the service account, whatever it is, not root
specifically.) From a malformed Base64 string to arbitrary command execution, and at no point did
I call a single function that a code-review grep would flag. The scariest exploits are the ones
made entirely of innocent pieces.
Finding &OnError’s offset was its own grind. I wrote a little scanner that parsed the static
JVMFlag table out of libjvm and cross-checked it by launching with -XX:OnError=<canary> and
reading the pointer back to confirm I had the right slot. Tedious, but a one-time cost per build.
Part 6: the difficulties, collected
The clean narrative above hides about three days of flailing. The honest list:
You don’t control the overflow bytes. The single biggest reframe. I wasted the first day trying to write a chosen pointer before accepting the fill is fixed and pivoting to “smash a length field with junk.” The lack of control is fine if the thing you’re hitting only needs to be big, not specific.
One shot per JVM. The C2 compiler deoptimises and blacklists the decode method after it sees the malformed input blow up enough times. After that it falls back to the safe scalar path and the bug is gone until you restart the process. So you get roughly one reliable overflow per JVM lifetime. The entire exploit chain has to run off a single trigger: you warm the intrinsic, fire once, and do all your R/W through the corruption you already have. No “try again.” This is the constraint that shapes everything; it’s why the groom has to be perfect before you pull the trigger.
The GC eats your victim. Early on my exploit worked maybe one run in five and I couldn’t see why. It was a young-gen collection firing between the corruption and my first read, relocating (or tripping over) an array whose length now claimed to be 2.5 billion elements. The collector tries to walk it and either moves my landmarks out from under me or dies. Fix: run with effectively no GC (Epsilon) or a heap large enough that nothing collects during the ~millisecond of the exploit. Suddenly it was five runs in five.
The aastore store-check fault (Part 4). Touching a corrupted object as a typed reference array dereferences its smashed klass. Keep all typed operations on clean objects; treat the smashed one as raw addresses only.
Getting the intrinsic to actually install under emulation. Hours lost to an exploit that was “correct” but silently running against the scalar decoder because C2 never compiled the method under SDE’s starved scheduler.
-Xbatch -XX:-TieredCompilationand an explicit warm-up loop fixed it. Lesson: before trusting a SIMD-bug exploit, prove the SIMD path is live. I added a check that the first malformed token corrupts a throwaway array, and bailed loudly if it didn’t.Build-specific constants. The
VTABLE_OFFSETandONERROR_OFFSETvalues are nailed to one exact JDK build. Point this at another build and you leak a pointer into the wrong place and segfault for real. Every constant in the chain needs a “how I re-derive this” note, or future-me is stuck.
Part 7: doing it over the network
Everything above I first proved locally: a standalone Java program on the box, grooming its own heap. The obvious objection to a local PoC is “so what, you already had code execution to run it.” Fair. The real question is whether a remote, HTTP-only attacker can do the same, because that’s the actual threat.
The original token service couldn’t be popped remotely, and it’s worth saying why clearly: it decoded attacker Base64 (so the corruption reproduces over the wire; I could prove the victim array’s length smashes via the response), but it exposed no persistent, client-indexable object to then read and write through. You can break something you can’t subsequently touch. The crash is remote; the primitive isn’t.
So to show the full remote chain I stood up a second service, MemCacheService, a deliberately
ordinary-looking “remote off-heap cache” that exposes exactly the surface a real vulnerable app
would: decode a blob on /session/open, and let the client peek/poke and region get/put its own session buffers by index. Nothing in it is a backdoor; every endpoint is the
kind of thing you’d write without a second thought. The corrupted array length is what quietly
turns “index your own cache” into “read and write my whole address space.”
The remote exploit is then just the local chain, re-expressed as HTTP:
POST /warmwith a few thousand valid tokens → C2 compiles the shared decode helper, intrinsic goes live.POST /session/openwith"A"*64 + "="→ groomspayload → meta → region → anchorback-to-back and fires the overflow; the response hands backmeta.lengthso I can see it’s corrupted.peektheanchorslot → narrow oop →addrOf.peekthe mirror →Klass*→ vtable →libjvm_base.pokethe DBB’saddressfield, thenregion/putmy command string and overwrite&OnError.region/getat a bad address → fatal error →OnErrorruns my one-liner as the service account. It starts a tiny one-shot callback server; the exploit opens one TCP connection to it and confirms the command executed:
################ REMOTE EXEC CONFIRMED ################
uid=0(root) gid=0(root) groups=0(root)
########################################################
Pure HTTP in, command execution out, no shell on the box to begin with. Same bug, same chain,
just posted through a web server instead of a main(). (Same caveat as before: uid=0 here only
because this lab service was started as root; the primitive gives you the service account, whatever
it is.) (One caveat baked into the design: the detonate step
crashes the target JVM on purpose, since that’s how OnError fires, so a successful run always
ends with the service dead. Re-run it and you get connection-refused until someone restarts the
service. That’s not a flaky exploit, it’s the exit condition.)
Part 8: what fixes it, and what I took away
The fix is unglamorous: the tail-length arithmetic in the intrinsic must be computed and masked so
it can’t go negative, and a length ≡ 1 (mod 4) must reject exactly like the scalar path does.
Running with -XX:-UseBASE64Intrinsics disables the stub entirely and makes the bug vanish, a
fine emergency mitigation if you’re stuck on a vulnerable build and happen to run on AVX-512
silicon. Patch the JDK properly when you can.
If you’re on the other side of this
Because the whole chain is built from innocent-looking pieces, there’s no single Runtime.exec
to alert on. But the exploit is loud in other ways if you know where to look:
- Malformed Base64 at volume. The warm-up sends thousands of valid tokens, then the trigger is
a token whose length is
≡ 1 (mod 4)(e.g. 64As + a single=). A decode endpoint that normally sees clean input suddenly taking a burst ofIllegalArgumentException-shaped tokens, immediately followed by a crash, is the signature. - The crash itself. Successful exploitation requires a fatal JVM error; it’s how
OnErrorfires. Anhs_err_pid*.log/core.*appearing right after that traffic, with a SIGSEGV in or near the Base64 stub, is your smoking gun. Treat an unexplained JVM fatal error as a security event, not just an availability one. OnErrorexecuting a child process. The payload runs as/bin/sh -c "…"spawned by thejavaprocess during a crash. A shell (orpython,curl, a reverse-shell one-liner) parented to a JVM that is simultaneously dying is about as abnormal as process trees get: easy EDR win. Bonus: flag any JVM whoseOnErrorflag is set to something nobody put in the launch config.- Cheap hardening. Don’t run the app as root (the whole “it came back as root” problem
evaporates). Keep decode endpoints behind auth. And on a vulnerable build you can’t patch yet,
-XX:-UseBASE64Intrinsicscloses the door outright.
The part that stays with me isn’t the pointer math, it’s the shape of the thing. A SIMD optimisation introduced a memory-safety bug into a memory-safe language, on a code path that only exists on specific hardware, triggered by an input the “real” decoder rejects as garbage. It’s invisible to review (the Java source is fine), invisible to most fuzzing (wrong CPU), and lands in a method everyone considers boring and safe. Base64 decode. The quietest function in the standard library.
Check what your performance intrinsics do at the edges. That’s the whole lesson.
Written up from lab notes; all testing was authorized, on owned infrastructure.