Skip to content
Memory corruption Disclosed report Advanced

Wasm GC array OOL forwarding word corruption leading to memory corruption

A typo in the Wasm GC code used a bitwise AND instead of OR when storing a forwarding pointer, corrupting the OOL header word. This caused misclassification of OOL data and led to memory corruption, including an ASLR bypass and arbitrary read/write.

Alessio Ghidini Follow

Originally disclosed on Mozilla

  • Fixed in 16 hours
  • Paid in 9 days
  • Disclosed after 16 hours
Text
Created attachment 9541951
repros.zip

#### Summary
  Commit `fcc2f20e35ec` (2026‑01‑19, Bug 1992888) introduced the bad line:

  - js/src/wasm/WasmGcObject.cpp
'''js
    // Store the forwarding word, with bit 0 set.
      oolHeaderOld->word = uintptr_t(oolHeaderNew) & 1;
'''

Obviously this should be `oolHeaderOld->word = uintptr_t(oolHeaderNew) | 1;`

##### Root Cause
The OOL header word is used to distinguish inline vs OOL data and to store a forwarding pointer when the OOL buffer moves. 
The code stores only bit 0 instead of the pointer with bit 0 set.
That corrupts the header, causing isDataInline to misclassify OOL data and updateFrameForMovingGC to update stack slots to an invalid base pointer.

#### Steps to reproduce

Build a debug shell with ASAN on a vulnerable commit, I used `236a7df6b45551ca52258bda8fe2a315e2fca961` and run 
`js --fuzzing-safe --wasm-compiler=optimizing repro_wasm.js`
- `--wasm-compiler=optimizing` is only used for convenience
- All samples require `js/src/jit-test/lib/wasm.js` in the cwd

'''bash
$ obj-fuzzbuild-release/dist/bin/js --fuzzing-safe --wasm-compiler=optimizing repro_wasm.js
[COV] no shared memory bitmap available, skipping
[COV] edge counters initialized. Shared memory: (null) with 500217 edges
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==152647==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x00802d2d2d28 (pc 0x56aa74b4a9d2 bp 0x7ffee74189a0 sp 0x7ffee7418960 T152647)
==152647==The signal is caused by a READ memory access.
/home/erge/firefox/obj-fuzzbuild-release/dist/bin/llvm-symbolizer: error: '[anon:js-executable-memory]': No such file or directory
    #0 0x56aa74b4a9d2 in js::gc::HeaderWord::getAtomic() const /home/erge/firefox/js/src/gc/Cell.h:101:12
    #1 0x56aa74b4a9d2 in js::gc::HeaderWord::flags() const /home/erge/firefox/js/src/gc/Cell.h:117:36
    #2 0x56aa74b4a9d2 in js::gc::HeaderWord::isForwarded() const /home/erge/firefox/js/src/gc/Cell.h:118:37
    #3 0x56aa74b4a9d2 in js::gc::Cell::isForwarded() const /home/erge/firefox/js/src/gc/Cell.h:154:45
    #4 0x56aa74b4a9d2 in bool js::gc::IsForwarded<js::WasmArrayObject>(js::WasmArrayObject const*) /home/erge/firefox/js/src/gc/Marking-inl.h:97:13
    #5 0x56aa74b4a9d2 in js::WasmArrayObject* js::gc::MaybeForwarded<js::WasmArrayObject*>(js::WasmArrayObject* const&) /home/erge/firefox/js/src/gc/Marking-inl.h:129:3
    #6 0x56aa74b4a9d2 in js::wasm::Instance::updateFrameForMovingGC(js::wasm::WasmFrameIter const&, unsigned char*, js::Nursery&) /home/erge/firefox/js/src/wasm/WasmInstance.cpp:3296:33
    #7 0x56aa7419fa2b in js::jit::UpdateJitActivationsForMinorGC(JSRuntime*) /home/erge/firefox/js/src/jit/JitFrames.cpp:1524:27
    #8 0x56aa73786844 in js::Nursery::doCollection(js::gc::AutoGCSession&, JS::GCOptions, JS::GCReason) /home/erge/firefox/js/src/gc/Nursery.cpp:1592:3
    #9 0x56aa73730155 in js::Nursery::collect(JS::GCOptions, JS::GCReason) /home/erge/firefox/js/src/gc/Nursery.cpp:1417:31
    #10 0x56aa73726a8f in js::gc::GCRuntime::collectNursery(JS::GCOptions, JS::GCReason, js::gcstats::PhaseKind) /home/erge/firefox/js/src/gc/GC.cpp:5076:13
    #11 0x56aa736ff8bc in js::gc::GCRuntime::minorGC(JS::GCReason, js::gcstats::PhaseKind) /home/erge/firefox/js/src/gc/GC.cpp:5047:3
    #12 0x56aa732a4aca in JSContext::minorGC(JS::GCReason) /home/erge/firefox/js/src/vm/JSContext-inl.h:288:17
    #13 0x56aa732a4aca in MinorGC(JSContext*, unsigned int, JS::Value*) /home/erge/firefox/js/src/builtin/TestingFunctions.cpp:808:7
    #14 0x56aa74376f0e in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /home/erge/firefox/js/src/vm/Interpreter.cpp:490:13
    #15 0x56aa743766f2 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:586:12
    #16 0x56aa7438b961 in js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:658:10
    #17 0x56aa7438b961 in js::Interpret(JSContext*, js::RunState&) /home/erge/firefox/js/src/vm/Interpreter.cpp:3272:16
    #18 0x56aa74375822 in js::RunScript(JSContext*, js::RunState&) /home/erge/firefox/js/src/vm/Interpreter.cpp:460:13
    #19 0x56aa7437661b in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:618:13
    #20 0x56aa74377dfe in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:685:8
    #21 0x56aa74b278b2 in js::wasm::Instance::callImport(JSContext*, unsigned int, unsigned int, unsigned long*) /home/erge/firefox/js/src/wasm/WasmInstance.cpp:354:8
    #22 0x56aa74b290b8 in js::wasm::Instance::callImport_general(js::wasm::Instance*, int, int, unsigned long*) /home/erge/firefox/js/src/wasm/WasmInstance.cpp:414:20
    #23 0x3adea826621c  ([anon:js-executable-memory]+0x21c)

==152647==Register values:
rax = 0x000000802d2d2d28  rbx = 0x000070feb9330c10  rcx = 0x000070feb9000000  rdx = 0x0000000000000020  
rdi = 0x000056aa755fb9a0  rsi = 0x000070feb8f6d060  rbp = 0x00007ffee74189a0  rsp = 0x00007ffee7418960  
 r8 = 0x00007ffee7418918   r9 = 0x0000000000000000  r10 = 0x0000000000000000  r11 = 0x0000000000000000  
r12 = 0x00007ffee7419930  r13 = 0x0000000000000001  r14 = 0x000070feb8f6d060  r15 = 0x0000244c87f050c0  
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV /home/erge/firefox/js/src/gc/Cell.h:101:12 in js::gc::HeaderWord::getAtomic() const
==152647==ABORTING
'''
This crash is due to the JS shell GC poisoning present in debug builds. 

