Closed Bug 1995159 Opened 1 year ago Closed 1 year ago

Assertion failure: retainedBytes_ >= nbytes, at js/src/gc/Scheduling.h:688

Categories

(Core :: JavaScript: GC, defect, P1)

defect

Tracking

()

RESOLVED FIXED
146 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox145 --- unaffected
firefox146 --- fixed

People

(Reporter: sakura, Assigned: jonco)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression, reporter-external, Whiteboard: [client-bounty-form][fuzzblocker])

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 poc.js

Test SpiderMonkey commit hash: 3050e6c0372952b8982733f8256c143f495879d6

Crash Stack Trace

--------------------------------------------------------------------------------
[3737168] Assertion failure: retainedBytes_ >= nbytes, at /home/sakura/gecko-dev/js/src/gc/Scheduling.h:688
#01: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2c728a5]
#02: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2c60cbc]
#03: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2c62e40]
#04: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2dbf29d]
#05: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2dc183b]
#06: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cf0dc2]
#07: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cf07ac]
#08: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cb7435]
#09: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2dc16cc]
#10: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2dd35ce]
#11: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e27e7d]
#12: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e0891b]
#13: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2dde34b]
#14: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cd6427]
#15: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cdc149]
#16: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cde35c]
#17: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2cb5f6c]
#18: JS::NonIncrementalGC(JSContext*, JS::GCOptions, JS::GCReason)[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2ceab44]
#19: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x264b9df]
#20: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dffa6f]
#21: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dff033]
#22: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1e15f11]
#23: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dfdf3c]
#24: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dfef5c]
#25: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2f84f6d]
#26: ??? (???:???)
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==3737168==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5566452988bd bp 0x7fff35c8ec70 sp 0x7fff35c8ec50 T3737168)
==3737168==The signal is caused by a WRITE memory access.
==3737168==Hint: address points to the zero page.
LLVMSymbolizer: error reading file: No such file or directory
#0 0x5566452988bd in MOZ_CrashSequence(void*, long) /home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/include/mozilla/Assertions.h:237:3
#1 0x5566452988bd in js::gc::HeapSize::removeBytes(unsigned long, bool) /home/sakura/gecko-dev/js/src/gc/Scheduling.h:688:7
#2 0x5566452988bd in js::gc::BufferAllocator::decreaseHeapSize(unsigned long, bool, bool) /home/sakura/gecko-dev/js/src/gc/BufferAllocator.cpp:3247:26
#3 0x556645286cbb in js::gc::BufferAllocator::sweepChunk(js::gc::BufferChunk*, js::gc::BufferAllocator::SweepKind, bool) /home/sakura/gecko-dev/js/src/gc/BufferAllocator.cpp:2528:5
#4 0x556645288e3f in js::gc::BufferAllocator::sweepForMajorCollection(bool) /home/sakura/gecko-dev/js/src/gc/BufferAllocator.cpp:1301:9
#5 0x5566453e529c in js::gc::GCRuntime::sweepBackgroundThings(js::gc::ZoneList&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:419:27
#6 0x5566453e783a in js::gc::GCRuntime::sweepFromBackgroundThread(js::AutoLockHelperThreadState&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:527:5
#7 0x556645316dc1 in js::GCParallelTask::runTask(JS::GCContext*, js::AutoLockHelperThreadState&) /home/sakura/gecko-dev/js/src/gc/GCParallelTask.cpp:218:3
#8 0x5566453167ab in js::GCParallelTask::runFromMainThread(js::AutoLockHelperThreadState&) /home/sakura/gecko-dev/js/src/gc/GCParallelTask.cpp:174:3
#9 0x5566452dd434 in js::GCParallelTask::runFromMainThread() /home/sakura/gecko-dev/js/src/gc/GCParallelTask.cpp:161:3
#10 0x5566453e76cb in js::gc::GCRuntime::queueZonesAndStartBackgroundSweep(js::gc::ZoneList&&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:510:15
#11 0x5566453f95cd in js::gc::GCRuntime::endSweepingSweepGroup(JS::GCContext*, JS::SliceBudget&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:1836:3
#12 0x55664544de7c in sweepaction::SweepActionSequence::run(js::gc::SweepAction::Args&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:2325:23
#13 0x55664542e91a in sweepaction::SweepActionForEach<js::gc::SweepGroupsIter, JSRuntime*>::run(js::gc::SweepAction::Args&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:2360:19
#14 0x55664540434a in js::gc::GCRuntime::performSweepActions(JS::SliceBudget&) /home/sakura/gecko-dev/js/src/gc/Sweeping.cpp:2521:53
#15 0x5566452fc426 in js::gc::GCRuntime::incrementalSlice(JS::SliceBudget&, JS::GCReason, bool) /home/sakura/gecko-dev/js/src/gc/GC.cpp:4067:11
#16 0x556645302148 in js::gc::GCRuntime::gcCycle(bool, JS::SliceBudget const&, JS::GCReason) /home/sakura/gecko-dev/js/src/gc/GC.cpp:4620:3
#17 0x55664530435b in js::gc::GCRuntime::collect(bool, JS::SliceBudget const&, JS::GCReason) /home/sakura/gecko-dev/js/src/gc/GC.cpp:4809:9
#18 0x5566452dbf6b in js::gc::GCRuntime::gc(JS::GCOptions, JS::GCReason) /home/sakura/gecko-dev/js/src/gc/GC.cpp:4889:3
#19 0x556645310b43 in JS::NonIncrementalGC(JSContext*, JS::GCOptions, JS::GCReason) /home/sakura/gecko-dev/js/src/gc/GCAPI.cpp:300:21
#20 0x556644c719de in GC(JSContext*, unsigned int, JS::Value*) /home/sakura/gecko-dev/js/src/builtin/TestingFunctions.cpp:782:3
#21 0x556644425a6e in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:490:13
#22 0x556644425032 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:586:12
#23 0x55664443bf10 in js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:658:10
#24 0x55664443bf10 in js::Interpret(JSContext*, js::RunState&) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:3276:16
#25 0x556644423f3b in js::RunScript(JSContext*, js::RunState&) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:460:13
#26 0x556644424f5b in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:618:13
#27 0x5566455aaf6c in js::jit::DoCallFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICFallbackStub*, unsigned int, JS::Value*, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/jit/BaselineIC.cpp:1695:10
#28 0x3158409fe1fe  ([anon:js-executable-memory]+0xc1fe)

