Type confusion crash [@ JSObject::shape] via PrivateGCThing leaked through shell ModuleLoader closure to Debugger
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
People
(Reporter: bugmon, Unassigned)
References
(Blocks 1 open bug)
Details
(Keywords: ai-involved, assertion, testcase)
Attachments
(3 files)
|
352 bytes,
text/plain
|
Details | |
|
583 bytes,
patch
|
Details | Diff | Splinter Review | |
|
6.62 KB,
text/plain
|
Details |
The JS shell's ModuleLoader::dynamicImport stores a PrivateGCThingValue wrapping a JSScript* as a normal data property ("referrer") on a plain object, then resolves an internal Promise with that object. Because the Promise is created in the debuggee global, a Debugger with an onPromiseSettled hook receives a Debugger.Object for the closure and can call getOwnPropertyDescriptor("referrer") on it.
DebuggerObject::getOwnPropertyDescriptor reads the property value and passes it to Debugger::wrapDebuggeeValue. That function handles isObject() and isMagic(), then defers everything else to Compartment::wrap. Compartment::wrap handles symbol/string/bigint, asserts vp.isObject() for the remainder, and calls vp.toObject(). A PrivateGCThing value is a GC thing but is none of object/symbol/string/bigint/magic, so in a debug build the MOZ_ASSERT(vp.isObject()) at Compartment-inl.h:64 fails, and in an opt/ASAN build vp.toObject() extracts the payload through the wrong tag, yielding a wild pointer that is immediately dereferenced as a JSObject in ObjectWrapperMap::lookup → JSObject::compartment → JSObject::shape, producing a SEGV at an unmapped address.
The value-producing side lives in shell-only code (js/src/shell/ModuleLoader.cpp) and observation requires the privileged Debugger API, so web content cannot reach this path in Firefox. It nonetheless demonstrates that neither Debugger::wrapDebuggeeValue nor Compartment::wrap(MutableHandleValue) defend against PrivateGCThing values; any embedding that stores such a value on a Debugger-reachable object property hits the same type confusion.
Build Info
- Branch: main
- Revision: 3b0ec2e6ef5bd362c37420922deaddf9d5d5e175
- Timestamp: 2026-06-20T22:36:09+00:00
Affected Code
File: js/src/shell/ModuleLoader.cpp, line 340-381
RootedValue moduleRequestValue(cx, ObjectValue(*moduleRequest));
RootedObject closure(cx, JS_NewObjectWithGivenProto(cx, nullptr, nullptr));
RootedValue referrerValue(cx);
if (referrer) {
referrerValue = PrivateGCThingValue(referrer); // JSScript* boxed as PrivateGCThing
} else {
...
referrerValue = PrivateGCThingValue(script);
}
MOZ_ASSERT(!referrerValue.isUndefined());
if (!closure ||
!JS_DefineProperty(cx, closure, "referrer", referrerValue, // stored as a normal data property
JSPROP_ENUMERATE) ||
... ) {
return false;
}
...
RootedValue closureValue(cx, ObjectValue(*closure));
delayPromise = PromiseObject::unforgeableResolve(cx, closureValue); // Debugger.onPromiseSettled sees this
File: js/src/debugger/Object.cpp, line 2212-2238
bool DebuggerObject::getOwnPropertyDescriptor(...) {
...
if (!GetOwnPropertyDescriptor(cx, referent, id, desc_)) { // reads PrivateGCThingValue
return false;
}
...
if (desc.hasValue()) {
if (!dbg->wrapDebuggeeValue(cx, desc.value())) { // passes it to wrapDebuggeeValue
return false;
}
}
File: js/src/debugger/Debugger.cpp, line 1477-1524
bool Debugger::wrapDebuggeeValue(JSContext* cx, MutableHandleValue vp) {
cx->check(object.get());
if (vp.isObject()) { // false for PrivateGCThing
...
} else if (vp.isMagic()) { // false for PrivateGCThing
...
} else if (!cx->compartment()->wrap(cx, vp)) { // falls through here
vp.setUndefined();
return false;
}
return true;
}
File: js/src/vm/Compartment-inl.h, line 29-90
inline bool JS::Compartment::wrap(JSContext* cx, JS::MutableHandleValue vp) {
if (!vp.isGCThing()) { // PrivateGCThing IS a GC thing
return true;
}
if (vp.isSymbol()) { ... }
if (vp.isString()) { ... }
if (vp.isBigInt()) { ... }
MOZ_ASSERT(vp.isObject()); // <-- debug assert fails here
...
if (js::ObjectWrapperMap::Ptr p = lookupWrapper(&vp.toObject())) { // <-- opt: tag-corrupted JSObject*
...
The shell module loader stores a PrivateGCThingValue on a plain object property that is later observable via the Debugger; wrapDebuggeeValue/Compartment::wrap have no case for PrivateGCThing and treat it as an Object.
Exploit Chain
- Create a debuggee global in a separate compartment and attach a Debugger with an onPromiseSettled hook.
- In the debuggee, evaluate a dynamic import() expression. js::shell::ModuleLoader::dynamicImport builds a plain
closureobject and definesclosure.referrer = PrivateGCThingValue(script)(a boxed JSScript*). - ModuleLoader resolves an internal Promise with
closureas its fulfillment value; DebugAPI::onPromiseSettled fires the hook and hands the debugger a Debugger.Object wrapping that Promise. - The hook reads promiseValue (a Debugger.Object for
closure) and calls getOwnPropertyDescriptor("referrer"), which fetches the PrivateGCThingValue and passes it to Debugger::wrapDebuggeeValue. - wrapDebuggeeValue falls through the isObject()/isMagic() checks to Compartment::wrap, which assumes the remaining GC-thing case is an Object. In debug builds MOZ_ASSERT(vp.isObject()) fails; in opt builds vp.toObject() yields a tag-corrupted pointer (JSScript* bits XORed with the Object tag).
- ObjectWrapperMap::lookup → JSObject::compartment → JSObject::shape dereferences the bogus pointer, causing a wild-address SEGV (type confusion between JSScript* / PrivateGCThing and JSObject*).
Steps to Reproduce
- Build the SpiderMonkey shell with AddressSanitizer (e.g. mozconfig.linux.asan.fuzzing).
- Save the testcase below as test.js.
- Run: obj-asan/dist/bin/js --fuzzing-safe test.js
- Observe an ASAN SEGV at a wild address in js::gc::HeaderWord::get() / JSObject::shape via Compartment::wrap → Debugger::wrapDebuggeeValue. A debug build instead hits 'Assertion failure: vp.isObject(), at js/src/vm/Compartment-inl.h:64'.
- Testcase:
var g = newGlobal({newCompartment: true});
var dbg = new Debugger(g);
dbg.onPromiseSettled = function(p) {
if (p.promiseState !== "fulfilled") return;
var v = p.promiseValue;
if (!(v instanceof Debugger.Object)) return;
try { v.getOwnPropertyDescriptor("referrer"); } catch (e) {}
};
g.eval("import('./x.js').catch(e => {})");
drainJobQueue();
Security Impact
- Severity: Low
- Attacker capability: Type confusion / wild pointer dereference: a PrivateGCThing-tagged JS::Value (boxing a JSScript*) is reinterpreted as a JSObject* and dereferenced. As reproduced this is a read at an address derived from XORing mismatched NaN-box tags, which is not attacker-controlled and crashes safely; however the underlying invariant violation (Compartment::wrap assumes any non-string/symbol/bigint GC thing is an Object) is a genuine type-confusion primitive if a PrivateGCThing value reaches it through other paths.
- Preconditions: Requires the JS shell's module loader (js/src/shell/ModuleLoader.cpp — not shipped in the Firefox browser) and the privileged Debugger API (newGlobal({newCompartment:true}) + new Debugger), neither of which is reachable from web content. Not exploitable from a content process in Firefox.
ASAN Report
AddressSanitizer:DEADLYSIGNAL
=================================================================
==21757==ERROR: AddressSanitizer: SEGV on unknown address 0x439bb49bc416 (pc 0x57070f5844ec bp 0x7ffd230cee30 sp 0x7ffd230cedf0 T0)
==21757==The signal is caused by a READ memory access.
#0 0x57070f5844ec in js::gc::HeaderWord::get() const /firefox/js/src/gc/Cell.h:113:23
#1 0x57070f5844ec in js::gc::CellWithTenuredGCPointer<js::gc::Cell, js::Shape>::headerPtr() const /firefox/js/src/gc/Cell.h:846:60
#2 0x57070f5844ec in JSObject::shape() const /firefox/js/src/vm/JSObject.h:92:37
#3 0x57070f5844ec in JSObject::compartment() const /firefox/js/src/vm/JSObject.h:144:49
#4 0x57070f5844ec in js::ObjectWrapperMap::lookup(JSObject*) const /firefox/js/src/vm/Compartment.h:169:31
#5 0x57070f583f5f in JS::Compartment::lookupWrapper(JSObject*) const /firefox/js/src/vm/Compartment.h:375:43
#6 0x57070f583f5f in JS::Compartment::wrap(JSContext*, JS::MutableHandle<JS::Value>) /firefox/js/src/vm/Compartment-inl.h:90:37
#7 0x57070fa57ba5 in js::Debugger::wrapDebuggeeValue(JSContext*, JS::MutableHandle<JS::Value>) /firefox/js/src/debugger/Debugger.cpp:1521:34
#8 0x57070fb7df11 in js::DebuggerObject::getOwnPropertyDescriptor(JSContext*, JS::Handle<js::DebuggerObject*>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>>) /firefox/js/src/debugger/Object.cpp:2236:17
#9 0x57070fb7d71a in js::DebuggerObject::CallData::getOwnPropertyDescriptorMethod() /firefox/js/src/debugger/Object.cpp:828:8
#10 0x57070fbb37f2 in bool js::DebuggerObject::CallData::ToNative<&js::DebuggerObject::CallData::getOwnPropertyDescriptorMethod()>(JSContext*, unsigned int, JS::Value*) /firefox/js/src/debugger/Object.cpp:229:10
#11 0x57071115d7ca in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /firefox/js/src/vm/Interpreter.cpp:498:13
#12 0x57071115d7ca in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /firefox/js/src/vm/Interpreter.cpp:594:12
...
#22 0x57070fa69b20 in js::Debugger::firePromiseHook(JSContext*, js::Debugger::Hook, JS::Handle<JSObject*>) /firefox/js/src/debugger/Debugger.cpp:3096:13
#30 0x57070fa6a7d8 in js::Debugger::slowPathPromiseHook(JSContext*, js::Debugger::Hook, JS::Handle<js::PromiseObject*>) /firefox/js/src/debugger/Debugger.cpp:3119:3
#31 0x57070f8bcba0 in js::DebugAPI::onPromiseSettled(JSContext*, JS::Handle<js::PromiseObject*>) /firefox/js/src/debugger/DebugAPI-inl.h:186:5
#32 0x57070f8bcba0 in js::PromiseObject::onSettled(JSContext*, JS::Handle<js::PromiseObject*>, JS::Handle<js::SavedFrame*>) /firefox/js/src/builtin/Promise.cpp:8005:3
#33 0x57070f8bcba0 in ResolvePromise(JSContext*, JS::Handle<js::PromiseObject*>, JS::Handle<JS::Value>, JS::PromiseState, JS::Handle<js::SavedFrame*>) /firefox/js/src/builtin/Promise.cpp:2075:3
#39 0x57070f8c4616 in js::PromiseObject::unforgeableResolve(JSContext*, JS::Handle<JS::Value>) /firefox/js/src/builtin/Promise.cpp:6120:10
#40 0x57070f4f7509 in js::shell::ModuleLoader::dynamicImport(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::Handle<JS::Value>) /firefox/js/src/shell/ModuleLoader.cpp:381:18
#41 0x57070f4f21a4 in js::shell::ModuleLoader::loadImportedModule(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::Handle<JS::Value>) /firefox/js/src/shell/ModuleLoader.cpp:251:12
#42 0x5707116b3ac6 in js::HostLoadImportedModule(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<JS::Value>, unsigned int, JS::ColumnNumberOneOrigin) /firefox/js/src/vm/Modules.cpp:855:13
#44 0x5707116b8931 in js::StartDynamicModuleImport(JSContext*, JS::Handle<JSScript*>, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::ImportPhase) /firefox/js/src/vm/Modules.cpp:2839:8
#45 0x570711169010 in js::Interpret(JSContext*, js::RunState&) /firefox/js/src/vm/Interpreter.cpp:4396:11
...
SUMMARY: AddressSanitizer: SEGV /firefox/js/src/gc/Cell.h:113:23 in js::gc::HeaderWord::get() const
==21757==ABORTING
[Debug build: Assertion failure: vp.isObject(), at /firefox/js/src/vm/Compartment-inl.h:64]
| Reporter | ||
Comment 1•4 months ago
|
||
| Reporter | ||
Comment 2•4 months ago
|
||
| Reporter | ||
Comment 3•4 months ago
|
||
| Reporter | ||
Comment 4•4 months ago
|
||
Updated•4 months ago
|
Updated•4 months ago
|
Comment 6•2 months ago
|
||
JS shell only, requires the debugger API, and no longer reproduces after bug 1968904 changed our implementation.
Description
•