Skip to content
Memory corruption Disclosed report Advanced

Assertion failure: obj == cacheResult, at js/src/vm/Compartment-inl.h:105

A debug assertion in SpiderMonkey's compartment wrapper code fires when a debugger object's property descriptor is wrapped after the target realm has been flagged to disallow new cross-compartment wrappers. The text describes a crash in a debug build, not a demonstrated security impact.

Nan Wang Follow

Originally disclosed on Mozilla

  • Fixed in 4 days
  • Paid in 5 days
  • Disclosed after 4 days

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 --fuzzing-safe poc.js

Test SpiderMonkey commit hash: eb5d60087707d1acaf663a8ea2bbf14602e88d2f

Crash Stack Trace

--------------------------------------------------------------------------------
[2926318] Assertion failure: obj == cacheResult, at /home/sakura/gecko-dev/js/src/vm/Compartment-inl.h:105
#01: JS::Compartment::wrap(JSContext*, JS::MutableHandle<JS::Value>)[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dc514f]
#02: JS::Compartment::wrap(JSContext*, JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor> >)[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2079926]
#03: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2875981]
#04: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x222a47b]
#05: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x22b5af1]
#06: ??? (???:???)
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==2926318==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x558d94fc5167 bp 0x7ffc824af3b0 sp 0x7ffc824af330 T2926318)
==2926318==The signal is caused by a WRITE memory access.
==2926318==Hint: address points to the zero page.
LLVMSymbolizer: error reading file: No such file or directory
#0 0x558d94fc5167 in MOZ_CrashSequence(void*, long) /home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/include/mozilla/Assertions.h:237:3
#1 0x558d94fc5167 in JS::Compartment::wrap(JSContext*, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/vm/Compartment-inl.h:105:3
#2 0x558d95279925 in JS::Compartment::wrap(JSContext*, JS::MutableHandle<JS::PropertyDescriptor>) /home/sakura/gecko-dev/js/src/vm/Compartment.cpp:430:10
#3 0x558d95279925 in JS::Compartment::wrap(JSContext*, JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor> >) /home/sakura/gecko-dev/js/src/vm/Compartment.cpp:444:8
#4 0x558d95a75980 in js::Proxy::getOwnPropertyDescriptor(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor> >) /home/sakura/gecko-dev/js/src/proxy/Proxy.cpp:221:19
#5 0x558d9542a47a in js::GetOwnPropertyDescriptor(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor> >) /home/sakura/gecko-dev/js/src/vm/JSObject.cpp:2013:15
#6 0x558d954b5af0 in js::GetOwnPropertyDescriptorToArray(JSContext*, unsigned int, JS::Value*) /home/sakura/gecko-dev/js/src/builtin/Object.cpp:1462:8
#7 0x3053c86f63a7  ([anon:js-executable-memory]+0x213a7)

==2926318==Register values:
rax = 0x0000000000000000  rbx = 0x00000000824af301  rcx = 0x0000000000000069  rdx = 0x00007f1d2401b723
rdi = 0x00007f1d2401ca60  rsi = 0x0000000000000000  rbp = 0x00007ffc824af3b0  rsp = 0x00007ffc824af330
r8 = 0x0000000000000000   r9 = 0x0000000000000003  r10 = 0x0000558d975f9c30  r11 = 0x0000000000000293
r12 = 0x00007ffc824af358  r13 = 0x00007f1d23b3c218  r14 = 0x00007f1d213a1b30  r15 = 0x00007ffc824af330
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV /home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/include/mozilla/Assertions.h:237:3 in MOZ_CrashSequence(void*, long)
==2926318==ABORTING



================================================================================

PoC

JavaScript
const g = newGlobal({sameZoneAs: this});
const dbg = g.Debugger();
Object.defineProperty(dbg, 'onDebuggerStatement', {value: dbg});
g.nukeAllCCWs();
let cur = dbg;
while (cur && cur !== Object.prototype) {
  for (const name of Object.getOwnPropertyNames(cur)) {
    try {
      Object.getOwnPropertyDescriptor(cur, name);
    } catch (e) {}
  }
  cur = Object.getPrototypeOf(cur);
}
// Flags: --fuzzing-safe

Root Cause

nukeAllCCWs() calls NukeCrossCompartmentWrappers(..., NukeAllReferences) (shell/js.cpp:7578-7584). This routine marks the target realm's nukedIncomingWrappers bit so future CCWs aren't allowed, but it deliberately skips wrappers whose targets are DebuggerInstanceObjects (proxy/CrossCompartmentWrapper.cpp:447-456). As a result, debugger CCWs stay in the wrapper map even though the realm is flagged as "no new wrappers".

Later, the PoC calls Object.getOwnPropertyDescriptor on a debugger object through a proxy, which triggers Proxy::getOwnPropertyDescriptor (proxy/Proxy.cpp:205-224). The descriptor is wrapped to the proxy's compartment via Compartment::wrap(JS::MutableHandle<mozilla::Maybe<PropertyDescriptor>>) (vm/Compartment.cpp:346-366). Inside Compartment::wrap(JS::MutableHandleValue) (vm/Compartment-inl.h:87-105), the wrapper map still contains the old debugger CCW, so lookupWrapper returns it and debug builds store it in cacheResult.

Immediately afterward, Compartment::getNonWrapperObjectForCurrentCompartment checks AllowNewWrapper (vm/Compartment.cpp:214-244). Because the debugger realm has nukedIncomingWrappers set, AllowNewWrapper returns false (proxy/CrossCompartmentWrapper.cpp:475-487), replacing the value with a freshly created dead proxy (Compartment.cpp:239-244). This discards the cached debugger wrapper even though it still lives in the wrapper map.

When control returns to Compartment::wrap(JS::MutableHandleValue), the final assertion MOZ_ASSERT_IF(cacheResult, obj == cacheResult) (vm/Compartment-inl.h:105) fires: cacheResult points at the old debugger CCW, but obj was overwritten with a dead proxy due to the "no new wrapper" policy.

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 nuke routine skips debugger wrappers when marking a realm as no-new-wrappers, so a cached debugger wrapper survives while the wrapper policy later replaces the value with a dead proxy, breaking the cache assertion.

Impact

The text only shows a debug-build assertion failure and crash in the JavaScript shell; no memory corruption or exploitable impact on users is demonstrated.

What the attacker needed

Debug build of the JS shell; fuzzing-safe flag; ability to run the provided script

How it was found

  1. Build the JavaScript shell from the Firefox source with the given configure flags.
  2. Run the shell with the fuzzing-safe flag on the provided script.
  3. The script creates a same-zone global, makes a Debugger, sets a property on it, and nukes all cross-compartment wrappers.
  4. It then walks the prototype chain calling getOwnPropertyDescriptor on each object.
  5. The debug build aborts on the wrapper cache assertion.

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.

Firefox's JavaScript engine keeps objects from different pages or contexts separate, and when one side needs to see an object from the other it creates a small stand-in called a wrapper. This report shows a debug-only check that fails when the engine has been told to stop making new wrappers but still finds an old one cached, causing the test build to abort. It is a crash in a testing build, not a proven way to attack users.

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.