Skip to content
Memory corruption Advisory Advanced CVE-2024-5499

Out of bounds write in Streams API (CVE-2024-5499)

A use-after-free in Chrome's Streams API allows a malicious page to detach an ArrayBuffer while it is still queued for copying, leading to an out-of-bounds write during memcpy. An attacker could corrupt memory and potentially execute arbitrary code in the renderer process.

anonymous Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 20 days

VULNERABILITY DETAILS When js api ReadableByteStreamController.enqueue is called, it may go with ReadableByteStreamController::enqueue -> Enqueue -> ProcessPullIntoDescriptorsUsingQueue. In this function there is a while loop to fill pull into descriptor, if the chunk is ready, it uses Promise.Resolve to fullfill the request and return the buffer to user [1]. However, fullfill the request may trigger an user-defined js function and one can detach the buffer which already queued in the next descriptor by accessing readcontroller.byobRequest. This will result in memory corruption when executing memcpy at line[2], which has the ability to write an arbitrary value to memory range starting from 0 to maxArrayBufferLength.

void ReadableByteStreamController::ProcessPullIntoDescriptorsUsingQueue(
    ScriptState* script_state,
    ReadableByteStreamController* controller,
    ExceptionState& exception_state) {
    // skip
    if (FillPullIntoDescriptorFromQueue(controller, pull_into_descriptor)) {
      //     i. Perform !
      //     ReadableByteStreamControllerShiftPendingPullInto(controller).
      ShiftPendingPullInto(controller);
      //     ii. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(
      //     controller.[[stream]], pullIntoDescriptor).
      CommitPullIntoDescriptor(script_state,                                 // ======> [1]
                               controller->controlled_readable_stream_,
                               pull_into_descriptor, exception_state);
      DCHECK(!exception_state.HadException());
    }
  }
}

bool ReadableByteStreamController::FillPullIntoDescriptorFromQueue(
    ReadableByteStreamController* controller,
    PullIntoDescriptor* pull_into_descriptor) {
  // skip
  while (total_bytes_to_copy_remaining > 0) {
    // a. Let headOfQueue be queue[0].
    QueueEntry* head_of_queue = queue[0];
    // b. Let bytesToCopy be min(totalBytesToCopyRemaining,
    // headOfQueue’s byte length).
    size_t bytes_to_copy =
        std::min(total_bytes_to_copy_remaining, head_of_queue->byte_length);
    // c. Let destStart be pullIntoDescriptor’s byte offset +
    // pullIntoDescriptor’s bytes filled.
    // This addition will not overflow because byte offset and bytes filled
    // refer to actually allocated memory, so together they cannot exceed
    // size_t.
    size_t dest_start =
        pull_into_descriptor->byte_offset + pull_into_descriptor->bytes_filled;
    // d. Perform ! CopyDataBlockBytes(pullIntoDescriptor’s
    // buffer.[[ArrayBufferData]], destStart, headOfQueue’s
    // buffer.[[ArrayBufferData]], headOfQueue’s byte offset, bytesToCopy).
    memcpy(                                                                         // ======> [2]
        static_cast<char*>(pull_into_descriptor->buffer->Data()) + dest_start,
        static_cast<char*>(head_of_queue->buffer->Data()) +
            head_of_queue->byte_offset,
        bytes_to_copy);

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/streams/readable_byte_stream_controller.cc;l=503;drc=ffa073e3fa09b2be387adb32663a3ca9e93e61e9 [2] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/streams/readable_byte_stream_controller.cc;l=1055;drc=ffa073e3fa09b2be387adb32663a3ca9e93e61e9

VERSION Chrome Version: stable + dev

REPRODUCTION CASE Tested on: Chrome 126.0.6470.1 asan build 64-bit on Linux

  1. Setup http server python3 -m http.server
  2. Launch chrome and navigate to http://localhost:8000/poc.html out/Asan/chrome http://localhost:8000/poc.html The render would crash when accessing a specific address 0x000042424238

FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION Type of crash: renderer Crash State: see crash.log for details

== Bisection == This bug exists for a long time which was introduced in Dec, 2020 (https://chromium.googlesource.com/chromium/src/+/c85fa18ea9fd78fb9c992ac3dca9ae41d2f0a2a3)

The original report as published on the Chromium issue tracker, by anonymous. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code calls a user-defined JavaScript function (via Promise resolution) while still holding a pointer to a buffer that the user can detach, leading to a use-after-free and out-of-bounds write.

Impact

An attacker could cause memory corruption in the renderer, potentially leading to arbitrary code execution.

What the attacker needed

Victim visits a malicious webpage

How it was found

  1. Set up a local HTTP server serving the proof-of-concept page.
  2. Launch Chrome (ASAN build) and navigate to the page.
  3. The renderer crashes when accessing a specific address.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This bug is in a part of the browser that handles streaming data. When a page asks for data, the browser sometimes calls a function that the page controls. That function can free a memory buffer that the browser still plans to use, so the browser later writes into freed memory. This can crash the browser or let an attacker run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by anonymous

View all

2,270 more disclosed reports, best first.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.