SEGV in js::gc::GCRuntime::markUntilBudgetExhausted->js::GCMarker::processMarkStackTop, various crashes, and Assertion failure: !chunk->allocatedDuringCollection
Firefox could crash with a segmentation fault in the JavaScript garbage collector when a page using canvas image data and a large horizontal rule element was reloaded shortly after keyboard interaction. The reporter also saw a debug assertion about a chunk being allocated during collection, indicating a memory management bug in the GC.
Originally disclosed on Mozilla
- Fixed in 8 days
- Paid in 8 days
- Disclosed after 8 days
Created attachment 9530438
asan-SEGV-isSharedEmptySlots.txt
When run `canvas.createImageData()` and `<hr>` element with large size, while interacting the page with keyboard key, then reload the page after an short interval (within 40-170ms), on very intermittent case it able to crash Firefox with SEGV in `js::gc::GCRuntime::markUntilBudgetExhausted` to `js::GCMarker::processMarkStackTop` and other various JS GC crashes
I noticed it has more chance to hit the JS GC crashes on fuzzing build, probably due to `ac_add_option --enable-gczeal` flag or other slowdown which affect the timing.
On debug build it trigger `Assertion failure: !chunk->allocatedDuringCollection, at /builds/worker/checkouts/gecko/js/src/gc/BufferAllocator.cpp:1462`, in custom debug build with `MOZ_REALLY_CRASH(__LINE__);` been removed, it hit that Assertion failure before it crash on JS GC crashes or other JS assertion failure.
When using fuzzfetch to find the reproducible build date range, I then built Firefox ASAN fuzzing build on that commit range, I found it reproducible after commit on [Bug 1960811 - Part 6: Set a flag at the end of major sweeping](https://phabricator.services.mozilla.com/D245867).
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 garbage collector bookkeeping bug introduced when a flag was set at the end of major sweeping, causing a chunk to be allocated during collection and leading to crashes in the marking phase.
Impact
On an intermittent basis the browser could crash, and debug builds hit an assertion before the crash; the report does not claim any memory corruption exploit beyond the crash.
What the attacker needed
Victim loads a crafted page; keyboard interaction with the page; reload within 40-170ms; intermittent timing-dependent trigger
How it was found
- Open a page that calls canvas.createImageData() and contains a large hr element.
- Interact with the page using the keyboard.
- Reload the page within roughly 40 to 170 milliseconds.
- Observe the intermittent crash in the JS garbage collector.
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.
A browser has to clean up unused memory now and then, and this cleanup is called garbage collection. In this case the cleanup code could get confused and crash the whole browser, which means a page could take down the tab or the browser rather than just misbehave.
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.