==3737168==Register values:
rax = 0x0000000000000000  rbx = 0x0000000000004000  rcx = 0x00000000000002b0  rdx = 0x00007fcf0e81b723
rdi = 0x00007fcf0e81ca60  rsi = 0x0000000000000000  rbp = 0x00007fff35c8ec70  rsp = 0x00007fff35c8ec50
r8 = 0x0000000000000000   r9 = 0x0000000000000003  r10 = 0x0000556646958eb0  r11 = 0x0000000000000293
r12 = 0x0000000000000000  r13 = 0x0000000000010000  r14 = 0x00007fcf0cafc000  r15 = 0x0000000000000001
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)
==3737168==ABORTING



================================================================================

PoC

try {
  var v0 = new FinalizationRegistry(function (v3) {});
} catch (v4) {}
{
  try {
    for (let v5 = 0; v5 < 1000; ++v5) {
      let v6 = Symbol();
      v0.register(v6, 0, v6);
      v0.register(v6, 0, v6);
      v0.register(v6, 0, v6);
    }
  } catch (v7) {}
}
function fn1() {
  gc();
}
fn1();
Flags: sec-bounty?
Group: firefox-core-security → javascript-core-security
Component: Security → JavaScript: GC
Product: Firefox → Core
See Also: → 1786395

Thanks for the report. Miscalculation of heap retained size is not a security issue though.

Group: javascript-core-security
Flags: sec-bounty?

This may have been caused by the changes to CellAllocPolicy in bug 1993183.

We're seeing this frequently in internal JS fuzzing, marking as fuzzblocker.

Whiteboard: [client-bounty-form] → [client-bounty-form][fuzzblocker]

Jon, are you going to work on this bug? I will mark it S2/P1 since it is a fuzzblocker.

Blocks: GC.stability
Severity: -- → S2
Flags: needinfo?(jcoppeard)
Priority: -- → P1

I'm going to get the regressing bug backed out.

Flags: needinfo?(jcoppeard)
Keywords: regression
Regressed by: 1993183

Fixed by backout of bug 1993183.

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Assignee: nobody → jcoppeard
Target Milestone: --- → 146 Branch
You need to log in before you can comment on or make changes to this bug.