Type Confusion in V8 (CVE-2024-12692)
A missing mutability check in V8's Wasm canonicalisation allowed a type confusion between struct types with different field mutability. An attacker could exploit this to obtain in-sandbox exploit primitives and achieve arbitrary code execution in Chrome.
Originally disclosed on Chrome VRP
- Fix shipped in 14 days
VULNERABILITY DETAILS
Summary
Arbitrary Wasm type confusion due to missing struct field mutability check on canonicalization. Mutability checks are missing for struct fields at CanonicalEquality::EqualStructType(), allowing type confusion between arbitrary Wasm types.
This is a variant of b/381696874.
Details
I've pointed out in b/381696874 that if we have a broken CanonicalEquality check that may be exploitable, we can use the birthday attack to cause a hash collision and trigger the bug. CanonicalEquality::EqualStructType() is missing mutability checks for its fields:
bool EqualStructType(const CanonicalStructType& type1,
const CanonicalStructType& type2) const {
return std::equal(
type1.fields().begin(), type1.fields().end(), type2.fields().begin(),
type2.fields().end(),
std::bind_front(&CanonicalEquality::EqualValueType, this));
}
This can be exploited by a casting chain of struct {const ref null none} -> struct {const ref null any} -> struct {mut ref null any} where the last cast is due to broken canonicalization, and the first cast is through legal subtype relationship. This allows us to overwrite ref null none with a value of ref null any type, resulting in arbitrary Wasm type confusion.
The attached PoC/exploit has a precomputed hash-colliding struct type that uses either const ref null any or mut ref null any for its 40 field types.
Bisect
Bug likely introduced by https://crrev.com/c/6049646 in M133 that attempts to fix b/379009132 by removing relative type indexs from canonical types. Note that the commit is already backported to M132 and M131.
VERSION
- M133: https://crrev.com/c/6049646
- M132: https://crrev.com/c/6049645
- M131: https://crrev.com/c/6049646
Chrome Version: 131.0.6778.108, 132.0.6834.32, 133.0.6848.0 ~ latest
Operating System: All
REPRODUCTION CASE
Attached as poc.js which exploits the hash collision + type confusion to obtain in-sandbox exploit primitives, and then crashes on arbitrary caged write attempt.
Also attached is yet another full exploit exp.html that pops calc on Windows x64 Chrome, tested against Canary 133.0.6877.0.
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION
Type of crash: Renderer
Crash State: Crashes on arbitrary caged write attempt from JIT-compiled Wasm function (on d8, poc.js), arbitrary code execution (on Chrome, exp.html)
CREDIT INFORMATION
Reporter credit: Seunghyun Lee (@0x10n) of CMU CyLab
Context
V8 is the JavaScript and WebAssembly engine used by Chrome. WebAssembly's type system includes struct types, whose fields can be declared mutable or constant (const). For two Wasm types to be considered the same type, their fields must match, including whether each field is mutable. V8 canonicalises types so that equivalent types share a single representation, and the canonicalisation logic compares struct types field by field.
This report describes a type confusion in that canonicalisation logic, tracked as CVE-2024-12692, affecting the V8 engine in Chrome. It is a variant of an earlier issue, b/381696874.
Setup
The researcher tested against Chrome versions 131.0.6778.108, 132.0.6834.32 and 133.0.6848.0 through latest, on all operating systems. Two artefacts were attached to the report:
poc.js, which exploits the hash collision and type confusion to obtain in-sandbox exploit primitives and then crashes on an arbitrary caged write attempt. It was run on d8.exp.html, a full exploit that popscalcon Windows x64 Chrome, tested against Canary 133.0.6877.0.
No accounts, roles or special tooling beyond a V8/Chrome build are described.
Finding it
The researcher had already shown in b/381696874 that a broken CanonicalEquality check can be exploited by using a birthday attack to cause a hash collision and trigger the bug. Looking at the canonicalisation code, the researcher found that CanonicalEquality::EqualStructType() does not check the mutability of struct fields:
bool EqualStructType(const CanonicalStructType& type1,
const CanonicalStructType& type2) const {
return std::equal(
type1.fields().begin(), type1.fields().end(), type2.fields().begin(),
type2.fields().end(),
std::bind_front(&CanonicalEquality::EqualValueType, this));
}
The struct-level equality is missing mutability checks for its fields. That means two struct types that differ only in whether a field is const or mut can be treated as the same canonical type.
Exploitation
Step 1: Build the casting chain
The researcher exploits the missing check with a casting chain:
struct {const ref null none} -> struct {const ref null any} -> struct {mut ref null any}
The first cast is through a legal subtype relationship. The last cast succeeds only because canonicalisation is broken and treats the two struct types as equal. The result is that a ref null none can be overwritten with a value of type ref null any, producing arbitrary Wasm type confusion.
Step 2: Force the hash collision
The researcher had shown in b/381696874 that a birthday attack can cause a hash collision and trigger such a bug. The attached PoC contains a precomputed hash-colliding struct type that uses either const ref null any or mut ref null any for its 40 field types.
Step 3: Obtain primitives and demonstrate impact
With the collision and the resulting type confusion in place, poc.js obtains in-sandbox exploit primitives and then crashes on an arbitrary caged write attempt from a JIT-compiled Wasm function. The attached exp.html pops calc on Windows x64 Chrome, tested against Canary 133.0.6877.0.
Root cause
CanonicalEquality::EqualStructType() compares struct fields using EqualValueType but omits any check of field mutability. Two struct types whose fields differ only in const versus mut therefore compare as equal during canonicalisation. Combined with a hash collision produced by a birthday attack, this lets an attacker make V8 treat a struct {const ref null any} and a struct {mut ref null any} as the same canonical type, so a cast that should be rejected succeeds and a ref null none field can be overwritten with a ref null any value.
The report states the bug was likely introduced by https://crrev.com/c/6049646 in M133, a change that attempts to fix b/379009132 by removing relative type indexes from canonical types. The commit was already backported to M132 (https://crrev.com/c/6049645) and M131 (https://crrev.com/c/6049646).
Impact
The attached exploit turns the type confusion into in-sandbox primitives and, on Windows x64 Chrome, pops calc. The crash state is a renderer crash on an arbitrary caged write attempt from a JIT-compiled Wasm function on d8, and arbitrary code execution on Chrome. The issue affects Chrome 131.0.6778.108, 132.0.6834.32 and 133.0.6848.0 through latest, on all operating systems.
Fix
The report does not describe the fix that was applied. The change that likely introduced the bug, https://crrev.com/c/6049646, removed relative type indexes from canonical types while fixing b/379009132, and was backported to M132 and M131. One possible fix would be to add the missing mutability comparison to CanonicalEquality::EqualStructType().
Variants to test
- Other canonicalisation equality functions that compare field or element lists: check whether they account for every attribute that affects type identity, such as mutability, nullability and reference kind. A positive result is two types that differ in one attribute being canonicalised to the same type.
- Struct types with many fields: the birthday attack in this report used a precomputed colliding struct type with 40 field types. Try generating collisions for other field counts and layouts, and confirm whether a colliding pair reaches the broken equality check.
- Casting chains through legal subtype relationships: look for other pairs where a legal cast plus a broken canonicalisation cast yields a write of a wider reference type into a narrower field. A positive result is a
ref null nonefield holding aref null anyvalue. - Backported branches: the introducing commit was backported to M132 and M131, so test those versions as well as M133 and later. A positive result is the same crash on an arbitrary caged write attempt from a JIT-compiled Wasm function.
What happened, in plain words
Chrome runs JavaScript and WebAssembly code inside a component called V8. WebAssembly, or Wasm for short, is a way to run programs in the browser at near-native speed, and it has its own system of types: descriptions of what kind of data a piece of code is allowed to hold. One of those type kinds is a struct, which is a bundle of named fields, a bit like a form with several boxes on it. Each field can be declared either changeable (mutable, written mut) or fixed (constant, written const).
V8 tries to be efficient by storing only one copy of each distinct type. When two types are truly the same, V8 gives them the same internal identity, a process called canonicalisation. To decide whether two struct types are the same, V8 compares them field by field. The bug in this report is that this comparison forgot to look at one thing: whether a field is const or mut. So two struct types that differ only in that respect can be treated as the same type. That is a type confusion: the engine believes a value is of one type when it is really of another, and it then lets code do things that should be forbidden.
The issue is tracked as CVE-2024-12692 and affects the V8 engine in Chrome. It is a variant of an earlier issue, b/381696874, meaning the researcher had already found a related problem and this one is a close relative.
Setup
The researcher tested against these Chrome versions, on all operating systems:
- 131.0.6778.108
- 132.0.6834.32
- 133.0.6848.0 through latest
Two files were attached to the report:
poc.js, a proof of concept. It uses the hash collision and the type confusion to obtain in-sandbox exploit primitives, then crashes on an arbitrary caged write attempt. It was run on d8, which is V8's own command-line shell for running JavaScript and Wasm outside the browser.exp.html, a full exploit that popscalc(opens the Windows calculator) on Windows x64 Chrome, tested against Canary 133.0.6877.0. Canary is Chrome's early, experimental release channel.
No accounts, roles or special tooling beyond a V8 or Chrome build are described.
Finding it
In the earlier report, b/381696874, the researcher had already shown that a broken CanonicalEquality check can be exploited. The trick is to use a birthday attack to cause a hash collision, which then triggers the bug. A hash is a short fingerprint computed from data; a hash collision is when two different pieces of data produce the same fingerprint. A birthday attack is a way of finding such a pair by trying many candidates, named after the surprising fact that in a room of only 23 people there is already a good chance two share a birthday.
Looking at the canonicalisation code, the researcher found that CanonicalEquality::EqualStructType() does not check the mutability of struct fields:
bool EqualStructType(const CanonicalStructType& type1,
const CanonicalStructType& type2) const {
return std::equal(
type1.fields().begin(), type1.fields().end(), type2.fields().begin(),
type2.fields().end(),
std::bind_front(&CanonicalEquality::EqualValueType, this));
}
Line by line, in plain words:
bool EqualStructType(...) const {declares a function that answers a yes/no question: are these two struct types equal? It takes two struct types,type1andtype2.return std::equal(starts a standard comparison of two sequences.type1.fields().begin(), type1.fields().end(),gives the start and end of the first struct's list of fields.type2.fields().begin(), type2.fields().end(),gives the start and end of the second struct's list of fields.std::bind_front(&CanonicalEquality::EqualValueType, this));says how to compare each pair of fields: use theEqualValueTypefunction belonging to this object.
The struct-level equality is missing mutability checks for its fields. That means two struct types that differ only in whether a field is const or mut can be treated as the same canonical type.
Exploitation
Step 1: Build the casting chain
A cast is an instruction that says "treat this value as this other type". The researcher exploits the missing check with a chain of casts:
struct {const ref null none} -> struct {const ref null any} -> struct {mut ref null any}
In plain words, this chain goes from a struct whose field is a constant reference to the none type, to a struct whose field is a constant reference to the any type, to a struct whose field is a mutable reference to the any type. A reference is a pointer-like handle to a value; none and any are Wasm reference types, where none is the most restrictive and any the most general.
The first cast is through a legal subtype relationship: none is a subtype of any, so moving from none to any is allowed by the rules. The last cast succeeds only because canonicalisation is broken and treats the two struct types as equal. The result is that a ref null none can be overwritten with a value of type ref null any, producing arbitrary Wasm type confusion. In everyday terms: a box labelled "only ever holds a very narrow kind of thing" ends up holding something much broader, and the engine no longer notices.
Step 2: Force the hash collision
The researcher had shown in b/381696874 that a birthday attack can cause a hash collision and trigger such a bug. The attached PoC contains a precomputed hash-colliding struct type that uses either const ref null any or mut ref null any for its 40 field types. In other words, the struct has 40 fields, and each one is a reference to any; the two versions differ only in whether those fields are constant or mutable, and they were precomputed so that their fingerprints match.
Step 3: Obtain primitives and demonstrate impact
With the collision and the resulting type confusion in place, poc.js obtains in-sandbox exploit primitives and then crashes on an arbitrary caged write attempt from a JIT-compiled Wasm function. A primitive here means a small, reliable building block that an attacker can reuse. The sandbox is the restricted environment the renderer runs in, and a caged write is a write to memory inside a reserved region (the cage) that the engine is supposed to police. JIT stands for just-in-time compilation: turning Wasm code into machine code while the program runs.
The attached exp.html pops calc on Windows x64 Chrome, tested against Canary 133.0.6877.0. Arbitrary code execution means the attacker can make the machine run code of their choosing, which is the most serious outcome for a browser bug.
Root cause
CanonicalEquality::EqualStructType() compares struct fields using EqualValueType but omits any check of field mutability. Two struct types whose fields differ only in const versus mut therefore compare as equal during canonicalisation. Combined with a hash collision produced by a birthday attack, this lets an attacker make V8 treat a struct {const ref null any} and a struct {mut ref null any} as the same canonical type, so a cast that should be rejected succeeds and a ref null none field can be overwritten with a ref null any value.
The report states the bug was likely introduced by https://crrev.com/c/6049646 in M133, a change that attempts to fix b/379009132 by removing relative type indexes from canonical types. The commit was already backported to M132 (https://crrev.com/c/6049645) and M131 (https://crrev.com/c/6049646). Backporting means copying a fix (or, here, a change) from a newer version onto an older one that is still supported.
Impact
The attached exploit turns the type confusion into in-sandbox primitives and, on Windows x64 Chrome, pops calc. The renderer is the part of the browser that actually runs web pages, kept separate from the rest of the browser for safety. The crash state is a renderer crash on an arbitrary caged write attempt from a JIT-compiled Wasm function on d8, and arbitrary code execution on Chrome. The issue affects Chrome 131.0.6778.108, 132.0.6834.32 and 133.0.6848.0 through latest, on all operating systems.
Fix
The report does not describe the fix that was applied. The change that likely introduced the bug, https://crrev.com/c/6049646, removed relative type indexes from canonical types while fixing b/379009132, and was backported to M132 and M131. One possible fix would be to add the missing mutability comparison to CanonicalEquality::EqualStructType().
Variants to test
- Other canonicalisation equality functions that compare field or element lists: check whether they account for every attribute that affects type identity, such as mutability, nullability and reference kind. A positive result is two types that differ in one attribute being canonicalised to the same type.
- Struct types with many fields: the birthday attack in this report used a precomputed colliding struct type with 40 field types. Try generating collisions for other field counts and layouts, and confirm whether a colliding pair reaches the broken equality check.
- Casting chains through legal subtype relationships: look for other pairs where a legal cast plus a broken canonicalisation cast yields a write of a wider reference type into a narrower field. A positive result is a
ref null nonefield holding aref null anyvalue. - Backported branches: the introducing commit was backported to M132 and M131, so test those versions as well as M133 and later. A positive result is the same crash on an arbitrary caged write attempt from a JIT-compiled Wasm function.
Glossary
- V8: the JavaScript and WebAssembly engine inside Chrome; it turns script code into machine code and runs it.
- WebAssembly (Wasm): a compact, fast binary format for running programs in the browser, with its own type system.
- Struct type: a Wasm type made of several named fields bundled together, like a form with several boxes.
- Field: one entry inside a struct type.
- Mutable (
mut): a field whose value is allowed to change after creation. - Constant (
const): a field whose value is fixed after creation. - Canonicalisation: giving every distinct type a single shared internal identity so equivalent types are stored once.
- Type confusion: a bug where the engine believes a value has one type when it really has another, letting code do forbidden things.
- CVE: a public identifier for a known security vulnerability.
- Variant: a closely related bug, here a relative of an earlier issue.
- b/381696874: the identifier of the earlier, related bug report.
- Hash: a short fingerprint computed from data.
- Hash collision: two different pieces of data producing the same fingerprint.
- Birthday attack: a way of finding a colliding pair by trying many candidates, named after the birthday paradox.
poc.js: the proof-of-concept script attached to the report.- Proof of concept (PoC): a small program that demonstrates a bug is real.
exp.html: the full exploit attached to the report.- Exploit: code that turns a bug into a practical attack.
- d8: V8's own command-line shell for running JavaScript and Wasm outside the browser.
- Canary: Chrome's early, experimental release channel.
- In-sandbox exploit primitives: small, reliable building blocks an attacker can reuse while still confined to the browser's restricted environment.
- Sandbox: the restricted environment the renderer runs in.
- Caged write: a write to memory inside a reserved region (the cage) that the engine is supposed to police.
- JIT (just-in-time compilation): turning code into machine code while the program runs.
- Arbitrary code execution: the attacker can make the machine run code of their choosing.
- Renderer: the part of the browser that runs web pages, kept separate from the rest of the browser for safety.
- Cast: an instruction that treats a value as another type.
- Reference: a pointer-like handle to a value.
noneandany: Wasm reference types, wherenoneis the most restrictive andanythe most general.- Subtype relationship: when one type is a narrower version of another and can legally be used where the wider one is expected.
- Backport: copying a change from a newer version onto an older, still-supported one.
- M131, M132, M133: Chrome milestone version numbers.