Type Confusion in V8 (CVE-2025-13226)
A type confusion flaw in the WebAssembly custom descriptors specification allows casting between unrelated struct types using ref.cast_desc because descriptor subtyping is incorrectly applied to the described structs. An attacker could exploit this to alias unrelated types and achieve an arbitrary write within the sandbox, potentially leading to remote code execution.
Originally disclosed on Chrome VRP
- Fix shipped in 40 days
...and a nail in the coffin for the custom descriptors proposal.
README
This is a Wasm spec-level unsoundness issue. Any runtime implementing the same spec faithfully will have the same bug. I am reporting this privately to Google Chrome/V8 as Google seems to be leading the spec work and implementation of custom descriptors the first and practically has the most affected users in the wild.
As this is a spec-level unsoundness which the Wasm community needs to know, I believe that the issue necessitates a quicker disclosure deadline than what is enforced by default by Chrome's disclosure policies. It would be great if we can coordinate the disclosure within a week from the reported date - please contact me through email or through the comments. Unless otherwise coordinated, the spec unsoundness issue is subject to a 14-day disclosure deadline after which the issue, without any specific mentions of Chrome/V8, will be disclosed publicly on https://github.com/WebAssembly/custom-descriptors/issues. The Chrome/V8 security team is allowed to responsibly disclose this to other vendors and personnel involved in WebAssembly work (at CG meetings or whatnot) under the conditions that 1. the reporter is credited, and 2. is given at least a day's advance notice.
VULNERABILITY DETAILS
Summary
Wasm type confusion due to fundamental spec unsoundness in custom descriptors. Described structs may be unrelated but have descriptors in subtyping relationship, where the descriptors' subtype relationship may be used to unsoundly cast between the described structs using ref.cast_desc or br_on_cast_desc*.
Custom descriptors feature is exposed in the wild by default through Origin Trials from M141, which is currently at Beta and very soon reaches (Early) Stable. This bug is not caused by a recent code change and has existed from the very first feature implementation (approx. 6 months) due to an inherent spec unsoundness.
Note: Since the custom descriptors spec itself is unsound, discussing about other implementation bugs may be pointless. However, each and every one of the bugs that I've reported are independent and triggers even without
cast_desc.
Details
WebAssembly Custom Descriptors proposal introduces descriptors and descriptor-based type checks. These casts/checks require that the described struct has a descriptor that matches the given descriptor at runtime. By spec definition, these operations allow subtype descriptors. Take for example ref.cast_desc:
ref.cast_desc reftype
C |- ref.cast_desc rt : (ref null ht) (ref null (exact_1 y)) -> rt
-- rt = (ref null? (exact_1 x))
-- C |- C.types[x] <: ht
-- C.types[x] ~ descriptor y ct
In the above rule:
- Descriptor on the stack is allowed to be any subtype of
(ref null (exact_1 y)), the descriptor type ofrt. htmay also be chosen asany, allowing any references within theanyrefhierarchy to be casted through this operation even without a direct subtype relationship betweenrt, the described type, given that the descriptor actually matches.
Let us revisit subtyping rules on custom descriptors:
- A declared supertype of a type with a
(descriptor $x)clause must either not have adescriptorclause or have a(descriptor $y)clause, where$yis a declared supertype of$x. - A declared supertype of a type without a
descriptorclause must also not have adescriptorclause. - A declared supertype of a type with a
describesclause must have adescribesclause. - A declared supertype of a type without a
describesclause must also not have adescribesclause. - With shared-everything-threads, ... (omitted)
...additionally with the following type validation rule:
- Descriptor and describes clauses must agree, i.e. a describing type must have a describes clause referring to its described type, which in turn must have a descriptor clause referring to the describing type.
Note how describes clause are not subject to subtyping. Thus, a type definition as shown below is perfectly legal:
(rec
(type $sup (sub (descriptor $sup.rtt (struct (field $sup-only i32)))))
(type $sup.rtt (sub (describes $sup (struct))))
(type $sub (sub (descriptor $sub.rtt (struct))))
(type $sub.rtt (sub $sup.rtt (describes $sub (struct))))
)
We do not declare $sub <: $sup nor enforce it transitively through $sub.rtt <: $sup.rtt -- $sub and $sup are unrelated. The spec also explicitly calls out such cases as legal, although with a broken example (type $other in the spec overview which lacks a matching descriptor). A non-broken example is in Issue #29.
Now consider a case where we execute the following:
(func $unsound (result i32)
(local $rtt (ref $sub.rtt))
;; Instantiate $sub.rtt => $rtt
(local.set $rtt (struct.new $sub.rtt))
;; Instantiate $sub with $rtt
(struct.new $sub (local.get $rtt))
;; Get $rtt again as the descriptor to compare on cast
(local.get $rtt)
;; Cast $sub to $sup using $rtt. This will succeed because $sub.rtt <: $sup.rtt
(ref.cast_desc (ref $sup))
;; Out-of-bounds read.
(struct.get $sup $sup-only)
)
All of the steps are perfectly legal based on the current custom descriptor spec, but is obviously unsound. Essentially, ref.cast_desc as well as any br_on_cast_desc* variants transitively applies subtyping relationship of the descriptors to its described struct type. This trivially results in type confusion between unrelated described struct types.
I am unsure what the spec intends to do here as the formulation is fundamentally broken. Maybe the spec intended to enforce a describes declared subtype check in the modified subtyping rules -- but an example in the spec overview explicitly calls out against this idea. Maybe it needs a stricter typecheck against the value on the stack by only allowing subtypes of rt (in this case, checking if (struct.new $sub (local.get $rtt)) is a subtyped object of ref $sup) -- but the spec overview explicitly relaxes this in issue #37, and even before this ref.cast_desc was broken from the start. Either might be a valid fix but with wildly different semantics which I am uncertain what is even intended here.
But another concern is: Are there no formally verified version of this proposal, either through SpecTec or by manual work? What is the spec trying to model with custom descriptors, and what is V8 currently implementing? We got away in b/365802567 by saying that it's just a terminology confict of the term "match" across different proposal spec evolved independently, but in this case the spec is just flat out unsound. I can understand implementations and minor spec revisions being a trial-and-error process, but almost the entirety of the spec being unsound while going all the way through deployment into stable channel (albeit OT) is honestly a bit concerning. Or am I missing something?
Bisect
Bug introduced by WebAssembly Custom Descriptors, on Origin Trials from M141 and onwards. More specifically, it is introduced in commit 7cb98588 which implements ref.cast_desc.
VERSION
Chrome Version: M141~
Operating System: All
REPRODUCTION CASE
Attached as poc.js which exploits this issue to alias two unrelated struct types, then uses this type confusion to trigger an arbitrary caged write within the sandbox.
Also attached is rce.html which exploits this issue, together with the wrapper-wasmcpt-uaf v8sbx bypass, to gain RCE and print out /flag/flag to stdout.
You might want to pass --experimental-wasm-custom-descriptors on d8 or --enable-blink-features=WebAssemblyCustomDescriptors on Chrome to simulate Origin Trials behavior.
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 with poc.js / RCE with rce.html
CREDIT INFORMATION
Reporter credit: Seunghyun Lee (@0x10n) of CMU CSD / CyLab
Context
This is a WebAssembly spec-level unsoundness in the Custom Descriptors proposal, reported to Google Chrome/V8 as a type confusion in V8 (CVE-2025-13226). The researcher, Seunghyun Lee (@0x10n) of CMU CSD / CyLab, frames it as a bug that any runtime implementing the same spec faithfully will have, because the problem is in the specification rather than in one implementation.
The Custom Descriptors proposal introduces descriptors and descriptor-based type checks. These casts and checks require that the described struct has a descriptor that matches the given descriptor at runtime. By spec definition, these operations allow subtype descriptors. The feature is exposed in the wild by default through Origin Trials from M141, which at the time of reporting was at Beta and about to reach (Early) Stable. The researcher notes the bug is not caused by a recent code change and has existed from the very first feature implementation, roughly six months, due to the inherent spec unsoundness.
The report is headed by the line "...and a nail in the coffin for the custom descriptors proposal."
Setup
No accounts, roles or special tooling are needed to understand the issue: it is a specification and implementation analysis. The relevant preconditions are:
- A runtime implementing the Custom Descriptors proposal, here V8 in Chrome M141 and later, on all operating systems.
- The feature enabled. For reproduction the researcher suggests passing
--experimental-wasm-custom-descriptorson d8 or--enable-blink-features=WebAssemblyCustomDescriptorson Chrome to simulate Origin Trials behaviour. - Two attached files,
poc.jsandrce.html, which are not reproduced in the report text.poc.jsexploits the issue to alias two unrelated struct types and then uses the type confusion to trigger an arbitrary caged write within the sandbox.rce.htmlexploits the issue together with thewrapper-wasmcpt-uafv8sbx bypass to gain RCE and print out/flag/flagto stdout.
The report also states a disclosure position: because this is a spec-level unsoundness the Wasm community needs to know about, the researcher asks for coordination within a week of the reported date, and states that unless otherwise coordinated the spec unsoundness issue is subject to a 14-day disclosure deadline, after which it will be disclosed publicly on https://github.com/WebAssembly/custom-descriptors/issues without specific mentions of Chrome/V8. The Chrome/V8 security team is allowed to responsibly disclose it to other vendors and personnel involved in WebAssembly work under two conditions: the reporter is credited, and is given at least a day's advance notice.
Finding it
The researcher analysed the typing rules for the new descriptor-based casts. Take ref.cast_desc:
ref.cast_desc reftype
C |- ref.cast_desc rt : (ref null ht) (ref null (exact_1 y)) -> rt
-- rt = (ref null? (exact_1 x))
-- C |- C.types[x] <: ht
-- C.types[x] ~ descriptor y ct
In this rule:
- The descriptor on the stack is allowed to be any subtype of
(ref null (exact_1 y)), the descriptor type ofrt. htmay also be chosen asany, allowing any references within theanyrefhierarchy to be cast through this operation even without a direct subtype relationship betweenrt, the described type, given that the descriptor actually matches.
The subtyping rules on custom descriptors are then relevant:
- A declared supertype of a type with a
(descriptor $x)clause must either not have adescriptorclause or have a(descriptor $y)clause, where$yis a declared supertype of$x. - A declared supertype of a type without a
descriptorclause must also not have adescriptorclause. - A declared supertype of a type with a
describesclause must have adescribesclause. - A declared supertype of a type without a
describesclause must also not have adescribesclause. - With shared-everything-threads, ... (omitted in the report).
Additionally, the type validation rule states that descriptor and describes clauses must agree: a describing type must have a describes clause referring to its described type, which in turn must have a descriptor clause referring to the describing type.
The key observation is that describes clauses are not subject to subtyping. That makes the following type definition perfectly legal:
(rec
(type $sup (sub (descriptor $sup.rtt (struct (field $sup-only i32)))))
(type $sup.rtt (sub (describes $sup (struct))))
(type $sub (sub (descriptor $sub.rtt (struct))))
(type $sub.rtt (sub $sup.rtt (describes $sub (struct))))
)
Here $sub <: $sup is not declared, nor enforced transitively through $sub.rtt <: $sup.rtt: $sub and $sup are unrelated. The spec explicitly calls out such cases as legal, although with a broken example (type $other in the spec overview lacks a matching descriptor). A non-broken example is in Issue #29.
Exploitation
Step 1: instantiate the descriptor
The function starts by creating a value of the descriptor type $sub.rtt and storing it in a local:
(func $unsound (result i32)
(local $rtt (ref $sub.rtt))
;; Instantiate $sub.rtt => $rtt
(local.set $rtt (struct.new $sub.rtt))
Step 2: instantiate the described struct with that descriptor
The $sub struct is then created using the descriptor value:
;; Instantiate $sub with $rtt
(struct.new $sub (local.get $rtt))
Step 3: cast using the descriptor
The same descriptor is loaded again and used as the descriptor operand of ref.cast_desc targeting $sup:
;; Get $rtt again as the descriptor to compare on cast
(local.get $rtt)
;; Cast $sub to $sup using $rtt. This will succeed because $sub.rtt <: $sup.rtt
(ref.cast_desc (ref $sup))
The cast succeeds because $sub.rtt <: $sup.rtt, even though $sub and $sup are unrelated described types.
Step 4: read through the wrong type
The result is then read as if it were a $sup, accessing a field that the original $sub value does not have:
;; Out-of-bounds read.
(struct.get $sup $sup-only)
)
All of these steps are legal under the current custom descriptor spec, but the sequence is obviously unsound. In effect, ref.cast_desc and every br_on_cast_desc* variant transitively apply the subtyping relationship of the descriptors to the described struct type, which trivially results in type confusion between unrelated described struct types.
The attached poc.js uses this to alias two unrelated struct types and then trigger an arbitrary caged write within the sandbox. The crash type is Renderer, and the crash state is a crash on an arbitrary caged write attempt from a JIT-compiled Wasm function with poc.js, or RCE with rce.html.
Root cause
The unsoundness is in the specification: describes clauses are not subject to subtyping, so two described structs can be unrelated while their descriptors are in a subtype relationship. The cast instructions then accept a descriptor that is a subtype of the expected descriptor type, and that descriptor relationship is effectively transferred to the described types. The researcher notes that each of the bugs reported is independent and triggers even without cast_desc.
The report considers possible intended fixes but is unsure which semantics the spec intends, since the formulation is fundamentally broken. One possibility is enforcing a describes declared subtype check in the modified subtyping rules, but an example in the spec overview explicitly calls out against this idea. Another is a stricter typecheck against the value on the stack, only allowing subtypes of rt (in this case checking whether (struct.new $sub (local.get $rtt)) is a subtyped object of ref $sup), but the spec overview explicitly relaxes this in issue #37, and even before that ref.cast_desc was broken from the start. Either might be a valid fix, but with wildly different semantics.
The researcher also raises a process concern: whether there is no formally verified version of the proposal, either through SpecTec or by manual work, and what the spec is trying to model versus what V8 is implementing. A previous case, b/365802567, was explained away as a terminology conflict of the term "match" across independently evolved proposal specs, but here the spec is flat out unsound.
On the implementation side, the bug was introduced by the WebAssembly Custom Descriptors work, on Origin Trials from M141 onwards, specifically in commit 7cb98588, which implements ref.cast_desc.
Impact
Any runtime implementing the same spec faithfully will have the same bug, so the impact is not limited to V8. In Chrome, the feature is exposed by default through Origin Trials from M141, which was at Beta and about to reach (Early) Stable at the time of reporting, and the affected versions are M141 and later on all operating systems.
The demonstrated consequences are type confusion between unrelated described struct types, leading to an arbitrary caged write within the sandbox from a JIT-compiled Wasm function, and, combined with the wrapper-wasmcpt-uaf v8sbx bypass, RCE with /flag/flag printed to stdout. The report does not give further detail on the bypass or on the exploit chain beyond that.
Fix
The report does not describe a fix that was applied. It discusses two candidate directions, both of which the researcher presents as uncertain because the spec's intent is unclear: enforcing a describes declared subtype check in the subtyping rules, or a stricter typecheck on the stack value that only allows subtypes of rt. The report notes that the spec overview argues against the first and that issue #37 relaxes the second, and that ref.cast_desc was broken from the start regardless.
Variants to test
- Other descriptor-based casts. The report states that
ref.cast_descand everybr_on_cast_desc*variant transitively apply the descriptor subtyping relationship. A positive result is a branch that succeeds on a descriptor subtype while the described types are unrelated. - Other runtimes implementing the proposal. Because the issue is spec-level, any faithful implementation should be affected. A positive result is the same unrelated-struct aliasing on a different engine.
- Casts with
htchosen asany. The rule allowshtto beany, permitting casts across theanyrefhierarchy without a direct subtype relationship, provided the descriptor matches. A positive result is a successful cast between types with no declared relationship. - Shared-everything-threads interaction. The report's subtyping list includes a shared-everything-threads clause that is omitted. A positive result is the same unsound cast under shared types.
- Other spec-level proposals with descriptor-like matching. A previous case, b/365802567, involved the term "match" across independently evolved proposal specs. A positive result is a similar mismatch between what a spec models and what an implementation enforces.
What happened, in plain words
A security researcher found a flaw in a set of rules that describes how a part of web browsers should behave, rather than in one company's code. The rules belong to a proposed addition to WebAssembly, the technology that lets websites run fast, compiled programs inside the browser. The addition is called Custom Descriptors. Because the rules themselves are wrong, any browser that follows them correctly will have the same problem. The researcher reported it to Google Chrome and the V8 team (V8 is the part of Chrome that runs JavaScript and WebAssembly), and it was tracked as CVE-2025-13226, a type confusion in V8.
The researcher is Seunghyun Lee (@0x10n) of CMU CSD / CyLab. The report is headed by the line "...and a nail in the coffin for the custom descriptors proposal."
To understand the rest, you need three ideas:
- WebAssembly (Wasm): a way to write programs that browsers can run very quickly and safely. Websites use it for things like games, video editors and heavy calculations.
- A specification (spec): a written rulebook that says exactly what a feature must do. Different browsers can each write their own code, but if they all follow the same rulebook, they should all behave the same way.
- Type confusion: a class of bug where a program treats one kind of data as if it were a different kind. It is like a cloakroom attendant handing you a coat that belongs to someone else because the ticket numbers looked similar. The program then reads or writes memory that was never meant for it, which can crash the browser or, worse, let an attacker run their own code.
The Custom Descriptors feature adds a new way for Wasm programs to label their data, and new instructions that check those labels at runtime. The check is supposed to make sure that a piece of data really is the kind the program claims it is. The researcher found that the check can be fooled: two completely unrelated kinds of data can be made to look interchangeable, because the labels attached to them are related even though the data is not.
The feature was being tested in the real world through Origin Trials from Chrome version M141. An Origin Trial is a way for a website to switch on an unfinished browser feature for its own visitors, so the feature runs for real users before it becomes permanent. At the time of the report, M141 was at the Beta stage and about to reach (Early) Stable. The researcher notes the bug was not caused by a recent code change: it has existed since the very first implementation of the feature, roughly six months, because the flaw is in the rules themselves.
The disclosure request
The researcher explains why he asks for a quicker disclosure deadline than Chrome's default. Because the problem is in a shared specification, the whole WebAssembly community needs to know about it, not just Google. He asks for coordination within a week of the reported date. Unless something else is agreed, he states that the spec-level issue is subject to a 14-day disclosure deadline, after which it will be published on https://github.com/WebAssembly/custom-descriptors/issues without specific mentions of Chrome or V8. He allows the Chrome/V8 security team to share it responsibly with other browser makers and people involved in WebAssembly work, such as at community group meetings, on two conditions: the reporter is credited, and he gets at least a day's advance notice.
What you need in place to follow along
No accounts, roles or special tools are needed to understand the issue. It is an analysis of a specification and of one implementation of it. The preconditions are:
- A runtime that implements the Custom Descriptors proposal. Here that is V8 in Chrome M141 and later, on all operating systems. A runtime is the software that actually executes a program; V8 is Chrome's runtime for JavaScript and Wasm.
- The feature switched on. For reproduction, the researcher suggests passing
--experimental-wasm-custom-descriptorson d8 or--enable-blink-features=WebAssemblyCustomDescriptorson Chrome, to simulate the Origin Trials behaviour. d8 is a bare-bones command-line version of V8 used by developers for testing. A command-line flag is an extra word you add when starting a program to change how it behaves. - Two attached files,
poc.jsandrce.html, which are not reproduced in the report text. PoC stands for proof of concept: a small demonstration that the bug is real.poc.jsexploits the issue to make two unrelated struct types share the same memory (the report calls this aliasing), then uses the type confusion to trigger an arbitrary caged write within the sandbox.rce.htmlexploits the issue together with thewrapper-wasmcpt-uafv8sbx bypass to gain RCE and print out/flag/flagto stdout. In plain terms: a sandbox is a wall around the browser's memory so that a bug cannot easily reach the rest of the computer; a caged write is a write to memory inside that wall; RCE (remote code execution) means an attacker gets their own code running on the machine; stdout is the normal text output of a program; and/flag/flagis a file the exploit prints, the kind of marker used in security competitions to prove success. The report does not give further detail on the bypass or the exploit chain.
Finding it
The researcher started by reading the typing rules for the new descriptor-based casts. A typing rule is a precise statement in the rulebook of the form "this instruction is allowed when these conditions hold". Think of it as the conditions a bouncer checks before letting someone into a club.
Here is the rule for one instruction, ref.cast_desc:
ref.cast_desc reftype
C |- ref.cast_desc rt : (ref null ht) (ref null (exact_1 y)) -> rt
-- rt = (ref null? (exact_1 x))
-- C |- C.types[x] <: ht
-- C.types[x] ~ descriptor y ct
Line by line, in plain words:
ref.cast_desc reftypenames the instruction and says it takes a type as an argument.- The long line with the arrow is the rule itself: given a context
C(the set of all known types), the instruction takes two things from the stack, a reference of type(ref null ht)and a descriptor of type(ref null (exact_1 y)), and produces a result of typert. The stack is the workspace where a running program keeps the values it is working on, like a stack of plates. rt = (ref null? (exact_1 x))says the target typertis a reference to the exact typex(the question mark means it may or may not be allowed to be null, i.e. empty).C.types[x] <: htsays the typexmust be a subtype ofht. Subtype means "is a more specific version of": a cat is a subtype of an animal. The symbol<:is read "is a subtype of".C.types[x] ~ descriptor y ctsays the typexis described by the descriptor typeywith contentsct.
Two details in this rule matter:
- The descriptor on the stack is allowed to be any subtype of
(ref null (exact_1 y)), the descriptor type ofrt. In other words, the bouncer accepts not only the exact expected label but also any more specific label. htmay also be chosen asany, which allows any reference within theanyrefhierarchy to be cast through this operation even without a direct subtype relationship betweenrt, the described type, given that the descriptor actually matches. The anyref hierarchy is the family of all reference types in Wasm;anyis the top of that family, the way "thing" is the top of every category of object.
The researcher then looked at the subtyping rules for custom descriptors:
- A declared supertype of a type with a
(descriptor $x)clause must either not have adescriptorclause or have a(descriptor $y)clause, where$yis a declared supertype of$x. - A declared supertype of a type without a
descriptorclause must also not have adescriptorclause. - A declared supertype of a type with a
describesclause must have adescribesclause. - A declared supertype of a type without a
describesclause must also not have adescribesclause. - With shared-everything-threads, ... (omitted in the report).
A clause here is a small annotation attached to a type definition, like a note in a passport. descriptor says which label type belongs to a piece of data; describes says which piece of data a label type belongs to. A declared supertype is a parent type that the programmer explicitly names. shared-everything-threads is a separate proposal about sharing data between threads (independent streams of execution); the report leaves that part out.
On top of that, the type validation rule says descriptor and describes clauses must agree: a describing type must have a describes clause referring to its described type, which in turn must have a descriptor clause referring to the describing type. In everyday terms, the label on the coat and the ticket in the cloakroom must point at each other.
The key observation is that describes clauses are not subject to subtyping. That means the following type definition is perfectly legal:
(rec
(type $sup (sub (descriptor $sup.rtt (struct (field $sup-only i32)))))
(type $sup.rtt (sub (describes $sup (struct))))
(type $sub (sub (descriptor $sub.rtt (struct))))
(type $sub.rtt (sub $sup.rtt (describes $sub (struct))))
)
Line by line:
(recopens a group of type definitions that can refer to each other, like a set of forms filled in together.(type $sup (sub (descriptor $sup.rtt (struct (field $sup-only i32)))))defines a type named$sup. It is a struct (a bundle of named fields, like a record card) with one field called$sup-onlyholding a 32-bit integer (i32). Its descriptor is the type$sup.rtt.(type $sup.rtt (sub (describes $sup (struct))))defines the label type$sup.rtt, which describes$supand is itself an empty struct.(type $sub (sub (descriptor $sub.rtt (struct))))defines a second struct type$sub, with no fields, whose descriptor is$sub.rtt.(type $sub.rtt (sub $sup.rtt (describes $sub (struct))))defines the label type$sub.rttas a subtype of$sup.rtt, describing$sub.- The closing
)ends the group.
Here $sub <: $sup is not declared, nor enforced transitively through $sub.rtt <: $sup.rtt: $sub and $sup are unrelated. The spec explicitly calls out such cases as legal, although with a broken example (type $other in the spec overview lacks a matching descriptor). A non-broken example is in Issue #29. In plain words: the two data types are strangers to each other, but their labels are parent and child. The rulebook says that is fine.
Exploitation
Step 1: instantiate the descriptor
The function starts by creating a value of the descriptor type $sub.rtt and storing it in a local:
(func $unsound (result i32)
(local $rtt (ref $sub.rtt))
;; Instantiate $sub.rtt => $rtt
(local.set $rtt (struct.new $sub.rtt))
Line by line:
(func $unsound (result i32)starts a function named$unsoundthat will return a 32-bit integer.(local $rtt (ref $sub.rtt))declares a local variable named$rttthat holds a reference to a$sub.rtt. A local is a named storage slot inside a function, like a pocket.;; Instantiate $sub.rtt => $rttis a comment, ignored by the machine.(local.set $rtt (struct.new $sub.rtt))creates a new empty struct of type$sub.rttand puts it in the pocket. This is the label the attacker will reuse later.
Why this step: the exploit needs a real label object to present to the check in step 3.
Step 2: instantiate the described struct with that descriptor
The $sub struct is then created using the descriptor value:
;; Instantiate $sub with $rtt
(struct.new $sub (local.get $rtt))
Line by line:
- The comment says what is happening.
(struct.new $sub (local.get $rtt))creates a new struct of type$sub, taking the label out of the pocket (local.get $rtt) and attaching it. Now there is a genuine$subobject carrying a genuine$sub.rttlabel.
Why this step: the attacker needs a real object of the unrelated type to try to pass off as the other one.
Step 3: cast using the descriptor
The same descriptor is loaded again and used as the descriptor operand of ref.cast_desc targeting $sup:
;; Get $rtt again as the descriptor to compare on cast
(local.get $rtt)
;; Cast $sub to $sup using $rtt. This will succeed because $sub.rtt <: $sup.rtt
(ref.cast_desc (ref $sup))
Line by line:
(local.get $rtt)takes the label out of the pocket again.(ref.cast_desc (ref $sup))asks the runtime: "treat the object on the stack as a$sup, and check it against this label". The check succeeds because$sub.rtt <: $sup.rtt: the label is a subtype of the label the check expects. The object itself, however, is a$sub, which has nothing to do with$sup.
Why this step: this is the heart of the bug. The check looks at the label, not at the real relationship between the two data types, so it waves through an object it should reject.
Step 4: read through the wrong type
The result is then read as if it were a $sup, accessing a field that the original $sub value does not have:
;; Out-of-bounds read.
(struct.get $sup $sup-only)
)
Line by line:
(struct.get $sup $sup-only)reads the field$sup-onlyfrom the object, believing it is a$sup. But the object is really a$sub, which has no such field. The read goes past the end of the real data, which is why the comment calls it an out-of-bounds read. Out-of-bounds means reading or writing outside the area that was set aside for the data.- The final
)closes the function.
Why this step: this turns the confusion into a concrete memory error. Reading the wrong memory is the first rung of the ladder towards controlling it.
All of these steps are legal under the current custom descriptor spec, but the sequence is obviously unsound. Unsound means the rules can be used to prove something false, here that a $sub is a $sup. In effect, ref.cast_desc and every br_on_cast_desc* variant transitively apply the subtyping relationship of the descriptors to the described struct type, which trivially results in type confusion between unrelated described struct types. The br_on_cast_desc* family are related instructions that branch (jump) depending on the result of a descriptor check; they inherit the same flaw.
The attached poc.js uses this to alias two unrelated struct types and then trigger an arbitrary caged write within the sandbox. The crash type is Renderer, and the crash state is a crash on an arbitrary caged write attempt from a JIT-compiled Wasm function with poc.js, or RCE with rce.html. A renderer is the browser process that turns web pages into what you see; it is deliberately kept in a sandbox so that a crash or compromise there does not take down the whole browser. JIT-compiled means the code was translated into machine instructions on the fly for speed, which makes the resulting memory error harder to contain.
Root cause
The unsoundness is in the specification: describes clauses are not subject to subtyping, so two described structs can be unrelated while their descriptors are in a subtype relationship. The cast instructions then accept a descriptor that is a subtype of the expected descriptor type, and that descriptor relationship is effectively transferred to the described types. The researcher notes that each of the bugs reported is independent and triggers even without cast_desc.
The report considers possible intended fixes but is unsure which semantics the spec intends, since the formulation is fundamentally broken. One possibility is enforcing a describes declared subtype check in the modified subtyping rules, but an example in the spec overview explicitly calls out against this idea. Another is a stricter typecheck against the value on the stack, only allowing subtypes of rt (in this case checking whether (struct.new $sub (local.get $rtt)) is a subtyped object of ref $sup), but the spec overview explicitly relaxes this in issue #37, and even before that ref.cast_desc was broken from the start. Either might be a valid fix, but with wildly different semantics. Semantics means the meaning of the rules: what programs are supposed to do.
The researcher also raises a process concern: whether there is no formally verified version of the proposal, either through SpecTec or by manual work, and what the spec is trying to model versus what V8 is implementing. Formally verified means checked by machine, with mathematical proof, rather than by reading and testing. SpecTec is a tool for writing language specifications in a form that can be checked and turned into code. A previous case, b/365802567, was explained away as a terminology conflict of the term "match" across independently evolved proposal specs, but here the spec is flat out unsound.
On the implementation side, the bug was introduced by the WebAssembly Custom Descriptors work, on Origin Trials from M141 onwards, specifically in commit 7cb98588, which implements ref.cast_desc. A commit is a recorded change to a codebase, with an identifier; the report links to it as crrev.com/c/6400936.
Impact
Any runtime implementing the same spec faithfully will have the same bug, so the impact is not limited to V8. In Chrome, the feature is exposed by default through Origin Trials from M141, which was at Beta and about to reach (Early) Stable at the time of reporting, and the affected versions are M141 and later on all operating systems.
The demonstrated consequences are type confusion between unrelated described struct types, leading to an arbitrary caged write within the sandbox from a JIT-compiled Wasm function, and, combined with the wrapper-wasmcpt-uaf v8sbx bypass, RCE with /flag/flag printed to stdout. The report does not give further detail on the bypass or on the exploit chain beyond that.
Fix
It discusses two candidate directions, both of which the researcher presents as uncertain because the spec's intent is unclear: enforcing a describes declared subtype check in the subtyping rules, or a stricter typecheck on the stack value that only allows subtypes of rt. The report notes that the spec overview argues against the first and that issue #37 relaxes the second, and that ref.cast_desc was broken from the start regardless.
Variants to test
These are other places where the same underlying mistake might show up. For each, the report describes what a positive result would look like.
- Other descriptor-based casts. The report states that
ref.cast_descand everybr_on_cast_desc*variant transitively apply the descriptor subtyping relationship. A positive result is a branch that succeeds on a descriptor subtype while the described types are unrelated. - Other runtimes implementing the proposal. Because the issue is spec-level, any faithful implementation should be affected. A positive result is the same unrelated-struct aliasing on a different engine.
- Casts with
htchosen asany. The rule allowshtto beany, permitting casts across theanyrefhierarchy without a direct subtype relationship, provided the descriptor matches. A positive result is a successful cast between types with no declared relationship. - Shared-everything-threads interaction. The report's subtyping list includes a shared-everything-threads clause that is omitted. A positive result is the same unsound cast under shared types.
- Other spec-level proposals with descriptor-like matching. A previous case, b/365802567, involved the term "match" across independently evolved proposal specs. A positive result is a similar mismatch between what a spec models and what an implementation enforces.
Glossary
- Aliasing: making two different things refer to the same memory, so that changing one changes the other.
- anyref hierarchy: the family of all reference types in Wasm, with
anyat the top. - API: a defined way for one piece of software to ask another to do something, like a menu of allowed requests.
- Beta / Stable: stages in a browser's release cycle; Beta is a test release before the final Stable one.
- br_on_cast_desc*: a family of Wasm instructions that branch depending on the result of a descriptor-based cast.
- Caged write: a write to memory inside the sandbox's reserved memory area.
- Clause: a small annotation attached to a type definition, such as
descriptorordescribes. - Commit: a recorded change to a codebase, identified by a hash.
- CVE: a public identifier for a known security vulnerability.
- Declared supertype: a parent type that a programmer explicitly names in a definition.
- Descriptor: a label object attached to a piece of data, used by the new checks.
- describes clause: the annotation saying which piece of data a label type belongs to.
- d8: a bare-bones command-line version of V8 used for testing.
- Formally verified: checked by machine with mathematical proof rather than by reading and testing.
- JIT-compiled: translated into machine instructions on the fly for speed.
- Local: a named storage slot inside a function.
- Origin Trial: a way for a website to switch on an unfinished browser feature for its own visitors.
- Out-of-bounds: reading or writing outside the area set aside for the data.
- PoC (proof of concept): a small demonstration that a bug is real.
- RCE (remote code execution): an attacker gets their own code running on the machine.
- Renderer: the browser process that turns web pages into what you see, kept in a sandbox.
- Runtime: the software that actually executes a program.
- Sandbox: a wall around a process's memory so a bug cannot easily reach the rest of the computer.
- Semantics: the meaning of the rules; what programs are supposed to do.
- shared-everything-threads: a separate proposal about sharing data between threads.
- Spec (specification): a written rulebook saying exactly what a feature must do.
- SpecTec: a tool for writing language specifications in a checkable form.
- Stack: the workspace where a running program keeps the values it is working on.
- stdout: the normal text output of a program.
- Struct: a bundle of named fields, like a record card.
- Subtype: a more specific version of a type; a cat is a subtype of an animal.
- Type confusion: a bug where a program treats one kind of data as another kind.
- Typing rule: a precise statement of when an instruction is allowed.
- Unsound: a rule set that can be used to prove something false.
- V8: the part of Chrome that runs JavaScript and WebAssembly.
- Wasm (WebAssembly): a way to write programs that browsers run quickly and safely.