[wasm-gc] WASM type confusion due to broken js::wasm::ArrayType::canBeSubtypeOf() check
A broken subtype check in WebAssembly GC allowed type confusion between array elements with different mutability, enabling addrof/fakeobj and arbitrary read/write primitives. The proof-of-concept causes a renderer crash when logging a fake object.
Originally disclosed on Mozilla
- Fixed in 2 days
- Paid in 14 days
- Disclosed after 2 days
Created attachment 9418025 poc.html
Vulnerability Details
Summary
WASM type confusion due to broken js::wasm::ArrayType::canBeSubtypeOf() check.
Details
js::wasm::ArrayType::canBeSubtypeOf() always returns true if array mutability is different, resulting in arbitrary type confusion between array elements.
// https://searchfox.org/mozilla-central/source/js/src/wasm/WasmTypeDef.h#457
static bool canBeSubTypeOf(const ArrayType& subType,
const ArrayType& superType) {
// Mutable fields are invariant w.r.t. field types
if (subType.isMutable_ && superType.isMutable_) {
return subType.elementType_ == superType.elementType_;
}
// Immutable fields are covariant w.r.t. field types
if (!subType.isMutable_ && !superType.isMutable_) {
return StorageType::isSubTypeOf(subType.elementType_,
superType.elementType_);
}
return true;
}
This allows an attacker to acquire traditional JS exploit primitives such as addrof/fakeobj, as well as arbitrary read/write primitives.
Bug discovered through code audit.
Version / Bisect
Existed since the implementation of Bug 1774827 (108 Branch), up to latest.
Repro
Attached poc.html, visit the html file in Firefox for an immediate renderer crash.
This PoC uses the bug to confuse:
- anyref -> I64 (addrof)
- I64 -> anyref (fakeobj)
- I64 -> struct ( I64 ) (arbitrary RW)
...and obtain corresponding memory corruption primitives. The PoC attempts to console.log() on a fakeobj(0x424242424242n), resulting in a renderer crash.
Note that arbitrary read/write operations do work, but with invalid addresses it does not immediately crash the renderer. This is likely due to WASM trap handling incorrectly capturing the segfault as a null pointer dereference - the read/write attempt can easily be verified by a debugger.
Some info regarding submission
I've initially submitted this to [address removed] over PGP-encrypted email, following this Mozilla docs, but another docs suggest that I shouldn't have...? Quite confusing (report via email? bug bounty form? or just new bug w/ security checked in Bugzilla?), but anyways note that the vulnerability details & PoC has already been sent over PGP-encrypted email (and delete them if necessary). Also, please tell me where & in what format I should submit my future bugs so that everything works out clean :)
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 canBeSubTypeOf function returns true when array mutability differs, instead of enforcing invariance or covariance correctly.
Impact
An attacker could obtain addrof/fakeobj and arbitrary read/write primitives, leading to memory corruption and a renderer crash.
What the attacker needed
Firefox with WASM GC enabled; victim visits a malicious HTML page
How it was found
- Open the attached poc.html file in Firefox.
- The PoC uses the bug to confuse anyref to I64 (addrof), I64 to anyref (fakeobj), and I64 to struct (I64) for arbitrary read/write.
- The PoC attempts to console.log() on a fake object, causing a renderer crash.
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 fast, low-level code format for browsers. The garbage collector (GC) feature lets WASM manage objects. A type check that should prevent mixing incompatible array types was wrong, so the browser could be tricked into treating one kind of data as another, which can lead to memory corruption.
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.