Closed Bug 2018592 (CVE-2026-4716) Opened 9 months ago Closed 8 months ago

Uninitialized Tail Exposure After Resizable ArrayBuffer `transfer()`

Categories

(Core :: JavaScript Engine, defect, P1)

Firefox 150
defect

Tracking

()

RESOLVED FIXED
150 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 149+ fixed
firefox148 --- wontfix
firefox149 + fixed
firefox150 + fixed

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)

Attached file index.html —

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

  1. Create a resizable buffer:
    new ArrayBuffer(16, { maxByteLength: 80 })
  2. Transfer to a smaller/same length:
    transfer(8) or transfer(16)
  3. 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:673 ArrayBufferObject::transferImpl
  • js/src/vm/ArrayBufferObject.cpp:679 ArrayBufferCopyAndDetach(..., PreserveResizability::Yes)

Resizable branch:

  • js/src/vm/ArrayBufferObject.cpp:520
  • js/src/vm/ArrayBufferObject.cpp:532 ResizableArrayBufferObject::copyAndDetach(...)
  • js/src/vm/ArrayBufferObject.cpp:2796 ResizableArrayBufferObject::copyAndDetach
  • js/src/vm/ArrayBufferObject.cpp:2809 ResizableArrayBufferObject::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::resize does 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:1352 to js/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 / DataView after growth
  • Conditions:
    • resizable ArrayBuffer
    • transfer(newLen) where newLen <= oldLen
    • later resize() growth

Fix Direction

Either of these fixes the invariant:

  1. Use FillContents::Zero in the transfer-shrink copy path.
  2. 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

Group: firefox-core-security → javascript-core-security
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Attached file (secure) —

This code path is only used for small buffers, so let's simplify it a bit.

Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Blocks: js-lang
Severity: -- → S2
Priority: -- → P1
Keywords: regression
Regressed by: 1842773

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 transfer method 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 time 0x4b = 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 createBufferAndData to 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
Attachment #9547198 - Flags: sec-approval?

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)

Duplicate of this bug: 2019402

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)

Attachment #9547198 - Flags: sec-approval? → sec-approval+

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
Attachment #9548946 - Flags: approval-mozilla-esr140?
Attached file (secure) —

This code path is only used for small buffers, so let's simplify it a bit.

Original Revision: https://phabricator.services.mozilla.com/D284448

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
Attachment #9548947 - Flags: approval-mozilla-beta?
Attached file (secure) —

This code path is only used for small buffers, so let's simplify it a bit.

Original Revision: https://phabricator.services.mozilla.com/D284448

Hello

I'm sending you the credit information because it's missing. Credit Name is : Pwn2addr

(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

Thanks

Group: javascript-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → 150 Branch
Attachment #9548947 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9548946 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
QA Whiteboard: [sec] [uplift] [qa-triage-done-c150/b149]

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.

Flags: sec-bounty+
Whiteboard: [reminder-test 2026-04-07] → [reminder-test 2026-04-07][adv-main149+][adv-ESR140.9+]
Alias: CVE-2026-4716

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.

Flags: needinfo?(andrebargull)
Whiteboard: [reminder-test 2026-04-07][adv-main149+][adv-ESR140.9+] → [adv-main149+][adv-ESR140.9+]
Flags: needinfo?(andrebargull)
Group: core-security-release
Attachment #9547199 - Attachment description: (secure) → Bug 2018592: Add test case. r=jandem!
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: