Type Confusion in V8 (CVE-2024-10231)
The V8 engine's DefaultReferenceValue function returns undefined instead of null for externref and nullexternref types, violating the WebAssembly GC specification. This type confusion allows an attacker to create a fake string with a huge length, leading to out-of-bounds reads and a renderer crash.
Originally disclosed on Chrome VRP
- Fix shipped in 21 days
VULNERABILITY DETAILS
Summary
Note: Bug split out from b/372285204 as this is technically a different bug.
DefaultReferenceValue() returns undefined value as a default value for externref (kExtern) and nullexternref (kNoExtern). This is a violation of wasm-gc spec as only null values are allowed for reference types. This results in type confusion due to inconsistencies from nullity checks being bypassed.
Details
DefaultReferenceValue() returns undefined value as a default value for externref (i.e. kExtern) and nullexternref (i.e. kNoExtern):
i::Handle<i::HeapObject> DefaultReferenceValue(i::Isolate* isolate,
i::wasm::ValueType type) {
DCHECK(type.is_object_reference());
// Use undefined for JS type (externref) but null for wasm types as wasm does
// not know undefined.
if (type.heap_representation() == i::wasm::HeapType::kExtern ||
type.heap_representation() == i::wasm::HeapType::kNoExtern) {
return isolate->factory()->undefined_value(); // [!] undefined, not null
}
return isolate->factory()->wasm_null();
}
This results in type confusion as the only allowed value for a nullexternref is a JS null.
The bug has multiple potential problems:
- Optimizing compilers (turbofan, turboshaft) may falsely optimize out code as unreachable, resulting in typer problems
kNoExternbutundefinedvalue may be confused into other types likekExternString
Attached PoC is a repro of #2.
Bisect
Bug introduced by commit 2e357c4 in M112 that introduced wasm null.
Suggested Fix
Change default reference value of extern & exn types to JS null.
VERSION
See bisect commit release info in Chromium Dash for more info: https://chromiumdash.appspot.com/commit/2e357c4814954c6d83c336655209e14aa53911d4
Chrome Version: 112.0.5579.0 ~ latest
Operating System: All
REPRODUCTION CASE
Attached PoC which confuses undefined value into kExternString type, resulting in a fake string of length 0x7ff80000. charCodeAt is continuously called which results in reading characters from undefined (near 0x68) up to 0x10000 where it finally hits a guard page and segfaults as below:
undefined
0 0
1 0
2 0
3 0
4 0
5 0
6 99
7 9
8 0
...
9c7c 0
9c7d 0
9c7e 35
9c7f 20
9c80 0
9c81 0
Received signal 11 SEGV_ACCERR 3b2400010000
Segmentation fault (core dumped)
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION
Type of crash: Renderer
Crash State: Crashes on invalid memory access on WASM string-builtins charCodeAt
CREDIT INFORMATION
Reporter credit: Seunghyun Lee (@0x10n) of CMU CyLab
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
Impact
An attacker could cause a renderer crash due to out-of-bounds memory access, potentially leading to further exploitation.
What the attacker needed
Ability to run WASM in V8
The fix
The default reference value for extern and exn types should be changed to JS null.
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 way to run code in the browser. The V8 engine handles WASM and has rules about default values for certain types. Here, it used the wrong default value (undefined instead of null), which confused the engine into treating a value as a string with a very large length, causing it to read memory it shouldn't and crash.
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.