Skip to content
Memory corruption Advisory Advanced CVE-2025-13228

Type Confusion in V8 (CVE-2025-13228)

A type confusion in V8's WebAssembly custom descriptors implementation allows an attacker to treat a descriptor of a subtype as an exact supertype, leading to arbitrary type confusion and potentially arbitrary caged write within the sandbox. The reporter also demonstrates RCE when combined with a separate sandbox bypass.

Seunghyun Lee Follow

Originally disclosed on Chrome VRP

Bounty$55,000 High View original
  • Fix shipped in 40 days

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 spec unsoundness around ref.get_desc exactness typing. Spec describes two different rules for ref.get_desc:

  • (Rule #1) Rule in the codeblock indicates that ref.get_desc must type the result as exact only when the stack type is a subtype of the exact encoded type (thus only allowing the exact encoded type). This rule is sound.
  • (Rule #2) Rule written in plain English indicates that "If the provided reference is to an exact heap type, then the type of the custom descriptor is known precisely, so the result can be exact as well". In other words, the provided reference's exactness directly propagates to the result type. However, the result type in this case MUST be typed as the provided reference's descriptor type, not the encoded immediate type's descriptor type. This rule is also sound (if done right) but is different than the first rule.
  • However, mixing the two up yields an unsound rule, e.g. by propagating the provided reference's exactness to the result type (Rule #2), but taking the base result type from the encoded immediate type's descriptor (Rule #1). The spec is unsound in that it describes two completely different rules as if it is the same ref.get_desc.

V8 also gets confused and implements the unsound rule, transferring the exactness of the stack type to the result type while using the encoded immediate type's descriptor. This allows typing the resulting descriptor as an exact supertype, leading to type confusion.

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.

Details

Spec indicates that ref.get_desc must type the result as exact only when the stack type is a subtype of the exact sourcetype:

ref.get_desc typeidx

C |- ref.get_desc x : (ref null (exact_1 x)) -> (ref (exact_1 y))
-- C.types[x] ~ descriptor y ct

For example, take x' <: x with C.types[x'] ~ descriptor y' ct' where C |- ¬(C.types[x'] ~ C.types[x]) - that is, x' is a strict subtype of x. Due to subtyping rules on descriptors, y' <: y holds. If ref exact x' is passed to ref.get_desc x:

Stack: ref exact x'
Match: ref exact x' <: ref null x => exact_1 = inexact
=> ref.get_desc x (ref exact x') -> (ref y)

Since ¬(ref exact x' <: ref null exact x), exact_1 = inexact is the only suitable rule and the resulting descriptor type must be inexact.

However, the spec also describes this rule in plain English but with different typing rules:

If the provided reference is to an exact heap type, then the type of the custom descriptor is known precisely, so the result can be exact as well. Otherwise, the subtyping rules described above ensure that there will be some custom descriptor value and that it will be a subtype of the custom descriptor type for x, so the result can be a non-null reference to the inexact descriptor type.

This may be interpreted as a weakened, unsound rule that translates to the below rule:

ref.get_desc? typeidx

C |- ref.get_desc? x : (ref null (exact_1 x')) -> (ref (exact_1 y))
-- C.types[x] ~ descriptor y ct
-- C.types[x'] ~ descriptor y' ct'
-- C |- x' <: x                                                                     // [!] (modified) subtype check

Note that we've subtly weakened the rule on the input type, effectively passing on the exactness of whatever was on the stack instead of typechecking stacktype <: ref null exact x. We also derive y from the encoded type x, not the provided type on the stack. This yields the results below:

Stack: ref exact x'
Match: (ref exact x' <: ref null exact x') ∧ (x' <: x) => exact_1 = exact
=> ref.get_desc? x (ref exact x') -> (ref exact y)

V8's implementation takes the weakened, unsound rule:

CC
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/function-body-decoder-impl.h;drc=43df3221d3b0c1ea8f7d54394a00cb8656204085;l=5994
      case kExprRefGetDesc: {
        // ...
        StructIndexImmediate imm(this, this->pc_ + opcode_length, validate);
        if (!this->Validate(this->pc_ + opcode_length, imm)) return 0;
        const TypeDefinition& type = this->module_->type(imm.index);
        if (!VALIDATE(type.has_descriptor())) {
          // ...
          return 0;
        }
        Value ref = Pop(ValueType::RefNull(imm.heap_type()));                       // [!] (modified) subtype check
        Value* desc =
            Push(ValueType::Ref(this->module_->heap_type(type.descriptor))
                     .AsExact(ref.type.exactness()));                               // [!] exactness directly from stack type (x')
        CALL_INTERFACE_IF_OK_AND_REACHABLE(RefGetDesc, ref, desc);
        return opcode_length + imm.length;
      }

Now we have ref exact y' typed as ref exact y where y' <: y. This pokes a hole in the type system exactly as described in the proposal docs, allowing attackers to invalidly type a descriptor y' into an exact supertype y, instantiate struct x, then invalidly cast down to x'. This leads to type confusion between arbitrary Wasm types.

This seems to be a very common misinterpretation of the spec. Development work on Binaryen also shows this misunderstanding: "ref.get_desc inherits its input ref's exactness..." which is only true when the reference type's descriptor is used as the return type (which from a cursory glance may be what Binaryen's doing). This leads me to wonder if the spec was initially designed to represent something like Rule #1, but happened to be written down in a different thing described as Rule #2, and then things got messy? Slides from CG meeting for Phase 2 advancement of the proposal also mix up the two, stating the formal rule as Rule #1 but uses the phrase "propagates exactness of references" which applies on Rule #2.

Bisect

Bug introduced by WebAssembly Custom Descriptors, on Origin Trials from M141 and onwards. More specifically, it is introduced in commit 2f4c043d which implements ref.get_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

The original report as published on the Chromium issue tracker, by Seunghyun Lee (@0x10n). 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. 9 min read.

Context

This report concerns the WebAssembly custom descriptors proposal and its implementation in V8, the JavaScript and WebAssembly engine used by Google Chrome. The feature adds a descriptor to a struct type, so that a struct value carries a reference to another heap type that describes it. The proposal introduces new instructions, among them ref.get_desc, which takes a reference to a struct and returns a reference to that struct's custom descriptor.

The researcher frames the issue as a spec-level unsoundness rather than a V8-only coding mistake: any runtime that implements the same specification faithfully will have the same bug. It was reported privately to Google Chrome/V8 on the basis that Google appears to be leading the spec work and the implementation of custom descriptors, and practically has the most affected users in the wild.

The feature was exposed in the wild by default through Origin Trials from M141, which at the time of the report was at Beta and about to reach (Early) Stable. The bug was not caused by a recent code change: it had existed from the very first feature implementation, roughly six months, because of the inherent spec unsoundness.

Setup

No accounts, roles or remote infrastructure are involved. The work is a reading of the specification against the V8 source, followed by local reproduction.

The relevant versions and conditions are:

  • Chrome Version: M141 and later.
  • Operating System: All.
  • The bug is introduced by the WebAssembly Custom Descriptors feature, on Origin Trials from M141 onwards, specifically in commit 2f4c043d, which implements ref.get_desc.
  • To simulate Origin Trials behaviour, the researcher suggests passing --experimental-wasm-custom-descriptors on d8, or --enable-blink-features=WebAssemblyCustomDescriptors on Chrome.

Two attachments accompany the report: poc.js, which exploits the issue to alias two unrelated struct types and then trigger an arbitrary caged write within the sandbox, and rce.html, which combines the issue with the wrapper-wasmcpt-uaf v8sbx bypass to gain RCE and print /flag/flag to stdout.

Finding it

The specification describes two different rules for ref.get_desc, and the researcher separates them explicitly.

  • Rule #1 is the rule in the code block. It says ref.get_desc must type the result as exact only when the stack type is a subtype of the exact encoded type, thus only allowing the exact encoded type. This rule is sound.
  • Rule #2 is the rule written in plain English: "If the provided reference is to an exact heap type, then the type of the custom descriptor is known precisely, so the result can be exact as well". In other words, the provided reference's exactness directly propagates to the result type. For this to be sound, the result type must be the provided reference's descriptor type, not the encoded immediate type's descriptor type. Done that way the rule is also sound, but it is different from the first rule.
  • Mixing the two yields an unsound rule: propagate the provided reference's exactness to the result type (Rule #2), but take the base result type from the encoded immediate type's descriptor (Rule #1). The specification is unsound in that it describes two completely different rules as if they were the same ref.get_desc.

V8 gets confused in the same way and implements the unsound rule, transferring the exactness of the stack type to the result type while using the encoded immediate type's descriptor. That allows the resulting descriptor to be typed as an exact supertype, which leads to type confusion.

The formal rule in the specification is:

Text
ref.get_desc typeidx

C |- ref.get_desc x : (ref null (exact_1 x)) -> (ref (exact_1 y))
-- C.types[x] ~ descriptor y ct

The researcher walks through the consequence. Take x' <: x with C.types[x'] ~ descriptor y' ct' where C |- ¬(C.types[x'] ~ C.types[x]), that is, x' is a strict subtype of x. Due to subtyping rules on descriptors, y' <: y holds. If ref exact x' is passed to ref.get_desc x:

Text
Stack: ref exact x'
Match: ref exact x' <: ref null x => exact_1 = inexact
=> ref.get_desc x (ref exact x') -> (ref y)

Since ¬(ref exact x' <: ref null exact x), exact_1 = inexact is the only suitable rule and the resulting descriptor type must be inexact.

The plain English text in the specification reads:

If the provided reference is to an exact heap type, then the type of the custom descriptor is known precisely, so the result can be exact as well. Otherwise, the subtyping rules described above ensure that there will be some custom descriptor value and that it will be a subtype of the custom descriptor type for x, so the result can be a non-null reference to the inexact descriptor type.

That can be interpreted as a weakened, unsound rule:

Text
ref.get_desc? typeidx

C |- ref.get_desc? x : (ref null (exact_1 x')) -> (ref (exact_1 y))
-- C.types[x] ~ descriptor y ct
-- C.types[x'] ~ descriptor y' ct'
-- C |- x' <: x                                                                     // [!] (modified) subtype check

The rule on the input type has been subtly weakened, effectively passing on the exactness of whatever was on the stack instead of typechecking stacktype <: ref null exact x. The result type y is also derived from the encoded type x, not from the provided type on the stack. That produces:

Text
Stack: ref exact x'
Match: (ref exact x' <: ref null exact x') ∧ (x' <: x) => exact_1 = exact
=> ref.get_desc? x (ref exact x') -> (ref exact y)

The researcher notes this appears to be a very common misinterpretation. Development work on Binaryen also shows the misunderstanding: "ref.get_desc inherits its input ref's exactness...", which is only true when the reference type's descriptor is used as the return type, which from a cursory glance may be what Binaryen is doing. This leads the researcher to wonder whether the spec was initially designed to represent something like Rule #1 but happened to be written down as Rule #2, after which things got messy. Slides from the CG meeting for Phase 2 advancement of the proposal also mix up the two, stating the formal rule as Rule #1 but using the phrase "propagates exactness of references", which applies to Rule #2.

Exploitation

The exploitation follows directly from the typing hole. The researcher describes the chain as follows.

Step 1: obtain an exact descriptor of the wrong type

Because V8 implements the weakened rule, a value of type ref exact y' is typed as ref exact y where y' <: y. This pokes a hole in the type system exactly as described in the proposal docs on exact types.

Step 2: invalidly type a descriptor as an exact supertype

The attacker uses that hole to invalidly type a descriptor y' into an exact supertype y.

Step 3: instantiate and cast down

The attacker instantiates struct x and then invalidly casts down to x'. This leads to type confusion between arbitrary Wasm types.

Step 4: turn the confusion into memory access

The attached poc.js exploits the issue to alias two unrelated struct types, then uses this type confusion to trigger an arbitrary caged write within the sandbox. The crash state recorded for the report is: crashes on arbitrary caged write attempt from JIT-compiled Wasm function with poc.js, and RCE with rce.html.

Step 5: escape the sandbox

The attached rce.html exploits the issue together with the wrapper-wasmcpt-uaf v8sbx bypass to gain RCE and print out /flag/flag to stdout.

The crash type is Renderer.

Root cause

The mistake is in the specification and is mirrored in the implementation. The specification gives two rules for ref.get_desc that are not the same rule: the formal code block (Rule #1) and the plain English paragraph (Rule #2). Rule #2 is sound only if the result type is the provided reference's descriptor type. V8 implements the unsound mixture: it propagates the exactness of the stack type to the result, but takes the base result type from the encoded immediate type's descriptor.

The relevant V8 code, as quoted in the report:

CC
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/function-body-decoder-impl.h;drc=[redacted];l=5994
      case kExprRefGetDesc: {
        // ...
        StructIndexImmediate imm(this, this->pc_ + opcode_length, validate);
        if (!this->Validate(this->pc_ + opcode_length, imm)) return 0;
        const TypeDefinition& type = this->module_->type(imm.index);
        if (!VALIDATE(type.has_descriptor())) {
          // ...
          return 0;
        }
        Value ref = Pop(ValueType::RefNull(imm.heap_type()));                       // [!] (modified) subtype check
        Value* desc =
            Push(ValueType::Ref(this->module_->heap_type(type.descriptor))
                     .AsExact(ref.type.exactness()));                               // [!] exactness directly from stack type (x')
        CALL_INTERFACE_IF_OK_AND_REACHABLE(RefGetDesc, ref, desc);
        return opcode_length + imm.length;
      }

The two marked lines are the problem. The popped value is checked against RefNull(imm.heap_type()), a plain subtype check against the encoded type, rather than against the exact encoded type. The pushed descriptor is built from type.descriptor, the descriptor of the encoded immediate type, and then .AsExact(ref.type.exactness()) copies the exactness of the stack type onto it. That is exactly the unsound combination: exactness from the stack, descriptor from the immediate.

The bug was present from the first implementation of the feature and shipped through Origin Trials, so there was no earlier, sound version to compare against. The researcher also points to the same misreading in Binaryen and in the CG slides, which suggests the ambiguity was easy to reproduce across independent implementations.

Impact

Within the renderer, the type confusion allows aliasing of two unrelated struct types. The poc.js attachment turns that into an arbitrary caged write within the sandbox from a JIT-compiled Wasm function. Combined with the wrapper-wasmcpt-uaf v8sbx bypass, rce.html gains RCE and prints /flag/flag to stdout.

The report says the feature was exposed in the wild by default through Origin Trials from M141, on all operating systems. The report does not give a CVSS score. The platform records the severity as high and a bounty of 55,000 USD.

Fix

The report does not describe a patch. It identifies the specification as unsound: it describes two different rules for ref.get_desc as if they were the same instruction. The report also notes that the same misreading appears in Binaryen and in the CG slides.

Variants to test

  1. Other engines implementing custom descriptors. Take the same x' <: x setup with ref exact x' passed to ref.get_desc x and check whether the result is typed as exact. A positive result is a validator that accepts the exact result type while the descriptor comes from the encoded immediate, which is the unsound combination.
  2. Toolchain producers. Feed the same pattern through a compiler or optimiser that claims ref.get_desc inherits its input reference's exactness, as Binaryen's change description does. A positive result is output that relies on the inherited exactness while using the encoded type's descriptor.
  3. Specification text versus formal rule. Compare the code block and the plain English paragraph for any instruction that propagates exactness. A positive result is a paragraph that can be read as propagating exactness without pinning the result to the provided reference's descriptor type.
  4. Exactness propagation in adjacent instructions. Any instruction that takes an exact reference and returns a type derived from an immediate is worth the same test: does the result's exactness come from the stack, and does its base type come from the immediate? A positive result is a validator that accepts an exact result whose base type is not the one the stack value actually carries.
  5. Origin Trials gating. Run the reproduction with --experimental-wasm-custom-descriptors on d8 and with --enable-blink-features=WebAssemblyCustomDescriptors on Chrome to confirm behaviour matches the trial configuration. A positive result is the same type confusion under both flags.

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. 22 min read.

What happened, in plain words

A security researcher found a flaw in a new feature of WebAssembly, the low-level language that runs inside web browsers alongside JavaScript. The flaw is not a simple coding slip in one program. It is a mistake in the written rulebook (the specification) that describes how the feature should behave, and the browser engine that Google makes, V8, copied the mistake. Because the rulebook itself is wrong, any browser engine that follows it faithfully will have the same problem.

The feature is called custom descriptors. It lets a piece of data carry a label that says what kind of thing it is. The flaw lets a malicious web page convince the browser that one kind of data is actually a different kind. Once the browser believes that, the page can trigger an arbitrary caged write within the sandbox. The researcher supplied two files: one that demonstrates the confusion and triggers an arbitrary caged write inside the browser's protective box (the sandbox), and one that combines the issue with a separate v8sbx bypass to gain RCE.

This article walks through the report from the beginning: what the feature is, what the rulebook says, where the two versions of the rule disagree, how V8 implemented the wrong one, and how that turns into memory corruption and then into full control of the machine.

Background: the pieces involved

Before the details, here are the basic ideas, explained from zero.

WebAssembly (Wasm) is a compact, fast language that web pages can run. JavaScript is flexible and relatively slow for heavy computation; Wasm is designed to be predictable and quick. A page downloads a Wasm module (a compiled bundle of code) and the browser runs it. Games, video editors and cryptography libraries in the browser often use Wasm.

V8 is the engine inside Google Chrome (and other Chromium-based browsers) that runs JavaScript and WebAssembly. When you load a page, V8 is the part that actually executes the code.

A specification (spec) is the written rulebook for a language. It says what every instruction means and what is allowed. Different browsers each write their own engine, but they all follow the same spec so that a page behaves the same everywhere. If the spec contains a contradiction, every engine that follows it can inherit the same bug.

A type is a label on a value saying what kind of thing it is: a number, a piece of text, a record with certain fields. Types let the browser check that an operation makes sense before running it. If you try to treat a number as text, a type checker should stop you.

Type confusion is the name of the vulnerability class here. It means the browser has been tricked into believing a value is one type when it is really another. Once the labels are wrong, the browser's safety checks are checking the wrong thing, and memory can be read or written in ways the programmer never intended. It is like a luggage carousel where someone swaps the tags on two suitcases: the handler who trusts the tags sends the wrong bag to the wrong place.

A struct is a bundle of named fields grouped together, like a form with several boxes. In Wasm, a struct type describes which fields exist and what types they hold.

A heap type is a type that lives in the part of memory the engine manages for objects (the heap), as opposed to a plain number. References point at heap objects.

A reference is a value that points at an object rather than containing it. Think of a claim ticket for a coat at a cloakroom: the ticket is not the coat, but it tells you which coat to fetch.

A descriptor is the new idea in this feature. It is a label attached to a struct type that describes it. The proposal adds a descriptor to a struct type, so that a struct value carries a reference to another heap type that describes it. In everyday terms, imagine a parcel with a sticker on it saying which depot it belongs to; the descriptor is that sticker.

Exact and inexact types. A type can be exact, meaning the value is precisely that type and no more specific subtype, or inexact, meaning it could be that type or a more specific one. Compare a ticket that says "a seat in row 10" (inexact: any seat in that row) with one that says "seat 10C exactly" (exact). Exactness matters because it lets the engine make stronger assumptions, and stronger assumptions are exactly what an attacker wants to abuse.

A subtype is a more specific version of a type. If x' is a subtype of x, then every x' is also an x, but not the other way round. A bicycle is a subtype of a vehicle: every bicycle is a vehicle, but not every vehicle is a bicycle. The notation x' <: x means "x' is a subtype of x".

ref.get_desc is the new Wasm instruction at the centre of the report. It takes a reference to a struct and returns a reference to that struct's custom descriptor. In plain terms: hand it a parcel, it hands you back the sticker that says which depot the parcel belongs to.

Origin Trials are a Chrome mechanism for letting a new feature be switched on for real websites before it becomes permanent. A site can opt in, and the feature runs for real users. The custom descriptors feature was exposed this way by default from Chrome milestone 141 (M141), which at the time of the report was at the Beta stage and about to reach Early Stable. So real users were already running the feature.

A sandbox is a protective box around the browser's rendering process. Even if a web page manages to corrupt memory inside the renderer, the sandbox is meant to stop it from reaching the rest of the machine. A caged write is a write to memory inside that box. Breaking out of the sandbox is called a sandbox escape.

RCE stands for remote code execution: an attacker gets their own code to run on the victim's machine. It is the most serious outcome in this kind of report.

JIT stands for just-in-time compilation. Instead of interpreting code line by line, the engine translates hot code into machine instructions while the program runs. The crash in this report happens in a JIT-compiled Wasm function.

A renderer is the browser process that turns a web page into what you see. It is the part that runs page code, and it is the part that crashed here.

A commit is a single recorded change to a codebase, with an identifier. The report names commit 2f4c043d as the one that introduced ref.get_desc.

d8 is a bare command-line shell built on V8, used by developers to test engine behaviour without a full browser. Blink is Chrome's rendering engine; --enable-blink-features=... is a Chrome command-line switch that turns a named feature on.

The setup

No accounts, roles or remote servers are involved. The work is a careful reading of the specification compared against the V8 source code, followed by a local reproduction on the researcher's own machine.

The relevant versions and conditions are:

  • Chrome Version: M141 and later.
  • Operating System: All.
  • The bug is introduced by the WebAssembly Custom Descriptors feature, on Origin Trials from M141 onwards, specifically in commit 2f4c043d, which implements ref.get_desc.
  • To simulate Origin Trials behaviour, the researcher suggests passing --experimental-wasm-custom-descriptors on d8, or --enable-blink-features=WebAssemblyCustomDescriptors on Chrome.

Those two flags are how you switch the feature on outside a real trial. On d8, the first flag tells the shell to accept the experimental Wasm instructions. On Chrome, the second tells Blink to enable the feature for the current session. The researcher suggests them so that anyone reproducing the issue sees the same behaviour as a real user in the trial.

Two attachments accompany the report: poc.js, which exploits the issue to alias two unrelated struct types and then trigger an arbitrary caged write within the sandbox, and rce.html, which combines the issue with the wrapper-wasmcpt-uaf v8sbx bypass to gain RCE and print /flag/flag to stdout. In other words, the first file is the proof that memory can be corrupted; the second file chains that corruption with a separate, already-known sandbox-escape technique to run code and read a file that stands in for a secret.

Finding it: two rules that are not the same rule

The specification describes two different rules for ref.get_desc, and the researcher separates them explicitly.

  1. Rule #1 is the rule in the code block. It says ref.get_desc must type the result as exact only when the stack type is a subtype of the exact encoded type, thus only allowing the exact encoded type. This rule is sound. "Sound" here means the rule never lets the type checker approve something that is actually false at runtime.
  2. Rule #2 is the rule written in plain English: "If the provided reference is to an exact heap type, then the type of the custom descriptor is known precisely, so the result can be exact as well". In other words, the provided reference's exactness directly propagates to the result type. For this to be sound, the result type must be the provided reference's descriptor type, not the encoded immediate type's descriptor type. Done that way the rule is also sound, but it is different from the first rule.
  3. Mixing the two yields an unsound rule: propagate the provided reference's exactness to the result type (Rule #2), but take the base result type from the encoded immediate type's descriptor (Rule #1). The specification is unsound in that it describes two completely different rules as if they were the same ref.get_desc.

To unpack the jargon: the encoded immediate is the type written directly into the instruction in the Wasm module, the fixed label the programmer typed. The stack type is the type of the value actually sitting on the evaluation stack when the instruction runs, which may be a more specific subtype. Rule #1 looks only at the encoded immediate and demands an exact match. Rule #2 looks at the value on the stack and lets its exactness flow to the result. Each is fine on its own. The danger is a hybrid: take the exactness from the stack but the descriptor from the immediate.

V8 gets confused in the same way and implements the unsound rule, transferring the exactness of the stack type to the result type while using the encoded immediate type's descriptor. That allows the resulting descriptor to be typed as an exact supertype, which leads to type confusion.

The formal rule in the specification is:

Text
ref.get_desc typeidx

C |- ref.get_desc x : (ref null (exact_1 x)) -> (ref (exact_1 y))
-- C.types[x] ~ descriptor y ct

Line by line:

  • ref.get_desc typeidx names the instruction and says it takes a type index, a number that points into the module's table of types.
  • C |- ref.get_desc x : ... says: in the typing context C (the set of known types), the instruction applied to type x has the type shown after the colon.
  • (ref null (exact_1 x)) -> (ref (exact_1 y)) is the input and output type. The input is a reference that may be null, to x, with an exactness marker exact_1. The output is a non-null reference to y, with the same marker exact_1.
  • -- C.types[x] ~ descriptor y ct is the side condition: the type at index x in the context is a descriptor type whose descriptor is y and whose constructor type is ct.

The key point is that the same marker exact_1 appears on both sides, so the output is exact only when the input was checked as exact. That is the sound version.

The researcher walks through the consequence. Take x' <: x with C.types[x'] ~ descriptor y' ct' where C |- ¬(C.types[x'] ~ C.types[x]), that is, x' is a strict subtype of x. Due to subtyping rules on descriptors, y' <: y holds. If ref exact x' is passed to ref.get_desc x:

Text
Stack: ref exact x'
Match: ref exact x' <: ref null x => exact_1 = inexact
=> ref.get_desc x (ref exact x') -> (ref y)

Line by line:

  • Stack: ref exact x' says the value on the stack is an exact reference to the subtype x'.
  • Match: ref exact x' <: ref null x => exact_1 = inexact says: to match the input type, the engine checks whether the stack value fits ref null x. It does, because x' is a subtype of x. But the check was against the inexact x, so the exactness marker must be set to inexact.
  • => ref.get_desc x (ref exact x') -> (ref y) is the result: the descriptor comes out as an inexact reference to y.

Since ¬(ref exact x' <: ref null exact x), exact_1 = inexact is the only suitable rule and the resulting descriptor type must be inexact. In everyday terms: because the ticket only said "row 10", not "seat 10C", the cloakroom cannot promise you seat 10C, so it hands you a general row-10 claim, not an exact one.

The plain English text in the specification reads:

If the provided reference is to an exact heap type, then the type of the custom descriptor is known precisely, so the result can be exact as well. Otherwise, the subtyping rules described above ensure that there will be some custom descriptor value and that it will be a subtype of the custom descriptor type for x, so the result can be a non-null reference to the inexact descriptor type.

That can be interpreted as a weakened, unsound rule:

Text
ref.get_desc? typeidx

C |- ref.get_desc? x : (ref null (exact_1 x')) -> (ref (exact_1 y))
-- C.types[x] ~ descriptor y ct
-- C.types[x'] ~ descriptor y' ct'
-- C |- x' <: x                                                                     // [!] (modified) subtype check

Line by line:

  • ref.get_desc? typeidx is the same instruction, marked with a question mark to show this is the alternative reading.
  • C |- ref.get_desc? x : (ref null (exact_1 x')) -> (ref (exact_1 y)) is the new typing: the input is now described in terms of x', the type on the stack, while the output is still y, the descriptor of the encoded type x.
  • -- C.types[x] ~ descriptor y ct still ties the encoded type x to descriptor y.
  • -- C.types[x'] ~ descriptor y' ct' adds the stack type x' and its own descriptor y'.
  • -- C |- x' <: x is the modified check, marked with [!]: it only asks whether x' is a subtype of x, not whether the stack value is an exact x.

The rule on the input type has been subtly weakened, effectively passing on the exactness of whatever was on the stack instead of typechecking stacktype <: ref null exact x. The result type y is also derived from the encoded type x, not from the provided type on the stack. That produces:

Text
Stack: ref exact x'
Match: (ref exact x' <: ref null exact x') ∧ (x' <: x) => exact_1 = exact
=> ref.get_desc? x (ref exact x') -> (ref exact y)

Line by line:

  • Stack: ref exact x' is again an exact reference to the subtype.
  • Match: (ref exact x' <: ref null exact x') ∧ (x' <: x) => exact_1 = exact says: the stack value does fit an exact x' (trivially, it is one), and x' is a subtype of x, so the marker is set to exact.
  • => ref.get_desc? x (ref exact x') -> (ref exact y) is the dangerous result: the descriptor of the encoded type x, namely y, is handed back typed as exact, even though the value on the stack was the subtype x' whose descriptor is y'.

In the cloakroom comparison: the ticket says "seat 10C" (exact x'), the clerk checks only that 10C is somewhere in row 10 (subtype of x), and then hands you a claim for "row 10 exactly" (exact y). You now hold a claim that is stronger than what you are entitled to.

The researcher notes this appears to be a very common misinterpretation. Development work on Binaryen, a toolchain that compiles code to Wasm, also shows the misunderstanding: "ref.get_desc inherits its input ref's exactness...", which is only true when the reference type's descriptor is used as the return type, which from a cursory glance may be what Binaryen is doing. This leads the researcher to wonder whether the spec was initially designed to represent something like Rule #1 but happened to be written down as Rule #2, after which things got messy. Slides from the CG meeting for Phase 2 advancement of the proposal also mix up the two, stating the formal rule as Rule #1 but using the phrase "propagates exactness of references", which applies to Rule #2. The CG is the Community Group that develops the WebAssembly standard; Phase 2 is a stage in the proposal process. The point is that independent teams read the same text in the same wrong way, which is strong evidence that the text itself is the problem.

Exploitation: from a wrong label to memory corruption

The exploitation follows directly from the typing hole. The researcher describes the chain as follows.

Step 1: obtain an exact descriptor of the wrong type

Because V8 implements the weakened rule, a value of type ref exact y' is typed as ref exact y where y' <: y. This pokes a hole in the type system exactly as described in the proposal docs on exact types. In plain terms, the engine now believes a specific descriptor is the general one, exactly, with no room for doubt. That belief is false, and everything that follows relies on it.

Step 2: invalidly type a descriptor as an exact supertype

The attacker uses that hole to invalidly type a descriptor y' into an exact supertype y.

Step 3: instantiate and cast down

The attacker instantiates struct x and then invalidly casts down to x'. This leads to type confusion between arbitrary Wasm types. Casting down means telling the engine "this general object is really the specific subtype". Normally the engine checks that claim; with the labels already corrupted, the check passes when it should not, and the attacker can treat one struct as a completely different struct.

Step 4: turn the confusion into memory access

The attached poc.js exploits the issue to alias two unrelated struct types, then uses this type confusion to trigger an arbitrary caged write within the sandbox. Aliasing means two different type labels now point at the same memory, so writing through one label changes data that the other label believes it owns. The crash state recorded for the report is: crashes on arbitrary caged write attempt from JIT-compiled Wasm function with poc.js, and RCE with rce.html.

Step 5: escape the sandbox

The attached rce.html exploits the issue together with the wrapper-wasmcpt-uaf v8sbx bypass to gain RCE and print out /flag/flag to stdout. A use-after-free (UAF) is a bug where memory is freed but still used; the named bypass is a separate, known technique for getting past the V8 sandbox. The report does not explain how that bypass works, only that it is combined with this issue.

The crash type is Renderer.

Root cause: where the code goes wrong

The mistake is in the specification and is mirrored in the implementation. The specification gives two rules for ref.get_desc that are not the same rule: the formal code block (Rule #1) and the plain English paragraph (Rule #2). Rule #2 is sound only if the result type is the provided reference's descriptor type. V8 implements the unsound mixture: it propagates the exactness of the stack type to the result, but takes the base result type from the encoded immediate type's descriptor.

The relevant V8 code, as quoted in the report:

CC
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/function-body-decoder-impl.h;drc=[redacted];l=5994
      case kExprRefGetDesc: {
        // ...
        StructIndexImmediate imm(this, this->pc_ + opcode_length, validate);
        if (!this->Validate(this->pc_ + opcode_length, imm)) return 0;
        const TypeDefinition& type = this->module_->type(imm.index);
        if (!VALIDATE(type.has_descriptor())) {
          // ...
          return 0;
        }
        Value ref = Pop(ValueType::RefNull(imm.heap_type()));                       // [!] (modified) subtype check
        Value* desc =
            Push(ValueType::Ref(this->module_->heap_type(type.descriptor))
                     .AsExact(ref.type.exactness()));                               // [!] exactness directly from stack type (x')
        CALL_INTERFACE_IF_OK_AND_REACHABLE(RefGetDesc, ref, desc);
        return opcode_length + imm.length;
      }

Line by line:

  • The comment at the top is a link to the exact file, revision and line in the Chromium source, so anyone can find the code. function-body-decoder-impl.h is the header file where V8 validates Wasm function bodies.
  • case kExprRefGetDesc: { starts the handler for the ref.get_desc instruction. The decoder walks through each instruction in a Wasm function and checks it before running it.
  • StructIndexImmediate imm(this, this->pc_ + opcode_length, validate); reads the instruction's immediate operand, the type index encoded right after the opcode, into a small object called imm. this->pc_ is the program counter, the position in the byte stream; opcode_length skips past the opcode itself.
  • if (!this->Validate(this->pc_ + opcode_length, imm)) return 0; checks that the immediate is well formed. If not, validation stops.
  • const TypeDefinition& type = this->module_->type(imm.index); looks up the type definition that the immediate points at, in the module's type table.
  • if (!VALIDATE(type.has_descriptor())) { checks that this type actually has a descriptor. If it does not, the instruction is invalid.
  • Value ref = Pop(ValueType::RefNull(imm.heap_type())); pops the input value from the stack and checks it against RefNull(imm.heap_type()), a plain reference to the encoded type that may be null. This is the first marked line: the check is against the plain type, not the exact type. That is the weakened subtype check.
  • Value* desc = Push(ValueType::Ref(this->module_->heap_type(type.descriptor)).AsExact(ref.type.exactness())); builds the result type and pushes it. The base is type.descriptor, the descriptor of the encoded immediate type. Then .AsExact(ref.type.exactness()) copies the exactness of the value that was on the stack. This is the second marked line: exactness from the stack, descriptor from the immediate, the unsound combination.
  • CALL_INTERFACE_IF_OK_AND_REACHABLE(RefGetDesc, ref, desc); tells the rest of the engine that a ref.get_desc operation happened, passing the input and the result, but only if validation succeeded and the code is reachable.
  • return opcode_length + imm.length; advances the decoder past the opcode and its immediate so it can process the next instruction.

The two marked lines are the problem. The popped value is checked against RefNull(imm.heap_type()), a plain subtype check against the encoded type, rather than against the exact encoded type. The pushed descriptor is built from type.descriptor, the descriptor of the encoded immediate type, and then .AsExact(ref.type.exactness()) copies the exactness of the stack type onto it. That is exactly the unsound combination: exactness from the stack, descriptor from the immediate.

The bug was present from the first implementation of the feature and shipped through Origin Trials, so there was no earlier, sound version to compare against. The researcher also points to the same misreading in Binaryen and in the CG slides, which suggests the ambiguity was easy to reproduce across independent implementations.

Impact

Within the renderer, the type confusion allows aliasing of two unrelated struct types. The poc.js attachment turns that into an arbitrary caged write within the sandbox from a JIT-compiled Wasm function. Combined with the wrapper-wasmcpt-uaf v8sbx bypass, rce.html gains RCE and prints /flag/flag to stdout.

The report says the feature was exposed in the wild by default through Origin Trials from M141, on all operating systems. The report does not give a CVSS score. The platform records the severity as high and a bounty of 55,000 USD.

Fix

It identifies the specification as unsound: it describes two different rules for ref.get_desc as if they were the same instruction. The report also notes that the same misreading appears in Binaryen and in the CG slides.

Variants to test

These are follow-up checks anyone can run to see whether the same class of mistake exists elsewhere. Each one is a way of asking the same question: does exactness come from one place while the base type comes from another?

  1. Other engines implementing custom descriptors. Take the same x' <: x setup with ref exact x' passed to ref.get_desc x and check whether the result is typed as exact. A positive result is a validator that accepts the exact result type while the descriptor comes from the encoded immediate, which is the unsound combination.
  2. Toolchain producers. Feed the same pattern through a compiler or optimiser that claims ref.get_desc inherits its input reference's exactness, as Binaryen's change description does. A positive result is output that relies on the inherited exactness while using the encoded type's descriptor.
  3. Specification text versus formal rule. Compare the code block and the plain English paragraph for any instruction that propagates exactness. A positive result is a paragraph that can be read as propagating exactness without pinning the result to the provided reference's descriptor type.
  4. Exactness propagation in adjacent instructions. Any instruction that takes an exact reference and returns a type derived from an immediate is worth the same test: does the result's exactness come from the stack, and does its base type come from the immediate? A positive result is a validator that accepts an exact result whose base type is not the one the stack value actually carries.
  5. Origin Trials gating. Run the reproduction with --experimental-wasm-custom-descriptors on d8 and with --enable-blink-features=WebAssemblyCustomDescriptors on Chrome to confirm behaviour matches the trial configuration. A positive result is the same type confusion under both flags.

Glossary

  • API: an agreed set of commands one program offers to another; here, the instructions a Wasm module can call.
  • Binaryen: a toolchain library that compiles and optimises code into WebAssembly.
  • Blink: Chrome's rendering engine, the part that turns HTML and CSS into a page.
  • CG (Community Group): the group that develops the WebAssembly standard and moves proposals through stages.
  • Commit: a single recorded change to a codebase, identified by a hash such as 2f4c043d.
  • Custom descriptors: a proposed Wasm feature that attaches a descriptor to a struct type, so a struct value carries a reference to another heap type describing it.
  • CVSS: a standard scoring system for the severity of a vulnerability; the report gives no score.
  • d8: a command-line shell built on V8, used to test engine behaviour without a full browser.
  • Descriptor: the label attached to a struct type in the custom descriptors feature.
  • Exact type: a type that says the value is precisely that type, not a more specific subtype.
  • Heap: the area of memory where the engine stores objects, as opposed to plain numbers.
  • Heap type: a type describing an object stored on the heap.
  • Inexact type: a type that allows the value to be that type or a more specific subtype.
  • JIT (just-in-time compilation): translating code into machine instructions while the program runs, for speed.
  • M141: Chrome milestone 141, the version range where the feature was on Origin Trials.
  • Origin Trials: a Chrome mechanism that lets real websites opt into an experimental feature before it becomes permanent.
  • RCE (remote code execution): an attacker getting their own code to run on the victim's machine.
  • Reference: a value that points at an object rather than containing it.
  • Renderer: the browser process that runs page code and draws the page.
  • Sandbox: a protective box around the renderer that limits what corrupted code can reach.
  • Sandbox escape: getting out of that box to affect the rest of the machine.
  • Sound: a rule or check that never approves something false at runtime.
  • Specification (spec): the written rulebook that defines what a language's instructions mean.
  • Stack: the working area where an instruction's inputs sit and its outputs are placed.
  • Struct: a bundle of named fields grouped as one value.
  • Subtype: a more specific type; every value of the subtype is also a value of the supertype.
  • Type: a label saying what kind of value something is.
  • Type confusion: a vulnerability where the engine is tricked into treating a value as the wrong type.
  • UAF (use-after-free): using memory after it has been freed.
  • V8: the JavaScript and WebAssembly engine inside Chrome and other Chromium-based browsers.
  • v8sbx: the V8 sandbox, the protective box around the engine.
  • Wasm (WebAssembly): a compact, fast language that web pages can run alongside JavaScript.
  • WebAssembly custom descriptors proposal: the standards proposal that adds descriptors to Wasm struct types.

More by Seunghyun Lee

View all

14 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.