Heap-use-after-free in [@ js::BufferIterator::peek] during deserialize() when Debugger.onNativeCall replaces the clone buffer
Categories
(Core :: JavaScript: Debugger API, defect, P3)
Tracking
()
People
(Reporter: bugmon, Unassigned)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
(Keywords: crash, testcase)
Attachments
(4 files)
Deserialize (js/src/builtin/TestingFunctions.cpp:6536) hands JS_ReadStructuredClone a const reference to the JSStructuredCloneData still owned by the mutable CloneBufferObject, so nothing keeps that buffer alive for the duration of the read: JSStructuredCloneReader::readDataView re-enters JS through JS_NewDataView -> Construct -> CallJSNative -> DebugAPI::onNativeCall, and a Debugger.prototype.onNativeCall hook that assigns cb.clonebuffer runs CloneBufferObject::setCloneBuffer_impl -> discard() -> js_delete, destroying the BufferList the active reader iterates. On return, JSStructuredCloneReader::read's in.getPair dereferences the now-dangling BufferIterator, giving an 8-byte heap-use-after-free read at js::BufferIterator::peek (js/src/vm/StructuredClone.cpp:269) with the reader continuing to parse freed memory as clone tags; both required primitives (the shell clonebuffer setter and the Debugger API) are shell/privileged-only, so no web-content path was demonstrated.
Exploit Chain
- Create a debuggee global
gand aDebuggeron it. - In
g, callserialize([...])with an array whose first element is a DataView, followed by further elements so the reader has more data to consume after the DataView; store the resulting CloneBufferObject ing.cb. - Install
dbg.onNativeCallthat, on the first call whose callee isDataView, assignsg.cb.clonebuffer = "AAAAAAAA". - In
g, calldeserialize(cb).JSStructuredCloneReader::readDataViewcallsJS_NewDataView->Construct->CallJSNative->DebugAPI::onNativeCall, running the hook. - The hook's assignment runs
CloneBufferObject::setCloneBuffer_impl->discard()->js_deleteof theJSStructuredCloneDatathe reader is iterating, freeing its 4096-byte BufferList segment. - The hook returns, the DataView is constructed, and
JSStructuredCloneReader::readcallsin.getPair, which dereferences the danglingBufferIteratorinBufferIterator::peek— an 8-byte read from freed heap memory (ASAN heap-use-after-free).
Affected Code
- js/src/builtin/TestingFunctions.cpp, line 6536-6538
- js/src/builtin/TestingFunctions.cpp, line 5818-5821, 5864-5866
- js/src/vm/StructuredClone.cpp, line 2849-2852
- js/src/vm/Interpreter.cpp, line 514-517
- js/src/vm/StructuredClone.cpp, line 4126-4134
- js/src/vm/StructuredClone.cpp, line 267-270
Steps to Reproduce
- git -C /firefox checkout . (tree must be unmodified)
- build_firefox(firefox_dir='/firefox', mozconfig_path='/app/mozconfigs/mozconfig.linux.asan.fuzzing') -> build_dir /firefox/obj-firefox-asan
- js_shell_evaluator(content=<testcase.js>, js_binary='/firefox/obj-firefox-asan/dist/bin/js') with no extra flags (harness supplies --fuzzing-safe)
- Observe AddressSanitizer heap-use-after-free at js/src/vm/StructuredClone.cpp:269 in js::BufferIterator<unsigned long, js::SystemAllocPolicy>::peek()
Security Impact
- Severity: Low
- Attacker capability: Read of freed heap memory (8 bytes per iteration of the structured-clone read loop) inside the JS shell; the reader continues to interpret attacker-influenced freed data as clone tags and payloads. Both required primitives — the
clonebuffersetter on the shell's CloneBufferObject andDebugger.prototype.onNativeCall— are shell testing / privileged debugger APIs, so no web-content path was demonstrated. - Preconditions: SpiderMonkey shell with testing functions (
serialize,deserialize,clonebuffersetter) and the Debugger API available; reproduces under --fuzzing-safe with no other flags, prefs, or patches.
The full analysis report is attached (analysis.md).
| Reporter | ||
Comment 1•2 months ago
|
||
| Reporter | ||
Comment 2•2 months ago
|
||
| Reporter | ||
Comment 3•2 months ago
|
||
| Reporter | ||
Comment 4•2 months ago
|
||
Comment 5•2 months ago
|
||
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.
WARNING: A blocking issue was auto-patched in the source used for this analysis. Please flag if you believe the bug was introduced by that patch.
Updated•2 months ago
|
Comment 6•2 months ago
|
||
There's a cluster of similar onNativeCall bugs.
Updated•2 months ago
|
Updated•2 months ago
|
Description
•