Skip to content
Memory corruption Disclosed report Advanced CVE-2023-4577

Assertion failure: kind == JS::TracerKind::Tenuring || kind == JS::TracerKind::MinorSweeping || kind == JS::TracerKind::Moving, at gc/Marking.cpp:137

A flaky assertion failure occurs in the JavaScript engine's garbage collector when a RegExpStatics object is destroyed during sweeping, triggering a write barrier that expects a different tracer kind. An attacker could potentially cause a crash, but the report does not demonstrate exploitation beyond a denial of service.

lukas.bernhard Follow

Originally disclosed on Mozilla

  • Fixed in 11 days
  • Paid in 24 days
  • Disclosed after 11 days
Text
Steps to reproduce:

On git commit 0816653c3ab851fa0e362eaec48c643fb764eaf4 the attached (flaky) sample crashes with one of two assertion violation.
I observed `js::Mutex::assertOwnedByCurrentThread at js/src/threading/Mutex.cpp:73` when reproducing with rr --chaos and
`Assertion failure: kind == JS::TracerKind::Tenuring || kind == JS::TracerKind::MinorSweeping || kind == JS::TracerKind::Moving, at gc/Marking.cpp:137` when running without an attached debugger.
The sample is invoked as `obj-x86_64-pc-linux-gnu/dist/bin/js --baseline-warmup-threshold=10 --ion-warmup-threshold=100 --fuzzing-safe --small-function-length=512 --inlining-entry-threshold=16 --gc-zeal=10 crash.js`
The crash is quite flaky; it takes a couple of dozens of execution until the crash manifests. I failed to further minimize the sample, sorry about that.
Furthermore, I only observed the crash in an optimized build; the mozconfig file is attached.
If you cannot reproduce the crash locally I'll upload a pernosco session.

