Type Confusion in V8 (CVE-2024-9122)
A type confusion in V8's WebAssembly implementation allowed an imported tag signature to be a subtype of the defined tag signature, breaking type invariance. An attacker could exploit this to perform unsafe downcasts when unpacking exceptions, potentially leading to memory corruption and remote code execution.
Originally disclosed on Chrome VRP
- Fix shipped in 22 days
VULNERABILITY DETAILS
Summary
WASM type confusion due to imported tag signature subtyping. The imported tag signature is allowed to be a subtype of the defined tag signature, which should instead be invariant.
Details
The following code in InstanceBuilder::ProcessImports() processes WASM imports, including tags:
int InstanceBuilder::ProcessImports(
Handle<WasmTrustedInstanceData> trusted_instance_data,
Handle<WasmTrustedInstanceData> shared_trusted_instance_data) {
// ...
for (int index = 0; index < num_imports; ++index) {
// ...
switch (import.kind) {
// ...
case kExternalTag: {
// TODO(14616): Implement shared tags.
if (!IsWasmTagObject(*value)) {
thrower_->LinkError("%s: tag import requires a WebAssembly.Tag",
ImportName(index).c_str());
return -1;
}
Handle<WasmTagObject> imported_tag = Cast<WasmTagObject>(value);
if (!imported_tag->MatchesSignature(module_->canonical_sig_id(
module_->tags[import.index].sig_index))) { // [!] allows subtype signature
thrower_->LinkError(
"%s: imported tag does not match the expected type",
ImportName(index).c_str());
return -1;
}
Tagged<Object> tag = imported_tag->tag();
DCHECK(IsUndefined(
trusted_instance_data->tags_table()->get(import.index)));
trusted_instance_data->tags_table()->set(import.index, tag);
tags_wrappers_[import.index] = imported_tag;
break;
}
default:
UNREACHABLE();
}
}
// ...
return num_imported_functions;
}
The imported tag is allowed to have a signature that is a subtype of the defined tag signature. However, this breaks the type system as the parameter values are used to both create exceptions and unpack exceptions - each values should be considered as a mutable storage field, and thus the types should be invariant. By allowing the imported tag to have a subtype signature, we are allowing contravariance which results in unsafe downcasts when unpacking exceptions made with the imported tag signature.
Exploitation with WASM type confusion primitives is trivial and has been presented multiple times. (Pwn2Own Vancouver 2024, TyphoonPWN 2024, v8CTF submission 8d4d57cb2258, b/360533914, ...)
Bisect
Bug introduced by commit 1ef0a09 in M111 that introduced isorecursive canonicalization to tag signatures.
VERSION
See bisect commit release info in Chromium Dash for more info: https://chromiumdash.appspot.com/commit/1ef0a093e8000931dcccbcf3cd8afe4421609fa7
Affects all Chrome builds with WasmGC available by default, which is M112 up to latest (M112 ~ M118 behind Origin Trials, later shipped in M119~).
Chrome Version: M112 ~ latest (tested on 128.0.6613.113)
Operating System: All
REPRODUCTION CASE
Attached as poc.js which illegally downcasts a struct {i64} into a struct {i64, i64, i64} then fetches index 1 (second i64).
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION
Not a crash, but the vulnerability is trivial.
CREDIT INFORMATION
Reporter credit: Seunghyun Lee (@0x10n) of CMU CyLab
Full exploit coming soon... (again!)
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code allowed the imported tag signature to be a subtype of the defined tag signature, violating the invariance required because tag parameters are used as mutable storage for exceptions.
Impact
An attacker could exploit this type confusion to achieve remote code execution in the Chrome browser, as demonstrated by multiple prior exploits.
What the attacker needed
Chrome with WasmGC enabled; Ability to run WASM code
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
WebAssembly (WASM) is a low-level code format that runs in browsers. Tags are used for exception handling. The bug let a program import a tag with a more specific type than expected, so when exceptions were caught, the program could treat data as a different type, causing memory errors. This could let an attacker run malicious code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.