Uninitialized Tail Exposure After Resizable ArrayBuffer `transfer()`
Categories
(Core :: JavaScript Engine, defect, P1)
Tracking
()
People
(Reporter: pwn2car, Assigned: anba)
References
(Blocks 1 open bug, Regression)
Details
(5 keywords, Whiteboard: [adv-main149+][adv-ESR140.9+])
Attachments
(1 file, 4 external files)
|
2.50 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Steps to reproduce:
Uninitialized Tail Exposure After Resizable ArrayBuffer transfer()
Summary
When ArrayBuffer.prototype.transfer() is used on a resizable buffer with a
smaller target length, the destination backing store can keep uninitialized
bytes in the hidden grow area. A later resize() growth makes those bytes
visible to JS.
Repro Shape
- Create a resizable buffer:
new ArrayBuffer(16, { maxByteLength: 80 }) - Transfer to a smaller/same length:
transfer(8)ortransfer(16) - Grow back:
resize(80)
Observed: non-zero bytes show up in the expanded tail
Example: 77,77,77,77,77,77,254,255,...
Control case: plain resize shrink/grow (without transfer) keeps tail bytes
at zero.
Call Path
ArrayBuffer.prototype.transfer() enters:
js/src/vm/ArrayBufferObject.cpp:673ArrayBufferObject::transferImpljs/src/vm/ArrayBufferObject.cpp:679ArrayBufferCopyAndDetach(..., PreserveResizability::Yes)
Resizable branch:
js/src/vm/ArrayBufferObject.cpp:520js/src/vm/ArrayBufferObject.cpp:532ResizableArrayBufferObject::copyAndDetach(...)js/src/vm/ArrayBufferObject.cpp:2796ResizableArrayBufferObject::copyAndDetachjs/src/vm/ArrayBufferObject.cpp:2809ResizableArrayBufferObject::copy(...)
Vulnerable copy branch (newByteLength <= sourceByteLength):
js/src/vm/ArrayBufferObject.cpp:2656
createBufferAndData<FillContents::Uninitialized>(..., newMaxByteLength, ...)js/src/vm/ArrayBufferObject.cpp:2662
only[0..newByteLength)is copied from source
Important detail: for resizable buffers, allocation is sized to maxByteLength
(js/src/vm/ArrayBufferObject.cpp:2563), not just current byteLength.
Root Cause
The bug is an invariant mismatch between copy-time initialization and grow-time
assumptions.
Copy-time behavior:
- The transfer-shrink path allocates with
FillContents::Uninitialized. - Only the prefix is copied.
- The remainder
[newByteLength .. maxByteLength)is left uninitialized.
Grow-time behavior:
ResizableArrayBufferObject::resizedoes not zero-fill on growth.- It assumes growth regions are already zeroed by initial allocation or by a
previous shrink. - See
js/src/vm/ArrayBufferObject.cpp:1352tojs/src/vm/ArrayBufferObject.cpp:1355.
Those assumptions are true for normal resize-only flows, but false for this
transfer-shrink copy path.
Code Contrast
Uninitialized transfer-shrink copy:
auto [buffer, toFill] = createBufferAndData<FillContents::Uninitialized>(
cx, newByteLength, newMaxByteLength, metadata, nullptr);
std::uninitialized_copy_n(source->dataPointer(), newByteLength, toFill);
js/src/vm/ArrayBufferObject.cpp:2656
Grow path that skips zeroing:
// Clear only on shrink.
if (newByteLength < oldByteLength) {
memset(dataPointer() + newByteLength, 0, oldByteLength - newByteLength);
}
js/src/vm/ArrayBufferObject.cpp:1352
One side creates uninitialized tail bytes, the other side assumes tail bytes are
already safe.
Why the Control Case Looks Correct
In resize-only workflows, shrink explicitly clears truncated bytes:
js/src/vm/ArrayBufferObject.cpp:1359
So when the buffer is grown later, the no-zero-on-grow rule is still safe.
transfer(shrink) bypasses that safety guarantee.
Impact
- Class: uninitialized memory exposure
- Surface: JS-readable bytes via
Uint8Array/DataViewafter growth - Conditions:
- resizable ArrayBuffer
transfer(newLen)wherenewLen <= oldLen- later
resize()growth
Fix Direction
Either of these fixes the invariant:
- Use
FillContents::Zeroin the transfer-shrink copy path. - Keep uninitialized allocation, but explicitly
memset(0)for
[newByteLength .. maxByteLength)before exposing the new buffer.
The key requirement is that grow-time assumptions must always remain true.
Actual results:
Memory Leak
Expected results:
Not Memory Leak
Updated•9 months ago
|
| Assignee | ||
Comment 1•9 months ago
|
||
This code path is only used for small buffers, so let's simplify it a bit.
Updated•9 months ago
|
| Assignee | ||
Comment 2•9 months ago
|
||
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
| Assignee | ||
Comment 3•9 months ago
|
||
Comment on attachment 9547198 [details]
(secure)
Security Approval Request
- How easily could an exploit be constructed based on the patch?: The affected code path can only be reached when calling the
transfermethod on resizable ArrayBuffers. This can give attackers some hints about how to start constructing an exploit. A proper exploit requires getting GC timings right, so that the uninitialised memory contains any useful data. For example the test case attached in comment #0 produces most of time0x4b = JS_SWEPT_TENURED_PATTERN, but occasionally other data. - Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: No
- Which branches (beta, release, and/or ESR) are affected by this flaw, and do the release status flags reflect this affected/unaffected state correctly?: All branches
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: Yes
- If not, how different, hard to create, and risky will they be?: Patch can be applied as-is to all affected branches.
- How likely is this patch to cause regressions; how much testing does it need?: Unlikely to cause regressions, because it only changes
createBufferAndDatato request zeroing the newly allocated data instead of leaving it uninitialised. - Is the patch ready to land after security approval is given?: Yes
- Is Android affected?: Yes
Comment 4•9 months ago
|
||
I'm flagging this as sec-moderate, but provable exploitation beyond a read of uninitialized data could convince us to reconsider the security rating. (See also: https://wiki.mozilla.org/Security_Severity_Ratings/Client)
Comment 6•9 months ago
|
||
Comment on attachment 9547198 [details]
(secure)
sec-approval+ to land now and request uplifts. Please wait to land the test (I'll set a reminder)
Updated•9 months ago
|
Comment 8•8 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined: See security approval request.
- Code covered by automated testing: yes
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: See security approval request.
- String changes made/needed: None
- Is Android affected?: yes
| Assignee | ||
Comment 9•8 months ago
|
||
This code path is only used for small buffers, so let's simplify it a bit.
Original Revision: https://phabricator.services.mozilla.com/D284448
Comment 10•8 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined: See security approval request.
- Code covered by automated testing: yes
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: See security approval request.
- String changes made/needed: None
- Is Android affected?: yes
| Assignee | ||
Comment 11•8 months ago
|
||
This code path is only used for small buffers, so let's simplify it a bit.
Original Revision: https://phabricator.services.mozilla.com/D284448
| Reporter | ||
Comment 12•8 months ago
|
||
Hello
I'm sending you the credit information because it's missing. Credit Name is : Pwn2addr
Comment 13•8 months ago
|
||
(In reply to pwn2car from comment #12)
I'm sending you the credit information because it's missing. Credit Name is : Pwn2addr
If you edit your user prefs in Bugzilla, set the "real name" field to what you want to be in the CVE reports. That is also how it will show up in Bugzilla. If you want your name changed in older CVE reports, you'll have to email security@mozilla.org
| Reporter | ||
Comment 14•8 months ago
|
||
Thanks
Comment 15•8 months ago
|
||
Updated•8 months ago
|
Updated•8 months ago
|
Comment 16•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Updated•8 months ago
|
Comment 17•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Comment 18•8 months ago
|
||
We are awarding a bounty for this bug, but the amount is split with the reporter of bug 2019402 which was filed within our collision window.
Updated•8 months ago
|
Updated•8 months ago
|
Comment 19•7 months ago
|
||
a month ago, dveditz placed a reminder on the bug using the whiteboard tag [reminder-test 2026-04-07] .
anba, please refer to the original comment to better understand the reason for the reminder.
| Assignee | ||
Updated•7 months ago
|
Updated•4 months ago
|
Comment 20•4 months ago
|
||
Updated•4 months ago
|
Comment 21•4 months ago
|
||
| bugherder | ||
Description
•