Type Confusion in V8 (CVE-2025-0291)
A type analysis pass in V8's Turboshaft compiler incorrectly handles single-block loops, cutting fixed-point iteration short and reporting wrong type feedback. This can cause type checks to be removed, leading to type confusion; the reporter demonstrated a crash and an out-of-sandbox write in Chromium.
- Fix shipped in 28 days
WasmGCTypeAnalyzer is a Turboshaft analyzer responsible for inferring known type information for various operations, which can then be used by WasmGCTypedOptimizationReducer to potentially remove some type checks at compile time. To do this, it traverses the Turboshaft graph while keeping track of which types might be encountered at any particular point in the code. When encountering a loop, the analyzer keeps revisiting the loop body indefinitely until the type feedback stabilizes - this is intended to ensure that the loop backedge's type feedback is properly accounted for. The analyzer revisits the loop's body by calling iterator.MarkLoopForRevisitSkipHeader() - the loop header has already been revisited while trying to determine whether the type feedback stabilized, so it is skipped here, presumably as an optimization.
However, this assumption / optimization doesn't account for single-block loops, which can occur in the Turboshaft graph when compiling infinite loops without any branches. For these loops, the loop header contains the entire loop body, effectively turning iterator.MarkLoopForRevisitSkipHeader() into a No-Op, and preventing the loop from being revisited any additional times. This cuts the fixed-point analysis short after two iterations: one initial visit, and one additional visit as part of the check to determine whether the type feedback stabilized. As such, WasmGCTypeAnalyzer might report incorrect type feedback to WasmGCTypedOptimizationReducer when the loop's type information does not stabilize after two iterations (which can be the case because of, for example, a chain of Phis), which can lead to type checks being incorrectly removed, resulting in type confusion.
See attached two files:
poc.js: this contains a minimal POC which utilizes this bug to create and dereference a fake object, resulting in a crash. This POC has been reproduced with an D8 optdebug build (commit86ffa19a533bdec3b9ce4a56106a2d9e8015e108) on an x86-64 Linux machine.exploit.js: this contains a full Chromium exploit chain, utilizing this bug + unprotected PartitionAlloc metadata to demonstrate an attacker controlled write outside of the sandbox. This exploit has been tested and confirmed to work on Chromium 131.0.6778.108 on an x86-64 Linux machine, using--js-flags="--turboshaft-wasm"to enable Turboshaft for Wasm. Note that this class of sandbox escape (namely manipulating exposedSlotSpanMetadataobjects) has been used in other exploit chains to achieve full RCE; this exploit stops short of achieving RCE, only demonstrating attacker controlled writes, since further exploitation requires hardcoding offsets for specific Chromium builds, which reduces the general reproducibility and reliability of the exploit.
A potential fix for this bug would be to not use MarkLoopForRevisitSkipHeader for revisiting single block loops, and instead use MarkLoopForRevisit for this particular edge case. A sample patch of such a fix could look as follows:
@@ -61,8 +61,14 @@ void WasmGCTypeAnalyzer::Run() {
if (needs_revisit) {
block_to_snapshot_[loop_header.index()] = MaybeSnapshot(snapshot);
// This will push the successors of the loop header to the iterator
- // stack, so the loop body will be visited in the next iteration.
- iterator.MarkLoopForRevisitSkipHeader();
+ // stack, so the loop body will be visited in the next iteration. If
+ // this is a single-block loop, then there are no successors - as such
+ // revisit the entire loop (consisting of just the header) in this
+ // case.
+ if (block.index() != header.index()) {
+ iterator.MarkLoopForRevisitSkipHeader();
+ } else {
+ iterator.MarkLoopForRevisit();
+ }
}
}
}
Reporter Credit: if applicable, please credit my pseudonym Popax21 in regards to this report.
Context
V8's Turboshaft compiler pipeline includes an analyzer called WasmGCTypeAnalyzer, which infers known type information for operations in the Turboshaft graph. That type information is consumed by WasmGCTypedOptimizationReducer, which can use it to remove type checks at compile time. The analyzer works by traversing the Turboshaft graph while tracking which types might be encountered at any point in the code.
When the traversal reaches a loop, the analyzer keeps revisiting the loop body until the type feedback stabilizes. This fixed-point behaviour is intended to make sure the loop backedge's type feedback is properly accounted for. The bug reported here is a type confusion in that fixed-point analysis, tracked as CVE-2025-0291, affecting V8 in Google Chrome. It was reported through the Chrome VRP by Popax21 and rated high severity, with a bounty of 55,000 USD. Disclosure was on 7 January 2025.
Setup
The report attaches two artefacts:
poc.js, a minimal proof of concept that uses the bug to create and dereference a fake object, resulting in a crash. It was reproduced with a D8 optdebug build at commit[redacted]on an x86-64 Linux machine.exploit.js, a full Chromium exploit chain that combines this bug with unprotected PartitionAlloc metadata to demonstrate an attacker-controlled write outside of the sandbox. It was tested and confirmed to work on Chromium 131.0.6778.108 on an x86-64 Linux machine, using--js-flags="--turboshaft-wasm"to enable Turboshaft for Wasm.
The exploit stops short of achieving RCE. The researcher notes that this class of sandbox escape, namely manipulating exposed SlotSpanMetadata objects, has been used in other exploit chains to achieve full RCE, but further exploitation requires hardcoding offsets for specific Chromium builds, which reduces the general reproducibility and reliability of the exploit.
Finding it
The problem lies in how the analyzer revisits a loop after deciding that the type feedback has not yet stabilized. When it needs to revisit, it stores a snapshot for the loop header and then calls iterator.MarkLoopForRevisitSkipHeader(). The loop header has already been revisited while trying to determine whether the type feedback stabilized, so it is skipped here, presumably as an optimization.
That assumption does not account for single-block loops. Such loops can occur in the Turboshaft graph when compiling infinite loops without any branches. For these loops, the loop header contains the entire loop body, so iterator.MarkLoopForRevisitSkipHeader() effectively becomes a No-Op and the loop is not revisited any additional times.
Exploitation
The consequence is that the fixed-point analysis is cut short after two iterations: one initial visit, and one additional visit as part of the check to determine whether the type feedback stabilized. If the loop's type information does not stabilize after two iterations, which can happen for example because of a chain of Phis, WasmGCTypeAnalyzer may report incorrect type feedback to WasmGCTypedOptimizationReducer. That can lead to type checks being incorrectly removed, resulting in type confusion.
The two attached files demonstrate the result:
poc.jsuses the bug to create and dereference a fake object, which crashes the D8 optdebug build at commit[redacted]on x86-64 Linux.exploit.jschains the bug with unprotected PartitionAlloc metadata to demonstrate an attacker-controlled write outside of the sandbox on Chromium 131.0.6778.108 on x86-64 Linux, with Turboshaft for Wasm enabled through--js-flags="--turboshaft-wasm".
Root cause
The analyzer's revisit logic skips the loop header because it was already revisited during the stabilization check, presumably as an optimization. In a single-block loop, the header is the whole body, so skipping it skips everything. The revisit becomes a No-Op, the fixed-point iteration stops after two passes, and the analyzer can hand stale or incorrect type feedback to the reducer. The reducer can then remove type checks that were in fact still needed, producing type confusion.
Impact
Under the conditions above, the incorrect type feedback can cause type checks to be removed and lead to type confusion. The proof of concept turns this into a fake object that is dereferenced, crashing the build. The full chain demonstrates an attacker-controlled write outside of the sandbox by combining the bug with unprotected PartitionAlloc metadata. The researcher is explicit that the chain does not achieve RCE, and that further exploitation requires hardcoding offsets for specific Chromium builds, which would reduce reproducibility and reliability.
Fix
A potential fix is not to use MarkLoopForRevisitSkipHeader when revisiting single-block loops, and to use MarkLoopForRevisit for that edge case instead. A sample patch:
@@ -61,8 +61,14 @@ void WasmGCTypeAnalyzer::Run() {
if (needs_revisit) {
block_to_snapshot_[loop_header.index()] = MaybeSnapshot(snapshot);
// This will push the successors of the loop header to the iterator
- // stack, so the loop body will be visited in the next iteration.
- iterator.MarkLoopForRevisitSkipHeader();
+ // stack, so the loop body will be visited in the next iteration. If
+ // this is a single-block loop, then there are no successors - as such
+ // revisit the entire loop (consisting of just the header) in this
+ // case.
+ if (block.index() != header.index()) {
+ iterator.MarkLoopForRevisitSkipHeader();
+ } else {
+ iterator.MarkLoopForRevisit();
+ }
}
}
}
Variants to test
- Compile infinite loops without branches in Wasm through Turboshaft and check whether the analyzer's fixed-point iteration runs more than twice. A positive result is type feedback that keeps changing after the second visit.
- Build loops whose type information depends on a chain of Phis, so that stabilization needs more than two iterations. A positive result is a type check being removed that should have remained.
- Exercise the same revisit path with other loop shapes that collapse to a single block. A positive result is the same No-Op behaviour in
MarkLoopForRevisitSkipHeader. - On Chromium builds with Turboshaft for Wasm enabled, combine the resulting type confusion with PartitionAlloc metadata manipulation and check for an out-of-sandbox write. A positive result is an attacker-controlled write outside the sandbox, as demonstrated in the reported chain.
What happened, in plain words
Google Chrome is a web browser. Inside it sits a program called V8, which is the part that reads and runs the JavaScript and WebAssembly code found on web pages. V8 does not simply run code line by line; it also tries to make that code faster by rewriting it before running it. One of the rewriting stages is called Turboshaft, and inside Turboshaft there is a small helper called WasmGCTypeAnalyzer.
That helper has one job: to work out what kind of value (a number, an object, a piece of text and so on) can appear at each point in a program. A second helper, WasmGCTypedOptimizationReducer, reads those notes and uses them to delete safety checks that it believes are unnecessary. Deleting a check is fine only if the notes are correct. If the notes are wrong, a check that was actually needed gets removed, and the program can then treat one kind of value as if it were a different kind. That mistake is called type confusion, and it is the bug described here.
The bug is tracked as CVE-2025-0291. It was reported through the Chrome VRP (Google's Vulnerability Reward Program, which pays people for finding security bugs) by a researcher using the name Popax21. It was rated high severity, the bounty was 55,000 USD, and it was disclosed on 7 January 2025.
The rest of this article walks through how the analyzer works, where its logic breaks, what the researcher built to prove it, and how the bug could be fixed.
Context
To follow the story you need a few ideas from the world of compilers, the programs that translate code written by people into something the machine can run quickly.
- V8 is Chrome's engine for JavaScript and WebAssembly. WebAssembly (often shortened to Wasm) is a low-level format that lets code written in other languages run inside a browser at near-native speed.
- Turboshaft is one of V8's compiler pipelines. It represents a program as a graph: a collection of blocks of instructions connected by arrows, where each arrow says which block runs next. Think of it like a flowchart of the program.
WasmGCTypeAnalyzeris an analyzer, a component that inspects the graph and writes down facts. It infers known type information for the operations in the graph. In everyday terms, it is like a careful reader going through a recipe and noting next to each step "this ingredient is flour" or "this ingredient is sugar".WasmGCTypedOptimizationReduceris the component that consumes those notes. If the notes say a value is definitely of a certain type, the reducer can remove a type check, a small piece of code that would otherwise verify the type at runtime. Removing checks makes programs faster, which is the whole point of an optimising compiler.
The analyzer works by traversing the Turboshaft graph while tracking which types might be encountered at any point in the code. Traversal means walking through the flowchart block by block, following the arrows.
When the traversal reaches a loop (a piece of code that repeats), the analyzer keeps revisiting the loop body until the type feedback stabilizes. Type feedback here means the notes the analyzer has collected about types. "Stabilizes" means the notes stop changing: you go round the loop again and the same notes come out. This repeated-until-nothing-changes process is called a fixed-point analysis, and it is intended to make sure the loop backedge's type feedback is properly accounted for. The backedge is the arrow that jumps from the end of the loop back to its beginning.
A useful comparison: imagine proofreading a circular letter that refers to itself. You read it once, make corrections, then read it again to see whether your corrections introduced new problems. You stop when a full pass produces no changes. That is a fixed point.
The bug reported here is a type confusion in that fixed-point analysis. It affects V8 in Google Chrome, was reported through the Chrome VRP by Popax21, and was rated high severity with a bounty of 55,000 USD. Disclosure was on 7 January 2025.
Setup
The report attaches two artefacts, meaning two files that demonstrate the problem.
poc.js, a minimal proof of concept. A proof of concept (POC) is the smallest program that shows a bug is real. This one uses the bug to create and dereference a fake object, resulting in a crash. "Dereference" means asking a program to read or use the thing an object reference points at; if the object is fake, the program reads nonsense and falls over. It was reproduced with a D8 optdebug build at commit[redacted]on an x86-64 Linux machine. D8 is V8's standalone command-line shell, a way to run JavaScript without a whole browser. An optdebug build is a build of the engine that keeps debugging information while still running the optimising compiler, which makes it useful for studying compiler bugs. A commit is a specific saved version of the source code, identified by a long hash.exploit.js, a full Chromium exploit chain. Chromium is the open-source project that Chrome is built from. An exploit chain is a sequence of steps where each step builds on the previous one to get further than a single bug would allow. This chain combines the bug with unprotected PartitionAlloc metadata to demonstrate an attacker-controlled write outside of the sandbox. PartitionAlloc is Chromium's memory allocator, the component that hands out chunks of memory to the rest of the program; its metadata is the bookkeeping it keeps about those chunks. A sandbox is a boundary that keeps code that has been compromised from reaching the rest of the machine. An attacker-controlled write means the attacker can choose what gets written and where, which is a serious capability. It was tested and confirmed to work on Chromium 131.0.6778.108 on an x86-64 Linux machine, using--js-flags="--turboshaft-wasm"to enable Turboshaft for Wasm. That flag is a command-line switch that tells the engine to use the Turboshaft pipeline for WebAssembly code.
The exploit stops short of achieving RCE, which stands for remote code execution: the ability to make the target machine run code of the attacker's choosing. The researcher notes that this class of sandbox escape, namely manipulating exposed SlotSpanMetadata objects, has been used in other exploit chains to achieve full RCE. SlotSpanMetadata is a structure inside PartitionAlloc that describes a group of memory slots. Further exploitation requires hardcoding offsets for specific Chromium builds, which reduces the general reproducibility and reliability of the exploit. An offset is a distance in memory; hardcoding one means writing a fixed number that only works for one exact build of the program.
Finding it
The problem lies in how the analyzer revisits a loop after deciding that the type feedback has not yet stabilized. When it needs to revisit, it stores a snapshot for the loop header and then calls iterator.MarkLoopForRevisitSkipHeader(). A snapshot is a saved copy of the current notes, so the analyzer can compare later and see whether anything changed. The loop header is the first block of a loop, the entry point. The call MarkLoopForRevisitSkipHeader() tells the traversal machinery to go round the loop again but to skip the header this time. The loop header has already been revisited while trying to determine whether the type feedback stabilized, so it is skipped here, presumably as an optimization. In other words, the author of that code reasoned: we just looked at the header, so there is no need to look at it twice.
That assumption does not account for single-block loops. A single-block loop is a loop whose entire body fits in one block of the graph. Such loops can occur in the Turboshaft graph when compiling infinite loops without any branches. An infinite loop is a loop that never ends on its own; a branch is a point where the program chooses between two or more paths. If there is only one path and it goes back to the start, the whole loop is one block.
For these loops, the loop header contains the entire loop body, so iterator.MarkLoopForRevisitSkipHeader() effectively becomes a No-Op and the loop is not revisited any additional times. A No-Op (short for no operation) is an instruction that does nothing. The everyday comparison: telling someone to "skip the first chapter and reread the rest" works fine for a book with ten chapters, but if the book has only one chapter, the instruction means reread nothing at all.
Exploitation
The consequence is that the fixed-point analysis is cut short after two iterations: one initial visit, and one additional visit as part of the check to determine whether the type feedback stabilized. An iteration here is one full pass of the analysis. If the loop's type information does not stabilize after two iterations, which can happen for example because of a chain of Phis, WasmGCTypeAnalyzer may report incorrect type feedback to WasmGCTypedOptimizationReducer. A Phi is a special instruction in a compiler graph that merges values arriving from different paths; a chain of Phis is several of them feeding into one another, so the value at the end depends on several rounds of merging. That can lead to type checks being incorrectly removed, resulting in type confusion.
Going back to the proofreading comparison: if you stop after two passes because you assume the letter is now clean, but the corrections from the second pass would have caused more changes on a third, you hand in a letter that still contains mistakes. Here the "mistakes" are wrong type notes, and the consequence is that safety checks get deleted.
The two attached files demonstrate the result:
poc.jsuses the bug to create and dereference a fake object, which crashes the D8 optdebug build at commit[redacted]on x86-64 Linux.exploit.jschains the bug with unprotected PartitionAlloc metadata to demonstrate an attacker-controlled write outside of the sandbox on Chromium 131.0.6778.108 on x86-64 Linux, with Turboshaft for Wasm enabled through--js-flags="--turboshaft-wasm".
Root cause
The analyzer's revisit logic skips the loop header because it was already revisited during the stabilization check, presumably as an optimization. In a single-block loop, the header is the whole body, so skipping it skips everything. The revisit becomes a No-Op, the fixed-point iteration stops after two passes, and the analyzer can hand stale or incorrect type feedback to the reducer. Stale means out of date: notes that were true at an earlier point but no longer match reality. The reducer can then remove type checks that were in fact still needed, producing type confusion.
Impact
Under the conditions above, the incorrect type feedback can cause type checks to be removed and lead to type confusion. The proof of concept turns this into a fake object that is dereferenced, crashing the build. The full chain demonstrates an attacker-controlled write outside of the sandbox by combining the bug with unprotected PartitionAlloc metadata. The researcher is explicit that the chain does not achieve RCE, and that further exploitation requires hardcoding offsets for specific Chromium builds, which would reduce reproducibility and reliability.
Fix
A potential fix is not to use MarkLoopForRevisitSkipHeader when revisiting single-block loops, and to use MarkLoopForRevisit for that edge case instead. In plain terms: if the loop is a single block, do not skip the header, because the header is all there is; revisit the whole loop. A sample patch:
@@ -61,8 +61,14 @@ void WasmGCTypeAnalyzer::Run() {
if (needs_revisit) {
block_to_snapshot_[loop_header.index()] = MaybeSnapshot(snapshot);
// This will push the successors of the loop header to the iterator
- // stack, so the loop body will be visited in the next iteration.
- iterator.MarkLoopForRevisitSkipHeader();
+ // stack, so the loop body will be visited in the next iteration. If
+ // this is a single-block loop, then there are no successors - as such
+ // revisit the entire loop (consisting of just the header) in this
+ // case.
+ if (block.index() != header.index()) {
+ iterator.MarkLoopForRevisitSkipHeader();
+ } else {
+ iterator.MarkLoopForRevisit();
+ }
}
}
}
Line by line, in plain words:
@@ -61,8 +61,14 @@ void WasmGCTypeAnalyzer::Run() {is the header of a diff, a format that shows changes to a file. It says the change starts around line 61 of the original file and that the function being edited isWasmGCTypeAnalyzer::Run(), the routine that starts the analysis.if (needs_revisit) {checks whether the analyzer has decided the loop must be looked at again because the type notes have not settled.block_to_snapshot_[loop_header.index()] = MaybeSnapshot(snapshot);saves a copy of the current notes for the loop header, so the next pass can be compared against it.- The comment lines beginning with
//explain what the following call does: it pushes the successors of the loop header onto the iterator stack, so the loop body will be visited in the next iteration. A successor is a block that comes after the current one; a stack is a last-in, first-out list of pending work. - The removed line
iterator.MarkLoopForRevisitSkipHeader();was the old unconditional call that skipped the header. - The added lines replace it with a decision.
if (block.index() != header.index()) {asks: is the current block different from the loop header? If yes, this is a normal loop, anditerator.MarkLoopForRevisitSkipHeader();is used as before. } else {covers the case where the current block is the header itself, which means a single-block loop.iterator.MarkLoopForRevisit();then revisits the entire loop, which consists of just the header, instead of skipping it.- The closing braces end the new conditional and the existing
if (needs_revisit)block.
Variants to test
- Compile infinite loops without branches in Wasm through Turboshaft and check whether the analyzer's fixed-point iteration runs more than twice. A positive result is type feedback that keeps changing after the second visit.
- Build loops whose type information depends on a chain of Phis, so that stabilization needs more than two iterations. A positive result is a type check being removed that should have remained.
- Exercise the same revisit path with other loop shapes that collapse to a single block. A positive result is the same No-Op behaviour in
MarkLoopForRevisitSkipHeader. - On Chromium builds with Turboshaft for Wasm enabled, combine the resulting type confusion with PartitionAlloc metadata manipulation and check for an out-of-sandbox write. A positive result is an attacker-controlled write outside the sandbox, as demonstrated in the reported chain.
Glossary
- Analyzer: a component that inspects a program and records facts about it, without changing the program itself.
- Attacker-controlled write: a situation where an attacker can choose both the data written and the place it is written to in memory.
- Backedge: the arrow in a program graph that jumps from the end of a loop back to its beginning.
- Block: a group of instructions in a compiler graph that always run together, connected to other blocks by arrows.
- Bounty: a payment made by a company to someone who reports a security bug.
- Branch: a point in a program where execution can go one of several ways.
- CVE: a public identifier for a known security vulnerability, here CVE-2025-0291.
- Chromium: the open-source browser project that Google Chrome is built from.
- Commit: a specific saved version of a source code repository, identified by a hash.
- Compiler: a program that translates code written by people into a form the machine can run, often making it faster along the way.
- D8: V8's standalone command-line shell for running JavaScript outside a browser.
- Dereference: to read or use the thing that a reference points at in memory.
- Diff: a text format that shows lines added to and removed from a file.
- Exploit chain: a sequence of steps, each building on the last, to get further than any single bug would allow.
- Fixed-point analysis: a repeated analysis that keeps going until a full pass produces no changes.
- Graph: a representation of a program as blocks connected by arrows, like a flowchart.
- Hardcoded offset: a fixed distance in memory written into an exploit that only works for one exact build of a program.
- Header (loop header): the first block of a loop, where the loop is entered.
- Infinite loop: a loop that never ends on its own.
- Iteration: one full pass of a repeated process.
- Loop: a piece of code that repeats.
- Metadata: bookkeeping data that a program keeps about something else, such as memory chunks.
- No-Op: an instruction that does nothing.
- Optdebug build: a build of an engine that keeps debugging information while still running the optimising compiler.
- PartitionAlloc: Chromium's memory allocator, which hands out chunks of memory to the rest of the program.
- Phi: a compiler instruction that merges values arriving from different paths; a chain of Phis merges values over several rounds.
- Proof of concept (POC): the smallest program that demonstrates a bug is real.
- RCE (remote code execution): the ability to make a target machine run code of the attacker's choosing.
- Reducer: a compiler component that simplifies or removes code based on facts gathered elsewhere.
- Reproducibility: how reliably a result can be obtained again on another machine or build.
- Sandbox: a boundary that keeps compromised code from reaching the rest of the machine.
- Sandbox escape: getting past that boundary.
- Severity: a rating of how serious a vulnerability is.
- Single-block loop: a loop whose entire body fits in one block of the graph.
- Snapshot: a saved copy of the current state, used for later comparison.
- Stack: a last-in, first-out list of pending work.
- Stale: out of date; no longer matching reality.
- Successor: a block that comes after the current block in a graph.
- Turboshaft: one of V8's compiler pipelines, which represents programs as graphs.
- Type check: a piece of code that verifies at runtime that a value is of the expected kind.
- Type confusion: a bug where a program treats a value of one kind as if it were another kind.
- Type feedback: the notes an analyzer has collected about which types can appear where.
- V8: Chrome's engine for running JavaScript and WebAssembly.
- VRP (Vulnerability Reward Program): Google's programme that pays researchers for reporting security bugs.
- Wasm (WebAssembly): a low-level format that lets code written in other languages run inside a browser at near-native speed.
- x86-64: a common family of processors found in desktop and laptop computers.