'''
#0  js::Mutex::assertOwnedByCurrentThread (this=0x551e58e26c68)
    at js/src/threading/Mutex.cpp:73
#1  0x000056358f6a4536 in js::gc::StoreBuffer::unput<js::gc::StoreBuffer::MonoTypeBuffer<js::gc::StoreBuffer::CellPtrEdge<JSString> >, js::gc::StoreBuffer::CellPtrEdge<JSString> > (buffer=...,
    edge=..., this=<optimized out>) at js/src/gc/StoreBuffer.h:409
#2  js::gc::StoreBuffer::unputCell (strp=0x551e58e539e8, this=<optimized out>)
    at js/src/gc/StoreBuffer.h:481
#3  js::gc::PostWriteBarrierImpl<JSString> (cellp=<optimized out>, prev=<optimized out>,
    next=<optimized out>) at js/src/gc/StoreBuffer.h:636
#4  js::gc::PostWriteBarrier<JSString> (vp=<optimized out>, prev=<optimized out>,
    next=<optimized out>) at js/src/gc/StoreBuffer.h:647
#5  js::InternalBarrierMethods<JSString*, void>::postBarrier (vp=<optimized out>,
    prev=<optimized out>, next=<optimized out>)
    at js/src/gc/Barrier.h:349
#6  js::WriteBarriered<JSString*>::post (this=<optimized out>, prev=<optimized out>,
    next=<optimized out>) at js/src/gc/Barrier.h:509
#7  js::HeapPtr<JSString*>::~HeapPtr (this=0x551e58e539e8)
    at js/src/gc/Barrier.h:703
#8  js::RegExpStatics::~RegExpStatics (this=0x551e58e53940)
    at js/src/vm/RegExpStatics.h:17
#9  0x000056358f67ea2d in js_delete<js::RegExpStatics> (p=0x551e58e53940)
    at obj-x86_64-pc-linux-gnu/dist/include/js/Utility.h:566
#10 JS::DeletePolicy<js::RegExpStatics>::operator() (this=<optimized out>, ptr=0x551e58e53940)
    at obj-x86_64-pc-linux-gnu/dist/include/js/Utility.h:639
#11 mozilla::UniquePtr<js::RegExpStatics, JS::DeletePolicy<js::RegExpStatics> >::reset (
    this=0x551e58ec3ed0, aPtr=0x0)
    at obj-x86_64-pc-linux-gnu/dist/include/mozilla/UniquePtr.h:301
#12 mozilla::UniquePtr<js::RegExpStatics, JS::DeletePolicy<js::RegExpStatics> >::~UniquePtr (
    this=0x551e58ec3ed0)
    at obj-x86_64-pc-linux-gnu/dist/include/mozilla/UniquePtr.h:249
#13 js::GlobalObjectData::~GlobalObjectData (this=0x551e58ec3800)
    at js/src/vm/GlobalObject.cpp:1002
#14 JS::GCContext::delete_<js::GlobalObjectData> (this=0x551e58e23740, cell=0x1d29829ab240, 
    p=0x551e58ec3800, nbytes=1808, use=js::MemoryUse::GlobalObjectData)
    at js/src/gc/GCContext.h:163
#15 JS::GCContext::delete_<js::GlobalObjectData> (this=0x551e58e23740, cell=0x1d29829ab240,
    p=0x551e58ec3800, use=js::MemoryUse::GlobalObjectData)
    at js/src/gc/GCContext.h:151
#16 js::GlobalObject::releaseData (this=0x1d29829ab240, gcx=0x551e58e23740)
    at js/src/vm/GlobalObject.cpp:997
#17 0x000056358fecc1ef in js::gc::GCRuntime::sweepRealmGlobals (this=0x551e58e23728)
    at js/src/gc/Sweeping.cpp:1233
#18 js::gc::GCRuntime::beginSweepingSweepGroup (this=0x551e58e23728, gcx=0x551e58e23740,
    budget=...) at js/src/gc/Sweeping.cpp:1570
#19 0x000056358fef1481 in sweepaction::SweepActionSequence::run (this=0x551e58e06970, args=...)
    at js/src/gc/Sweeping.cpp:2165
#20 0x000056358feeca00 in sweepaction::SweepActionForEach<js::gc::SweepGroupsIter, JSRuntime*>::run (this=0x551e58e1a100, args=...) at js/src/gc/Sweeping.cpp:2200
#21 0x000056358fed4cda in js::gc::GCRuntime::performSweepActions (this=0x551e58e23728,
    budget=...) at js/src/gc/Sweeping.cpp:2342
#22 0x000056358fe13dd2 in js::gc::GCRuntime::incrementalSlice (this=0x551e58e23728, budget=...,
    reason=JS::GCReason::DESTROY_RUNTIME, budgetWasIncreased=<optimized out>)
    at js/src/gc/GC.cpp:3670
#23 0x000056358fe19bfa in js::gc::GCRuntime::gcCycle (this=0x551e58e23728,
    nonincrementalByAPI=<optimized out>, budgetArg=..., reason=JS::GCReason::DESTROY_RUNTIME)
    at js/src/gc/GC.cpp:4181
#24 0x000056358fe1b670 in js::gc::GCRuntime::collect (this=0x551e58e23728,
    nonincrementalByAPI=<optimized out>, budget=..., reason=JS::GCReason::DESTROY_RUNTIME)
    at js/src/gc/GC.cpp:4372
#25 0x000056358fde06aa in js::gc::GCRuntime::gc (this=0x551e58e23728,
    options=JS::GCOptions::Shutdown, reason=JS::GCReason::DESTROY_RUNTIME)
    at js/src/gc/GC.cpp:4449
#26 0x000056358f846848 in JSRuntime::destroyRuntime (this=0x551e58e23000)
    at js/src/vm/Runtime.cpp:266
#27 0x000056358f6c4a91 in js::DestroyContext (cx=0x551e58e31500)
    at js/src/vm/JSContext.cpp:222
#28 0x000056358f3b01d4 in JS_DestroyContext (cx=0x551e58e31500)
    at js/src/jsapi.cpp:405
#29 main::$_2::operator() (this=<optimized out>)
    at js/src/shell/js.cpp:11283
#30 mozilla::ScopeExit<main::$_2>::~ScopeExit (this=<optimized out>)
    at obj-x86_64-pc-linux-gnu/dist/include/mozilla/ScopeExit.h:106
#31 main (argc=<optimized out>, argv=<optimized out>)
    at js/src/shell/js.cpp:11404
'''

The original report as published on Mozilla's Bugzilla, by lukas.bernhard. 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

Impact

The vulnerability could cause a denial of service through a crash, but only in an optimized build and with a flaky trigger.

What the attacker needed

Optimized build; specific commit; flaky trigger

How it was found

  1. Build the JavaScript shell at the specified commit with an optimized configuration.
  2. Run the shell with the provided flags and the crash.js sample.
  3. Repeat execution multiple times until the flaky crash occurs.

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 the JavaScript engine's memory management. When the engine cleans up old objects, it sometimes crashes because a cleanup step expects a certain internal state that isn't met. The crash is hard to trigger reliably and only happened in a special build.

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

View all

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