Attached are also two more samples that demonstrate the exploitability of this bug:
- `repro_aslr_bypass.js` which as the name implies leaks an address and defeats ASLR
- `repro_wasm_arb_RW.js` produces an ASAN trace by dereferencing an arbitrary address (0x414141414141)

We use `--setpref extra_gc_poisoning=false` to disable the GC poisoning (not present in release builds).
These 2 samples may require precise GC tweaking to reproduce correctly depending on the environment.

'''bash
$ obj-fuzzbuild-release/dist/bin/js --fuzzing-safe --setpref extra_gc_poisoning=false --wasm-compiler=optimizing repro_aslr_bypass.js
[COV] no shared memory bitmap available, skipping
[COV] edge counters initialized. Shared memory: (null) with 500217 edges
05ea9225bf4f0
executionHash is 0x1 with 0 inputs
'''

'''bash
$ obj-fuzzbuild-release/dist/bin/js --fuzzing-safe --setpref extra_gc_poisoning=false --wasm-compiler=optimizing repro_wasm_arb_RW.js
[COV] no shared memory bitmap available, skipping
[COV] edge counters initialized. Shared memory: (null) with 500217 edges
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==154259==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x414141414140 (pc 0x5a86847c9c9f bp 0x7ffd2772a940 sp 0x7ffd2772a930 T154259)
==154259==The signal is caused by a READ memory access.
/home/erge/firefox/obj-fuzzbuild-release/dist/bin/llvm-symbolizer: error: '[anon:js-executable-memory]': No such file or directory
    #0 0x5a86847c9c9f in js::WasmArrayObject::oolDataHeaderToDataPointer(js::WasmArrayObject::OOLDataHeader*) /home/erge/firefox/js/src/wasm/WasmGcObject.h:469:5
    #1 0x5a868480fb13 in js::wasm::Instance::updateFrameForMovingGC(js::wasm::WasmFrameIter const&, unsigned char*, js::Nursery&) /home/erge/firefox/js/src/wasm/WasmInstance.cpp:3319:19
    #2 0x5a8683e64a2b in js::jit::UpdateJitActivationsForMinorGC(JSRuntime*) /home/erge/firefox/js/src/jit/JitFrames.cpp:1524:27
    #3 0x5a868344b844 in js::Nursery::doCollection(js::gc::AutoGCSession&, JS::GCOptions, JS::GCReason) /home/erge/firefox/js/src/gc/Nursery.cpp:1592:3
    #4 0x5a86833f5155 in js::Nursery::collect(JS::GCOptions, JS::GCReason) /home/erge/firefox/js/src/gc/Nursery.cpp:1417:31
    #5 0x5a86833eba8f in js::gc::GCRuntime::collectNursery(JS::GCOptions, JS::GCReason, js::gcstats::PhaseKind) /home/erge/firefox/js/src/gc/GC.cpp:5076:13
    #6 0x5a86833c48bc in js::gc::GCRuntime::minorGC(JS::GCReason, js::gcstats::PhaseKind) /home/erge/firefox/js/src/gc/GC.cpp:5047:3
    #7 0x5a8682f69aca in JSContext::minorGC(JS::GCReason) /home/erge/firefox/js/src/vm/JSContext-inl.h:288:17
    #8 0x5a8682f69aca in MinorGC(JSContext*, unsigned int, JS::Value*) /home/erge/firefox/js/src/builtin/TestingFunctions.cpp:808:7
    #9 0x5a868403bf0e in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /home/erge/firefox/js/src/vm/Interpreter.cpp:490:13
    #10 0x5a868403b6f2 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:586:12
    #11 0x5a8684050961 in js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:658:10
    #12 0x5a8684050961 in js::Interpret(JSContext*, js::RunState&) /home/erge/firefox/js/src/vm/Interpreter.cpp:3272:16
    #13 0x5a868403a822 in js::RunScript(JSContext*, js::RunState&) /home/erge/firefox/js/src/vm/Interpreter.cpp:460:13
    #14 0x5a868403b61b in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:618:13
    #15 0x5a868403cdfe in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) /home/erge/firefox/js/src/vm/Interpreter.cpp:685:8
    #16 0x5a86847ec8b2 in js::wasm::Instance::callImport(JSContext*, unsigned int, unsigned int, unsigned long*) /home/erge/firefox/js/src/wasm/WasmInstance.cpp:354:8
    #17 0x5a86847ee0b8 in js::wasm::Instance::callImport_general(js::wasm::Instance*, int, int, unsigned long*) /home/erge/firefox/js/src/wasm/WasmInstance.cpp:414:20
    #18 0x14cbcf37021c  ([anon:js-executable-memory]+0x21c)

==154259==Register values:
rax = 0x0000000000000000  rbx = 0x0000414141414140  rcx = 0x00007e8106200000  rdx = 0x0000000000000020  
rdi = 0x00005a86852abb50  rsi = 0x00007e810616d060  rbp = 0x00007ffd2772a940  rsp = 0x00007ffd2772a930  
 r8 = 0x00007ffd2772a908   r9 = 0x0000000000000000  r10 = 0x0000000000000000  r11 = 0x0000000000000000  
r12 = 0x00001892824051c8  r13 = 0x0000000000000001  r14 = 0x0000000000000000  r15 = 0x0000414141414140  
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV /home/erge/firefox/js/src/wasm/WasmGcObject.h:469:5 in js::WasmArrayObject::oolDataHeaderToDataPointer(js::WasmArrayObject::OOLDataHeader*)
==154259==ABORTING
'''
#### Suggested Patch
Simply 
'''diff
diff --git a/js/src/wasm/WasmGcObject.cpp b/js/src/wasm/WasmGcObject.cpp
index f72bf9447e4a..40c362584504 100644
--- a/js/src/wasm/WasmGcObject.cpp
+++ b/js/src/wasm/WasmGcObject.cpp
@@ -373,7 +373,7 @@ size_t WasmArrayObject::obj_moved(JSObject* objNew, JSObject* objOld) {
     MOZ_RELEASE_ASSERT(oolBlockSize > sizeof(OOLDataHeader));
     if (nursery.isInside(oolHeaderOld)) {
       // Store the forwarding word, with bit 0 set.
-      oolHeaderOld->word = uintptr_t(oolHeaderNew) & 1;
+      oolHeaderOld->word = uintptr_t(oolHeaderNew) | 1;
       oolHeaderNew->word = WasmArrayObject::OOLDataHeader_Magic;
     }
   }
'''
:)

The original report as published on Mozilla's Bugzilla, by Alessio Ghidini. 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 a typo: the code used bitwise AND instead of OR when setting the low bit of a forwarding pointer, corrupting the OOL header word.

Impact

The bug could lead to memory corruption, including an ASLR bypass and arbitrary read/write, as demonstrated by the provided samples.

What the attacker needed

Vulnerable Firefox build; ability to run JavaScript/Wasm

How it was found

  1. Build a debug shell with ASAN on a vulnerable commit.
  2. Run the JS shell with the reproducer script and flags.
  3. Observe the crash or memory corruption.

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 small mistake in the browser's engine code (using '&' instead of '|') meant a pointer was stored incorrectly. This confused the garbage collector, which then used a bad address, crashing the program and potentially allowing an attacker to read or write memory.

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 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.