Controlled write-what-where via Nursery::forwardBufferPointer misclassifying a tenured one-past-the-end elements pointer that aliases a nursery chunk base
Categories
(Core :: JavaScript: GC, defect, P1)
Tracking
()
People
(Reporter: tjr, Assigned: sfink)
References
(Blocks 1 open bug)
Details
(5 keywords, Whiteboard: [adv-main155+r][adv-esr153.2+r][adv-esr140.15+r][adv-esr115.40+r])
Attachments
(3 files, 5 external files)
|
3.28 KB,
text/plain
|
Details | |
|
794 bytes,
patch
|
Details | Diff | Splinter Review | |
|
3.42 KB,
text/plain
|
Details |
Nursery::Space::isInside (js/src/gc/Nursery.h:745-751) considers a pointer inside the nursery iff uintptr_t(p) - uintptr_t(chunk) < ChunkSize for some nursery chunk, which classifies a pointer numerically equal to a nursery chunk base as nursery-resident. Nursery::forwardBufferPointer (js/src/gc/Nursery.cpp:964-993), used during every minor GC to fix up slots/elements pointers spilled in Ion frames (js/src/jit/JitFrames.cpp:1164,1183), blindly dereferences any 'inside' pointer not found in the forwardedBuffers table as a BufferRelocationOverlay and writes the read value back into the frame slot; its IsWriteableAddress check is DEBUG-only.
A zero-capacity tenured ArrayObject (e.g. from deserialize(serialize(new Array(100))), AllocKind OBJECT2) placed in the last cell of a tenured chunk has its elements_ pointer exactly at the chunk end; when that tenured chunk sits 1 MiB below a nursery chunk, elements_ equals the nursery chunk base. This layout is acknowledged as real in js/src/vm/ArrayBufferObject.cpp:3236-3242. The earlier bug-2045451 mitigation (Space::setCurrentEnd reserving CellAlignBytes at nursery chunk ends, js/src/gc/Nursery.cpp:2146-2155) only handles the nursery-side direction and does not prevent this tenured-side aliasing.
When an Ion frame holds such an elements pointer live across a minor GC, forwardBufferPointer dereferences the nursery chunk base — whose first word is the ChunkBase::storeBuffer field (js/public/HeapAPI.h:141-148), i.e. &rt->gc.storeBuffer_ — and patches the spilled elements pointer to that address. The subsequent Ion store-element-hole then performs an attacker-indexed 8-byte write of a raw double into the runtime's StoreBuffer object (index chosen via the array's length). The next minor GC traces the corrupted store buffer and dereferences the attacker value; the verified run crashed with rdi = 0x4141414141414141 in StoreBuffer::ValueEdge::trace. This is a controlled write-what-where in the JS engine reachable from untrusted JavaScript.
Build Info
- Branch: main
- Revision: ca6e9493686b3e5ed1cddb8d3a3974068463df71
- Timestamp: 2026-07-29T00:55:15+00:00
Affected Code
File: js/src/gc/Nursery.h, line 745-751
MOZ_ALWAYS_INLINE bool Nursery::Space::isInside(const void* p) const {
for (auto* chunk : chunks_) {
if (uintptr_t(p) - uintptr_t(chunk) < gc::ChunkSize) { // p == chunk base => 'inside'
return true;
}
}
return false;
}
File: js/src/gc/Nursery.cpp, line 964-993
void js::Nursery::forwardBufferPointer(uintptr_t* pSlotsElems) {
auto* buffer = reinterpret_cast<void*>(*pSlotsElems);
if (!isInside(buffer)) { // one-past-the-end tenured pointer aliasing a
return; // nursery chunk base passes this check
}
if (ForwardedBufferMap::Ptr p = forwardedBuffers.lookup(buffer)) {
buffer = p->value();
} else {
BufferRelocationOverlay* reloc =
static_cast<BufferRelocationOverlay*>(buffer);
buffer = *reloc; // reads ChunkBase::storeBuffer
MOZ_ASSERT(IsWriteableAddress(buffer)); // DEBUG-only
}
*pSlotsElems = reinterpret_cast<uintptr_t>(buffer); // frame's elements ptr
} // becomes &gc.storeBuffer_
File: js/public/HeapAPI.h, line 141-148
// The store buffer for pointers from tenured things to things in this
// chunk. Will be non-null if and only if this is a nursery chunk.
StoreBuffer* storeBuffer; // first word of every nursery chunk
JSRuntime* runtime;
ChunkKind kind;
uint8_t nurseryChunkIndex;
File: js/src/vm/ArrayBufferObject.cpp, line 3236-3242
// Check the data pointer is not inside the nursery, but take account of the
// fact that inline data pointers for zero length buffers can point to the end
// of a chunk which can abut the start of the nursery.
if (src.byteLength() != 0 || (uintptr_t(src.dataPointer()) & gc::ChunkMask)) {
Nursery& nursery = obj->runtimeFromMainThread()->gc.nursery();
MOZ_ASSERT(!nursery.isInside(src.dataPointer()));
}
The reader (forwardBufferPointer/isInside) and the writers disagree about one-past-the-end pointers: a tenured zero-capacity array whose elements_ pointer equals an adjacent nursery chunk's base address is misclassified as a nursery buffer, and its 'relocation overlay' — actually the nursery chunk header's StoreBuffer* — is written into the Ion frame's spilled elements pointer. The debug comment in ArrayBufferObject.cpp confirms this chunk-end/nursery-base aliasing occurs in practice; setCurrentEnd's CellAlignBytes reservation (Nursery.cpp:2146-2155) only protects the opposite (nursery-side) direction.
Exploit Chain
- Grow the nursery to 64 MiB and record nursery chunk base addresses; find a pair where a later chunk sits exactly 1 MiB below an earlier one (verified run: aliasBase=0x7abcc0e00000).
- Shrink the nursery so the lower chunk is freed to the empty-chunk pool while the upper chunk remains a nursery chunk; spray tenured zero-capacity arrays (deserialize(serialize(new Array(100)))) until one lands in the recycled chunk's last OBJECT2 cell (verified: victim at 0x7abcc0dfffd8; elements_ = victim+40 = nursery chunk base).
- Warm f(a,v){var len=a.length; var t={x:v}; a[len]=v; return t;} in Ion so the elements pointer stays live across the {x:v} allocation; fill the nursery to within 64 bytes of the end and call f(victim, evil) so the allocation's out-of-line path triggers a minor GC with the elements pointer spilled at the safepoint.
- During the minor GC, UpdateIonJSFrameForMinorGC calls Nursery::forwardBufferPointer on the spilled pointer; isInside(nursery chunk base) is true, the forwardedBuffers lookup misses, and the chunk header's first word (&rt->gc.storeBuffer_) is written into the frame slot.
- After the GC, the Ion store-element-hole executes with elements == &rt->gc.storeBuffer_: it passes its bounds check against out-of-bounds 'initializedLength' data and writes the raw double 0x4141414141414141 at &storeBuffer_ + 8*victim.length — an attacker-indexed 8-byte controlled write (verified: attack L=2..4).
- The next minor GC traces the corrupted store buffer; StoreBuffer::MonoTypeBuffer<ValueEdge>::trace dereferences the attacker value, crashing with rdi = 0x4141414141414141 in JS::Value::isGCThing.
Steps to Reproduce
- Build Firefox/SpiderMonkey with /app/mozconfigs/mozconfig.linux.asan.fuzzing on an unmodified tree.
- Run the provided testcase.js in the JS shell: obj-firefox-asan/dist/bin/js --fuzzing-safe testcase.js (no extra flags, prefs, patches, or servers).
- The run prints the groomed layout stages (pair/aliasBase, victim at 0x...fffd8, attack L=2..4) and crashes in the following minorgc() with SEGV on the controlled address 0x4141414141414141 in js::gc::StoreBuffer::ValueEdge::trace. The heap-layout steps are probabilistic but include retries; it reproduced on the first attempt in this verification (~3 minutes under ASAN).
Security Impact
- Severity: High
- Attacker capability: An attacker running untrusted JavaScript obtains an 8-byte controlled write at an attacker-chosen index off the runtime's StoreBuffer object (write-what-where into JS runtime state), demonstrated by the subsequent minor GC dereferencing the attacker value 0x4141414141414141. This is a memory-corruption primitive in the content-process JS engine suitable as the basis for content-process code execution.
- Preconditions: Attacker-controlled JavaScript with Ion compilation enabled (default). The demonstrated testcase uses fuzzing-safe shell testing functions (objectAddress, gcparam, minorgc, serialize/deserialize) to make the required heap layout — a tenured chunk directly below a nursery chunk with a zero-capacity array in the tenured chunk's last cell — deterministic; the underlying aliasing layout is acknowledged as occurring naturally in ArrayBufferObject.cpp:3236-3242, so exploitation from web content requires heap grooming without those helpers.
ASAN Report
AddressSanitizer:DEADLYSIGNAL
=================================================================
==25297==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x5b89a62e6e54 bp 0x7ffc6c2b9ef0 sp 0x7ffc6c2b9e90 T0)
==25297==The signal is caused by a READ memory access.
==25297==Hint: this fault was caused by a dereference of a high value address (see register values below).
#0 0x5b89a62e6e54 in JS::Value::isGCThing() const /firefox/obj-firefox-asan/dist/include/js/Value.h:861:12
#1 0x5b89a62e6e54 in js::gc::StoreBuffer::ValueEdge::isGCThing() const /firefox/js/src/gc/StoreBuffer.h:274:43
#2 0x5b89a62e6e54 in js::gc::StoreBuffer::ValueEdge::trace(js::gc::TenuringTracer&) const /firefox/js/src/gc/Tenuring.cpp:847:8
#3 0x5b89a62e6e54 in js::gc::StoreBuffer::MonoTypeBuffer<js::gc::StoreBuffer::ValueEdge>::trace(js::gc::TenuringTracer&, js::gc::StoreBuffer*) /firefox/js/src/gc/Tenuring.cpp:389:11
#4 0x5b89a6279c1d in js::Nursery::traceRoots(js::gc::AutoGCSession&, js::gc::TenuringTracer&) /firefox/js/src/gc/Nursery.cpp:1685:8
#5 0x5b89a6276dac in js::Nursery::doCollection(js::gc::AutoGCSession&, JS::GCOptions, JS::GCReason) /firefox/js/src/gc/Nursery.cpp:1549:3
#6 0x5b89a627596a in js::Nursery::collect(JS::GCOptions, JS::GCReason) /firefox/js/src/gc/Nursery.cpp:1408:31
#7 0x5b89a61ed4dc in js::gc::GCRuntime::collectNursery(JS::GCOptions, JS::GCReason, js::gcstats::PhaseKind) /firefox/js/src/gc/GC.cpp:5507:13
#8 0x5b89a61cf9b0 in js::gc::GCRuntime::minorGC(JS::GCReason, js::gcstats::PhaseKind) /firefox/js/src/gc/GC.cpp:5476:3
#9 0x5b89a5b26f2e in JSContext::minorGC(JS::GCReason) /firefox/js/src/vm/JSContext-inl.h:286:17
#10 0x5b89a5b26f2e in MinorGC(JSContext*, unsigned int, JS::Value*) /firefox/js/src/builtin/TestingFunctions.cpp:823:7
#11 0x3a0d7ea848fe (<unknown module>)
==25297==Register values:
rax = 0x0828282828282828 rbx = 0x00007abcc8e60040 rcx = 0x00007abcc8adaa9f rdx = 0x00007abcc8fc51f0
rdi = 0x4141414141414141 rsi = 0x00007abcc8e60040 rbp = 0x00007ffc6c2b9ef0 rsp = 0x00007ffc6c2b9e90
r8 = 0x0000000000000000 r9 = 0xf2f20000f1f1f100 r10 = 0x00007ffc6c3080b0 r11 = 0x00007ffc6c308080
r12 = 0x00007abcc8e60040 r13 = 0x00007abcc8fc5210 r14 = 0x00007abcc8fc51f0 r15 = 0x00000f57991f8a42
SUMMARY: AddressSanitizer: SEGV /firefox/obj-firefox-asan/dist/include/js/Value.h:861:12 in JS::Value::isGCThing() const
==25297==ABORTING
(Preceding stdout: pair keep=2 free=3 aliasBase=0x7abcc0e00000 / victim at 0x7abcc0dfffd8 / attack L=2 / attack L=3 / attack L=4)
| Reporter | ||
Comment 1•4 months ago
|
||
| Reporter | ||
Comment 2•4 months ago
|
||
| Reporter | ||
Comment 3•4 months ago
|
||
| Reporter | ||
Comment 4•4 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.
| Reporter | ||
Updated•4 months ago
|
Updated•4 months ago
|
| Assignee | ||
Comment 5•3 months ago
|
||
Updated•3 months ago
|
Comment 7•3 months ago
|
||
:sfink, please update all release status flags to reflect the affected/unaffected/disabled state correctly. Which branches (beta, release, and/or ESR) are affected by this flaw?
Comment 9•3 months ago
|
||
| bugherder | ||
Updated•3 months ago
|
Comment 10•3 months ago
|
||
The patch landed in nightly and beta is affected, along with ESR.
:sfink, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta and ESR approvals.
- See https://wiki.mozilla.org/Release_Management/Requesting_an_Uplift for documentation on how to request an uplift.
- If no, please set
status-firefox155and the ESR status flag(s) towontfix.
For more information, please visit BugBot documentation.
| Assignee | ||
Comment 11•3 months ago
|
||
Sorry, I got a little lost when trying to dig into this to understand when it began. I thought it was probably the buffer allocator, but it seems like it predates that. It's probably from pretty close to the introduction of generational GC. I think it's worth some uplifts.
| Assignee | ||
Comment 12•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D318587
Updated•3 months ago
|
Comment 13•3 months ago
|
||
firefox-esr115 Uplift Approval Request
- User impact if declined/Reason for urgency: It's a UAF that is reachable with some heap grooming. It's pretty unlikely to accidentally trigger, but it does seem useful to an attacker. The AI described how to make use of it in the bug. It more ends up as an attacker-controlled read than a write, but there is an attacker-controlled write as part of the setup, so it seems pretty concerning.
- Code covered by automated testing?: no
- 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: The fix is pretty straightforward, and applies narrowly to pointers that point to a place where they wouldn't be pointing to in the first place if they are actual valid pointers. Specifically, it only changes behavior in the case where a pointer points to the beginning of a 1MB nursery chunk, and there is no real data at the beginning of a nursery chunk, so it cannot be a valid pointer into a nursery chunk. It could be a valid pointer into something else, but this patch causes it to fall back to the path where it is assumed to be something else (it does nothing, as there is nothing to fix up).
- String changes made/needed?: none
- Is Android affected?: yes
Comment 14•3 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined/Reason for urgency: It's a UAF that is reachable with some heap grooming. It's pretty unlikely to accidentally trigger, but it does seem useful to an attacker. The AI described how to make use of it in the bug. It more ends up as an attacker-controlled read than a write, but there is an attacker-controlled write as part of the setup, so it seems pretty concerning.
- Code covered by automated testing?: no
- 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: The fix is pretty straightforward, and applies narrowly to pointers that point to a place where they wouldn't be pointing to in the first place if they are actual valid pointers. Specifically, it only changes behavior in the case where a pointer points to the beginning of a 1MB nursery chunk, and there is no real data at the beginning of a nursery chunk, so it cannot be a valid pointer into a nursery chunk. It could be a valid pointer into something else, but this patch causes it to fall back to the path where it is assumed to be something else (it does nothing, as there is nothing to fix up).
- String changes made/needed?: none
- Is Android affected?: yes
| Assignee | ||
Comment 15•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D318587
| Assignee | ||
Comment 16•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D318587
Updated•3 months ago
|
Comment 17•3 months ago
|
||
firefox-esr153 Uplift Approval Request
- User impact if declined/Reason for urgency: It's a UAF that is reachable with some heap grooming. It's pretty unlikely to accidentally trigger, but it does seem useful to an attacker. The AI described how to make use of it in the bug. It more ends up as an attacker-controlled read than a write, but there is an attacker-controlled write as part of the setup, so it seems pretty concerning.
- Code covered by automated testing?: no
- 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: The fix is pretty straightforward, and applies narrowly to pointers that point to a place where they wouldn't be pointing to in the first place if they are actual valid pointers. Specifically, it only changes behavior in the case where a pointer points to the beginning of a 1MB nursery chunk, and there is no real data at the beginning of a nursery chunk, so it cannot be a valid pointer into a nursery chunk. It could be a valid pointer into something else, but this patch causes it to fall back to the path where it is assumed to be something else (it does nothing, as there is nothing to fix up).
- String changes made/needed?: none
- Is Android affected?: yes
| Assignee | ||
Comment 18•3 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D318587
Updated•3 months ago
|
Comment 19•3 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: UAF, controlled write, pretty bad. The AIs can figure out how to use it.
- Code covered by automated testing?: no
- 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: Straightforward fix that avoids doing an access in a situation where the access only makes sense in an impossible situation.
- String changes made/needed?: none
- Is Android affected?: yes
Updated•3 months ago
|
Updated•3 months ago
|
Updated•3 months ago
|
Updated•3 months ago
|
Comment 20•3 months ago
|
||
| uplift | ||
Comment 21•3 months ago
|
||
| uplift | ||
Updated•3 months ago
|
Updated•3 months ago
|
Comment 22•3 months ago
|
||
| uplift | ||
Updated•3 months ago
|
Updated•3 months ago
|
Comment 23•3 months ago
|
||
| uplift | ||
Updated•3 months ago
|
Updated•3 months ago
|
Updated•23 days ago
|
Updated•23 days ago
|
Description
•