Open Bug 2077081 Opened 1 month ago Updated 1 month ago

SpiderMonkey asserts after lowering the GC helper-thread limit

Categories

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

defect

Tracking

()

UNCONFIRMED

People

(Reporter: bugmon, Unassigned)

References

Details

(Keywords: assertion, testcase)

Attachments

(6 files)

GCRuntime::updateHelperThreadCount assigns a smaller maxParallelThreads without reconciling already-dispatched GC work (js/src/gc/GC.cpp:1604). Starting the next collection's unmark task reaches GCRuntime::maybeDispatchParallelTasks with dispatchedParallelTasks exceeding the new limit and triggers its assertion (js/src/gc/GC.cpp:3122; js/src/gc/GCParallelTask.cpp:246).

A script author with access to SpiderMonkey's GC testing functions can terminate a debug shell by interleaving off-thread compilation, nursery collections, GC-parameter changes, and an incremental collection. The clean debug run reproduced under --fuzzing-safe; the optimized ASAN run completed successfully. Memory corruption and browser-content reachability are not demonstrated.

This finding was discovered during variant analysis seeded by bug 1646708.

Build Info

Affected Code

File: js/src/gc/GC.cpp, line 1580-1582

  size_t targetCount =
      std::max(helperThreadCount.ref(),
               markingThreadCount.ref() + SpareThreadsDuringParallelMarking);

File: js/src/gc/GC.cpp, line 1603-1605

  // Update the maximum number of threads that will be used for GC work.
  maxParallelThreads = targetCount;
}

File: js/src/gc/GCParallelTask.cpp, line 243-255

void GCRuntime::maybeDispatchParallelTasks(
    const AutoLockHelperThreadState& lock) {
  MOZ_ASSERT(maxParallelThreads != 0);
  MOZ_ASSERT(dispatchedParallelTasks <= maxParallelThreads);

  while (dispatchedParallelTasks < maxParallelThreads &&
         !queuedParallelTasks.ref().isEmpty(lock)) {
    GCParallelTask* task = queuedParallelTasks.ref().popFirst(lock);
    task->setDispatched(lock);
    HelperThreadState().submitTask(task, lock);
    dispatchedParallelTasks++;
  }
}

GCRuntime::setThreadParameter calls updateHelperThreadCount after changing the configured limit. That function can reduce maxParallelThreads below the outstanding-task count, violating an invariant checked whenever the scheduler dispatches work.

Exploit Chain

  1. Run the supplied JavaScript testcase in a debug SpiderMonkey shell with its GC testing functions available.
  2. Configure eight GC helper threads and zero marking threads, then create allocation pressure and off-thread compilation jobs.
  3. Request background allocation, shrink the nursery, and perform a minor collection.
  4. Reduce maxHelperThreads to one while asynchronous GC work remains dispatched.
  5. Start an incremental collection. Its unmark task reaches maybeDispatchParallelTasks and trips dispatchedParallelTasks <= maxParallelThreads.

Steps to Reproduce

  1. Use the unmodified Firefox source at revision 8445f37d6a14937595eabb96376b4433b4eb67e7.
  2. Call build_firefox with firefox_dir="/firefox" and mozconfig_path="/app/mozconfigs/mozconfig.js.linux.debug".
  3. Call js_shell_evaluator with the complete contents of /tmp/tmp1ugdseu6/repro.js, js_binary="/firefox/obj-js-debug/dist/bin/js", flags=[], and timeout=120. The evaluator supplies --fuzzing-safe.
  4. Observe crashed=true, timed_out=false, and exit_code=1. The independently captured stack is preserved at /tmp/tmp1ugdseu6/verification/debug-run/log_stderr.txt.
  5. For the optimized control, build with /app/mozconfigs/mozconfig.linux.asan.fuzzing and run the same testcase using /firefox/obj-firefox-asan/dist/bin/js. The independent run returned crashed=false, timed_out=false, and exit_code=0.

Security Impact

  • Severity: Low
  • Attacker capability: Trigger a GC scheduler invariant violation and terminate a debug SpiderMonkey shell. No memory corruption, release-build crash, or browser-content trigger was demonstrated.
  • Preconditions: Access to SpiderMonkey's GC testing functions, enabled helper threads, overlapping asynchronous work, and a debug build. The testcase requires no source patch or harness bypass.

ASAN Report

[10029] Assertion failure: dispatchedParallelTasks <= maxParallelThreads, at js/src/gc/GCParallelTask.cpp:246
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==10029==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5621381f2cdf bp 0x7ec4a6665140 sp 0x7ec4a6665110 T10029)
    #0 0x5621381f2cdf in MOZ_CrashSequence(void*, long) /firefox/obj-js-debug/dist/include/mozilla/Assertions.h:261:3
    #1 0x5621381f2cdf in js::gc::GCRuntime::maybeDispatchParallelTasks(js::AutoLockHelperThreadState const&) /firefox/obj-js-debug/js/src/gc/./../../../../js/src/gc/GCParallelTask.cpp:246:3
    #2 0x5621381ce208 in js::GCParallelTask::start() /firefox/obj-js-debug/js/src/gc/./../../../../js/src/gc/GCParallelTask.cpp:64:3
    #3 0x5621381d7615 in js::gc::GCRuntime::beginPreparePhase(js::gc::AutoGCSession&) /firefox/obj-js-debug/js/src/gc/./../../../../js/src/gc/GC.cpp:3122:16
    #4 0x5621381e2042 in js::gc::GCRuntime::incrementalSlice(JS::SliceBudget&, JS::GCReason, bool) /firefox/obj-js-debug/js/src/gc/./../../../../js/src/gc/GC.cpp:4450:12
    #5 0x5621381e5ed5 in js::gc::GCRuntime::gcCycle(bool, JS::SliceBudget const&, JS::GCReason) /firefox/obj-js-debug/js/src/gc/./../../../../js/src/gc/GC.cpp:5122:3
    #6 0x5621381e77ff in js::gc::GCRuntime::collect(bool, JS::SliceBudget const&, JS::GCReason) /firefox/obj-js-debug/js/src/gc/./../../../../js/src/gc/GC.cpp:5313:9
    #7 0x562137d38fcf in StartGC(JSContext*, unsigned int, JS::Value*) /firefox/obj-js-debug/js/src/builtin/./../../../../js/src/builtin/TestingFunctions.cpp:3213:10
SUMMARY: UndefinedBehaviorSanitizer: SEGV /firefox/obj-js-debug/dist/include/mozilla/Assertions.h:261:3 in MOZ_CrashSequence(void*, long)
==10029==ABORTING
Attached patch fix.patch — — Splinter Review
Attached file crash_stack.txt —
Attached file README.md —
Attached file repro.js —
Attached file log_stdout.txt —

This bug was filed automatically by an AI-powered security testing tool. The analysis, testcase, and any suggested patches were generated by an AI model and have NOT been verified by a human.

Please review all details carefully before triaging. The issue was confirmed by an independent verifier, but for non-ASAN issues, the verifier has been made less strict. Additionally, the root cause analysis and suggested fix may contain errors.

Group: core-security → javascript-core-security
See Also: → 1646708
Blocks: sm-security
Severity: -- → S3
Priority: -- → P3
No longer blocks: sm-security
Group: javascript-core-security
Keywords: sec-other
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: