Lost abortLinearWeakMarking() on parallel GC helper markers -> use-after-free of swept WeakMap values (Assertion failure: WeakMapBase::checkMarkingForZone(zone), at gc/Sweeping.cpp:1263)
Categories
(Core :: JavaScript: GC, defect, P1)
Tracking
()
People
(Reporter: decoder, Assigned: jonco)
References
(Blocks 1 open bug, Regression)
Details
(4 keywords, Whiteboard: [adv-main153+r][adv-esr140.13+r])
Attachments
(1 file, 4 external files)
Summary
GCMarker::haveAllImplicitEdges (js/src/gc/GCMarker.h:689) is a per-marker flag, but it guards a runtime-global invariant: that the per-zone gcEphemeronEdges tables contain every implicit (weakmap) edge. During parallel marking (enabled by default), a helper-thread marker (GCRuntime::markers[1..]) can hit an allocation failure while populating the ephemeron edge tables and record the failure via GCMarker::abortLinearWeakMarking() on the helper marker. The only reader of the flag, GCMarker::enterWeakMarkingMode(), consults markers[0] exclusively, so the helper-side abort is silently lost. Weak marking then proceeds in linear mode trusting an incomplete ephemeron table; a WeakMap value whose key and map are both live is never marked and gets swept while still reachable. A later WeakMap.get(key) returns a pointer to a freed GC cell — a use-after-free.
SpiderMonkey JS shell version: 20260603-5cffec5992d3 (m-c-asan-debug / m-c-fuzzing-asan-opt).
Root cause
- Per-marker flag:
js/src/gc/GCMarker.h:688-689declaresMainThreadOrGCTaskData<bool> haveAllImplicitEdges;, initializedtruefor every marker inGCMarker::start()(js/src/gc/Marking.cpp:2484, called for all markers atjs/src/gc/GC.cpp:3395-3397). - Helper markers populate the ephemeron tables: with
parallelMarkingEnabled=true(default) andmarkers.length() >= 2, helper threads runWeakMap::trace->markEntries->markEntry->addEphemeronEdgesForEntryunderAutoLockGC(js/src/gc/WeakMap-inl.h:264-327), doing fallibleHashMap::add/Vector::emplaceBackallocations (js/src/gc/WeakMap.cpp:99-140). - Abort path: on allocation failure (
js/src/gc/WeakMap-inl.h:287-291)marker->abortLinearWeakMarking()setshaveAllImplicitEdges = falseon the helper marker (js/src/gc/Marking.cpp:2714-2719); the failed key->value edge is dropped. - Lost read: the only reader is
GCMarker::enterWeakMarkingMode()(js/src/gc/Marking.cpp:2636-2640), invoked only asmarker().enterWeakMarkingMode()(i.e.markers[0]) fromGCRuntime::markWeakReferences(js/src/gc/Sweeping.cpp:645). The helper markers' flags are never consulted. - Consequence: weak marking enters linear mode and marks weakmap values purely from
gcEphemeronEdges; the iterative rescue passWeakMapBase::markZoneIterativelyis skipped while weak-marking mode is active (js/src/gc/Sweeping.cpp:687-691). The dropped edge means the value is never marked. At sweep timetraceWeakEdgesDuringSweepingkeeps the entry (key is marked) while the value cell is finalized, leaving a danglingHeapPtrthatmap.get(key)returns to the mutator.
When the same OOM occurs on the main-thread marker, enterWeakMarkingMode() returns false and the engine falls back to the iterative fixpoint, which re-marks values directly from the entries — fully correct. Only the helper-side abort is lost. (Note: OOM-simulation fuzzing cannot reach this path — targeting THREAD_TYPE_GCPARALLEL disables parallel marking entirely, js/src/gc/GC.cpp:3505-3518.)
Reproduction
Pure-JS testcase, no prefs, no debug-only functions, no env vars:
m-c-asan-debug/dist/bin/js --fuzzing-safe poc.js # ~2-5 min
poc.js builds 40 WeakMaps x 3600 entries whose keys are reachable only through a long linked chain (so they are unmarked when the maps are traced, forcing ~144k ephemeron edges and >8 MB edge-table growth), then exhausts the process virtual address space with untouched ArrayBuffers. The provided shells bake in allocator_may_return_null=1, so the multi-megabyte edge-table doubling fails by returning null while 1 MB GC chunks keep working. The failure lands on whichever marker thread performs the doubling; when that is a helper marker, the abort is lost. Reproduces reliably (3/3 runs).
Debug build (debug-only MaybeCheckWeakMapMarking validator catches the corruption at end of marking):
WeakMap value is less marked than map and key
(map ... is black, key ... is black, value ... is white)
Assertion failure: WeakMapBase::checkMarkingForZone(zone), at js/src/gc/Sweeping.cpp:1263
Opt ASan build (validator is debug/zeal-only, so the corruption proceeds to the real UAF — WeakMap.get() returns a swept, poisoned cell):
==ERROR: AddressSanitizer: SEGV on unknown address (READ)
rdi = 0x4b4b4b4b02680268 (swept-cell poison)
#0 js::gc::Cell read in GetPropIRGenerator::tryAttachStub (gc/Cell.h:113)
#1 js::jit::TryAttachStub<GetPropIRGenerator,...>
#2 js::jit::DoGetPropFallback (jit/BaselineIC.cpp:1323)
The mechanism was independently confirmed by single-call fault injection with gdb on the stock debug binary: forcing one addEphemeronEdge to return false on a helper thread ($_thread != 1) trips the Sweeping.cpp:1263 assertion, while forcing it on the main thread ($_thread == 1) completes cleanly — isolating the defect to the helper-marker abort.
Crash signature
- Debug:
Assertion failure: WeakMapBase::checkMarkingForZone(zone), at js/src/gc/Sweeping.cpp:1263 - Opt ASan:
SEGV (READ)on swept-cell poison underjs::jit::DoGetPropFallback(UAF throughWeakMap.get).
Security impact
Release builds have no checkMarkingForZone validation; the corruption is silent until the dangling value is used. Trigger conditions are reachable from content JS: a small malloc failure on a GC helper thread while parallel marking traces a weakmap-heavy heap. Both parallel marking and incremental weakmap marking are default-on; no special prefs. Outcome is get()-able freed cells inside live WeakMaps and GC tracing of freed memory in later cycles — an attacker-groomable use-after-free.
Suggested fix
Make the abort signal runtime-global. Options: move haveAllImplicitEdges to GCRuntime; have abortLinearWeakMarking() set the flag on runtime->gc.marker() (helper-side weakmap marking already holds the GC lock, so this is race-free); or have enterWeakMarkingMode() consult every marker:
bool GCMarker::enterWeakMarkingMode() {
...
for (auto& marker : runtime()->gc.markers) {
if (!marker->haveAllImplicitEdges) {
return false;
}
}
...
}
Additionally, consider removing the OOM-simulation blind spot for THREAD_TYPE_GCPARALLEL (js/src/gc/GC.cpp:3505-3518) so this path becomes fuzzable.
Files
poc.js— self-contained shell testcase (run with--fuzzing-safe, ~2-5 min timeout).
| Reporter | ||
Comment 1•5 months ago
|
||
Comment 2•5 months ago
|
||
Jon, could you help look into this newer sec-high bug?
| Assignee | ||
Updated•5 months ago
|
| Assignee | ||
Comment 3•5 months ago
|
||
Currently this is tracked per-marker but the effect should be per-runtime.
There may be multiple markers due to parallel marking.
I couldn't get the tescase to reproduce here either.
Comment 5•4 months ago
|
||
Should we also follow up on the "Additionally, consider removing the OOM-simulation blind spot for THREAD_TYPE_GCPARALLEL (js/src/gc/GC.cpp:3505-3518) so this path becomes fuzzable." part?
| Assignee | ||
Comment 7•4 months ago
|
||
(In reply to Jon Coppeard (:jonco) from comment #6)
Thinking more about this, I'm not sure that works. OOM simulation requires predictable behaviour and I don't think we can get that with parallel marking as you never know which code is going to execute on each thread. That's why the restriction was there in the first place. It might be possible to arrange parallel marking on a single thread though, so we can test this path.
Comment 9•4 months ago
|
||
Comment 10•4 months ago
|
||
Please add uplift requests for beta, esr115, and esr140
| Assignee | ||
Updated•4 months ago
|
| Assignee | ||
Comment 11•4 months ago
|
||
This bug only happens if parallel marking is in use, and that landed in version 124.
| Assignee | ||
Comment 12•4 months ago
|
||
Currently this is tracked per-marker but the effect should be per-runtime.
There may be multiple markers due to parallel marking.
I couldn't get the tescase to reproduce here either.
Original Revision: https://phabricator.services.mozilla.com/D307221
Updated•4 months ago
|
Comment 13•4 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: Possible crash / security vulnerability.
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: This is a simple change to move a state flag from being per-marker to runtime wide. It's been on central for 4 days with no problems found.
- String changes made/needed?: None.
- Is Android affected?: yes
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Comment 14•4 months ago
|
||
| uplift | ||
Updated•4 months ago
|
| Assignee | ||
Comment 16•4 months ago
|
||
| Assignee | ||
Comment 17•4 months ago
|
||
Updated•4 months ago
|
Comment 18•4 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined/Reason for urgency: Possible crash / security vulnerability.
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: This is a simple fix that has been on central for 10 days without any issues found.
- String changes made/needed?: None
- Is Android affected?: yes
Updated•4 months ago
|
Updated•4 months ago
|
Comment 19•4 months ago
|
||
| uplift | ||
Comment 20•4 months ago
|
||
A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)
Updated•3 months ago
|
Updated•1 month ago
|
Description
•