Crash on GC after redeclare let or const on the web console [js::gc::Cell::runtimeFromAnyThread (this=0x4b4b4b4b4b4b4b4b)]
Redeclaring a let or const binding in the Firefox web console and then repeatedly reloading the page or typing split expressions caused the tab to crash inside the garbage collector. The crash was a read from an invalid address, which the reporter suggested could be exploitable.
Originally disclosed on Mozilla
- Fixed in 33 days
- Paid in 39 days
- Disclosed after 33 days
Created attachment 9186217 array-split-reload.html
When mistakenly re-declaration of let or const on the browser console, then reload the page repeatedly or typing string.split("") or string.split(" ") while waiting browser console instant evaluation result, suddenly the tab is crashed. To trigger the crash, on the HTML file it need to initialize one constant variable i.e const x = "A"
Mostly when Firefox Nightly ASAN crash, it shows AddressSanitizer: SEGV on unknown address (pc 0x7fa6e7dbe0b9 bp 0x7ffe338b3620 sp 0x7ffe338b3610 T0) but the unknown address is not showed.
Sometimes Nightly ASAN shows AddressSanitizer: use-after-poison on address 0x27f915ded218 at pc 0x7f4221357bb8 bp 0x7fffb52d8850 sp 0x7fffb52d8848 READ of size 8 at 0x27f915ded218 thread T0 (Web Content)
Rare moment, Nightly ASAN show the unknown address: AddressSanitizer: SEGV on unknown address 0x363339343840 (pc 0x7fdf867b7257 bp 0x7ffe9e3f92b0 sp 0x7ffe9e3f8e20 T0) (reproduced on Firefox Nightly ASAN 2020-10-26) (64-bit)
It seems Nightly ASAN tried to access address 0x363339343840 which is potentially exploitable and worth to investigate further.
I've attached Firefox Nightly ASAN log, full GDB log (launch with command line ./mach run --debugger="gdb-9" --debugger-args="-q --args" --disable-e10s), full valgrind log, and PoC video when reproduce the issue.
Browser tested:
- Firefox 82.0.2 (64-bit) on Arch Linux
- Firefox 78.4.0esr (64-bit) on Arch Linux
- Firefox Nightly 84.0a1 (2020-11-05) (64-bit) on Windows 10
- Firefox Nightly ASAN 84.0a1 (2020-11-05) (64-bit) on Arch Linux
Steps to Reproduce:
Reload the page
- Visit attached file: array-split-reload.html
- Enter below text to the console:
const array = string.split("") ↵ (press enter) const array = string.split("\n") ↵ (press enter)
- Reload the page repeatedly
- Tab is crashed.
Console instant evaluation
- Visit attached file: array-split.html
- Open Web Developer -> Web Console (Ctrl+Shift+K)
- Enter below text to the console:
const array = string.split("\n") ↵ (press enter) const array = string.split("") ↵ (press enter)
- Type to the console (without press enter):
string.split("") string.split(" ") string.split("") string.split(" ") string.split("") string.split("\n") string.split("")
If above doesn't crash the tab, reload the page, then re-type to the console (without press enter):
string.split("") string.split(" ") string.split("") string.split(" ") string.split("")
What happened? (actual results)
Gah. Your tab just crashed.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==236847==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7fa6e7dbe0b9 bp 0x7ffe338b3620 sp 0x7ffe338b3610 T0)
==236847==The signal is caused by a READ memory access.
==236847==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
error: address range table at offset 0x5c90 has an invalid tuple (length = 0) at offset 0x5ca0
#0 0x7fa6e7dbe0b9 in runtimeFromAnyThread /builds/worker/checkouts/gecko/js/src/gc/Cell.h:335:27
#1 0x7fa6e7dbe0b9 in IsOwnedByOtherRuntime<js::BaseShape *> /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:170:23
#2 0x7fa6e7dbe0b9 in ShouldMark<js::BaseShape *> /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:885:7
#3 0x7fa6e7dbe0b9 in void DoMarking<js::BaseShape>(js::GCMarker*, js::BaseShape*) /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:941:8
#4 0x7fa6e7dbe04d in bool js::gc::TraceEdgeInternal<js::BaseShape*>(JSTracer*, js::BaseShape**, char const*) /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:675:5
#5 0x7fa6e7dc5250 in js::GCMarker::eagerlyMarkChildren(js::Shape*) /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:1249:13
#6 0x7fa6e7d94223 in markAndScan<js::Shape> /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:1032:5
#7 0x7fa6e7d94223 in traverse<js::Shape *> /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:1042:3
#8 0x7fa6e7d94223 in traverseEdge<JSObject *, js::Shape> /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:1132:3
#9 0x7fa6e7d94223 in js::GCMarker::processMarkStackTop(js::SliceBudget&) /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:2102:3
#10 0x7fa6e7d93422 in js::GCMarker::markUntilBudgetExhausted(js::SliceBudget&, js::GCMarker::ShouldReportMarkTime) /builds/worker/checkouts/gecko/js/src/gc/Marking.cpp:1835:7
#11 0x7fa6e7d4331a in js::gc::GCRuntime::markUntilBudgetExhausted(js::SliceBudget&, js::GCMarker::ShouldReportMarkTime) /builds/worker/checkouts/gecko/js/src/gc/GC.cpp:5662:17
#12 0x7fa6e7d523de in js::gc::GCRuntime::incrementalSlice(js::SliceBudget&, mozilla::Maybe<JSGCInvocationKind> const&, JS::GCReason, js::gc::AutoGCSession&) /builds/worker/checkouts/gecko/js/src/gc/GC.cpp:6795:13
#13 0x7fa6e7d55ed5 in js::gc::GCRuntime::gcCycle(bool, js::SliceBudget, mozilla::Maybe<JSGCInvocationKind> const&, JS::GCReason) /builds/worker/checkouts/gecko/js/src/gc/GC.cpp:7249:3
#14 0x7fa6e7d58213 in js::gc::GCRuntime::collect(bool, js::SliceBudget, mozilla::Maybe<JSGCInvocationKind> const&, JS::GCReason) /builds/worker/checkouts/gecko/js/src/gc/GC.cpp:7484:9
#15 0x7fa6e7d32de3 in gcSlice /builds/worker/checkouts/gecko/js/src/gc/GC.cpp:7575:3
#16 0x7fa6e7d32de3 in js::gc::GCRuntime::gcIfRequested() /builds/worker/checkouts/gecko/js/src/gc/GC.cpp:7769:7
#17 0x7fa6e7d0345b in gcIfNeededAtAllocation /builds/worker/checkouts/gecko/js/src/gc/Allocator.cpp:451:5
#18 0x7fa6e7d0345b in bool js::gc::GCRuntime::checkAllocatorState<(js::AllowGC)1>(JSContext*, js::gc::AllocKind) /builds/worker/checkouts/gecko/js/src/gc/Allocator.cpp:406:10
#19 0x7fa6e7d05674 in JSString* js::AllocateStringImpl<JSString, (js::AllowGC)1>(JSContext*, js::gc::InitialHeap) /builds/worker/checkouts/gecko/js/src/gc/Allocator.cpp:209:15
#20 0x7fa6e717665d in AllocateString<JSThinInlineString, js::CanGC> /builds/worker/checkouts/gecko/js/src/gc/Allocator.h:61:32
#21 0x7fa6e717665d in new_<js::CanGC> /builds/worker/checkouts/gecko/js/src/vm/StringType-inl.h:322:10
#22 0x7fa6e717665d in AllocateInlineString<js::CanGC, unsigned char> /builds/worker/checkouts/gecko/js/src/vm/StringType-inl.h:35:31
#23 0x7fa6e717665d in NewInlineString<js::CanGC, unsigned char> /builds/worker/checkouts/gecko/js/src/vm/StringType-inl.h:63:25
#24 0x7fa6e717665d in JSLinearString* js::Int32ToString<(js::AllowGC)1>(JSContext*, int) /builds/worker/checkouts/gecko/js/src/jsnum.cpp:816:7
#25 0x7fa6e79fd6ee in js::IdVectorToArray(JSContext*, JS::Handle<JS::GCVector<JS::PropertyKey, 0ul, js::TempAllocPolicy> >) /builds/worker/checkouts/gecko/js/src/debugger/Frame.cpp:1926:23
#26 0x7fa6e7a8c431 in js::DebuggerObject::CallData::getOwnPropertyNamesMethod() /builds/worker/checkouts/gecko/js/src/debugger/Object.cpp:778:24
#27 0x7fa6e7aad28e in bool js::DebuggerObject::CallData::ToNative<&(js::DebuggerObject::CallData::getOwnPropertyNamesMethod())>(JSContext*, unsigned int, JS::Value*) /builds/worker/checkouts/gecko/js/src/debugger/Object.cpp:243:10
#28 0x7fa652f6344f (<unknown module>)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /builds/worker/checkouts/gecko/js/src/gc/Cell.h:335:27 in runtimeFromAnyThread
==236847==ABORTING
JavaScript error: resource:///modules/ContentCrashHandlers.jsm, line 50: TypeError: can't access property "permanentKey", browser is undefined
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-collection marking bug where a shape or base shape reachable from the debugger's object inspection is traced after its memory has become invalid, triggered by the console's handling of a redeclaration error.
Impact
The tab crashes, and the reporter notes the invalid address accessed could potentially be exploitable, though no exploitation is demonstrated.
What the attacker needed
Firefox browser; victim opens a crafted HTML page; user types redeclarations in console
How it was found
- Open the attached HTML file that initialises a constant variable.
- In the web console, enter two const declarations that redeclare the same name using split calls.
- Reload the page repeatedly.
- The tab crashes.
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.
The browser console lets you type JavaScript to inspect a page. If you declare the same variable name twice with let or const, that is an error, but here it left the browser's memory bookkeeping in a bad state. Later, when the browser cleaned up memory (garbage collection), it read from a bogus address and the tab crashed.
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.