Open Bug 2068353 Opened 2 months ago Updated 2 months ago

Heap-use-after-free in [@ js::BufferIterator::peek] during deserialize() when Debugger.onNativeCall replaces the clone buffer

Categories

(Core :: JavaScript: Debugger API, defect, P3)

defect

Tracking

()

UNCONFIRMED

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

  1. Create a debuggee global g and a Debugger on it.
  2. In g, call serialize([...]) 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 in g.cb.
  3. Install dbg.onNativeCall that, on the first call whose callee is DataView, assigns g.cb.clonebuffer = "AAAAAAAA".
  4. In g, call deserialize(cb). JSStructuredCloneReader::readDataView calls JS_NewDataView -> Construct -> CallJSNative -> DebugAPI::onNativeCall, running the hook.
  5. The hook's assignment runs CloneBufferObject::setCloneBuffer_impl -> discard() -> js_delete of the JSStructuredCloneData the reader is iterating, freeing its 4096-byte BufferList segment.
  6. The hook returns, the DataView is constructed, and JSStructuredCloneReader::read calls in.getPair, which dereferences the dangling BufferIterator in BufferIterator::peek — an 8-byte read from freed heap memory (ASAN heap-use-after-free).

Affected Code

Steps to Reproduce

  1. git -C /firefox checkout . (tree must be unmodified)
  2. build_firefox(firefox_dir='/firefox', mozconfig_path='/app/mozconfigs/mozconfig.linux.asan.fuzzing') -> build_dir /firefox/obj-firefox-asan
  3. js_shell_evaluator(content=<testcase.js>, js_binary='/firefox/obj-firefox-asan/dist/bin/js') with no extra flags (harness supplies --fuzzing-safe)
  4. 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 clonebuffer setter on the shell's CloneBufferObject and Debugger.prototype.onNativeCall — are shell testing / privileged debugger APIs, so no web-content path was demonstrated.
  • Preconditions: SpiderMonkey shell with testing functions (serialize, deserialize, clonebuffer setter) and the Debugger API available; reproduces under --fuzzing-safe with no other flags, prefs, or patches.

The full analysis report is attached (analysis.md).

Attached file crash_stack.txt —
Attached patch fix.patch — — Splinter Review
Attached file testcase.js —
Attached file analysis.md —

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.

Group: core-security → javascript-core-security

There's a cluster of similar onNativeCall bugs.

Component: JavaScript: Standard Library → JavaScript: Debugger API
Blocks: sm-security
Severity: -- → S3
Priority: -- → P3
Group: javascript-core-security
Depends on: 2046631
Keywords: sec-other
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: