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

Use after free in QUIC (CVE-2024-3837)

A use-after-free existed in Chromium's QUIC client session handling, where a StreamRequest object could be destroyed while a callback bound to it was still queued for later execution. An attacker who could influence the freed callback memory could potentially achieve arbitrary code execution, though the report notes the race is hard to trigger.

{rotiple Follow

Originally disclosed on Chrome VRP

Bounty$7,000 Medium View original
  • Fix shipped in 3 months

Tested Version

• 121.0.6140.0 (Developer Build) • mac-release-asan-mac-release-1227262 from storage bucket • macOS 14.2 (23C5055b)

Attachments

• Apple MacOS Crash Report: 1-apple-macos-crash-report.log • Chromium ASAN Report: 2-chromium-asan-report.log • Proof of Concept: 3-proof-of-concept.html

Reproduction Steps

#1 - Open proof-of-concept.html. #2 - Wait for approximately 2 to 3 seconds. #3 - Close the tab.

※ While setTimeout(() => window.close(), 2500); can be employed for step #3, manually closing the window tends to reproduce better. ※ It is hard to trigger the bug as it requires tightly timed race condition.

AddressSanitizer Report

==24101==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000588b30 at pc 0x00016cac4946 bp 0x000308b053f0 sp 0x000308b053e8
READ of size 8 at 0x608000588b30 thread T6
    #0 0x16cac4945 in net::QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(int)+0x3e5 (/Users/dch3ck/Desktop/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e5f945)
    #1 0x16cac9ded in net::QuicChromiumClientSession::~QuicChromiumClientSession()+0xb9d (/Users/dch3ck/Desktop/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e64ded)
  ...  [ For the complete details, please refer to the chromium-asan-report.log file. ]

Description

The net::QuicChromiumClientSession::Handle::RequestStream function creates a StreamRequest object that is susceptible to a use-after-free condition. This occurs when an 8-byte pointer, which has been previously freed, is reused in the OnRequestCompleteFailure method, potentially leading to the execution of a callback function. If an attacker manipulates the callback_ object, it could be exploited to execute arbitrary code.

The UAF appears to stem from improper lifecycle management of a callback_. This callback is scheduled for execution in the OnRequestCompleteFailure function.

The nature of posting tasks for delayed execution base::SingleThreadTaskRunner::PostTask means that the callback might be executed at a time when the object it belongs to StreamRequest might already have been destroyed.

Evidence

Stack trace pointing to OnRequestCompleteFailure. The use of base::BindOnce with callback_ for delayed execution.

Allocation

previously allocated by thread T6 here:
    #0 0x109e12900 in __asan_memmove+0x2d30 (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Helpers/Chromium Helper.app/Contents/MacOS/libclang_rt.asan_osx_dynamic.dylib:x86_64+0x52900)
    #1 0x16aa1b8f7 in operator new(unsigned long)+0x27 (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x10db68f7)
    #2 0x16cac0a4b in net::QuicChromiumClientSession::Handle::RequestStream(bool, base::OnceCallback<void (int)>, net::NetworkTrafficAnnotationTag const&)+0x20b (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e5ba4b)
    #3 0x16cb2e95f in net::QuicHttpStream::DoRequestStream()+0x3af (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12ec995f)
    #4 0x16cb289db in net::QuicHttpStream::DoLoop(int)+0x43b (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12ec39db)
    ...

At #4 0x16cb289d, DoRequestStream() is called and the resulting integer value is stored in rv.

// chromium/src/net/quic/quic_http_stream.cc

int QuicHttpStream::DoLoop(int rv) {
  // ... [Snipped for brevity] ...
  do {
    // ... [State machine logic snipped for brevity] ...
        rv = DoRequestStream();
        break;
    // ... [Rest of the state machine logic snipped for brevity] ...
  } while (rv is not pending and states are still transitioning);
  return rv;
}

At #3 0x16cb2e95f, RequestStream() is invoked.

// chromium/src/net/quic/quic_http_stream.cc

int QuicHttpStream::DoRequestStream() {
  next_state_ = STATE_REQUEST_STREAM_COMPLETE; // Set next state

  return quic_session()->RequestStream(
      !can_send_early_, // Flag indicating if 0-RTT data can be sent
      base::BindOnce(&QuicHttpStream::OnIOComplete, weak_factory_.GetWeakPtr()), // Binding completion callback
      NetworkTrafficAnnotationTag(request_info_->traffic_annotation)); // Network traffic analysis tag
}

The memory for the QuicChromiumClientSession::Handle is allocated using operator new(unsigned long).

The RequestStream method is called within net::QuicHttpStream::DoRequestStream, which subsequently calls DoLoop that processes the request loop and handles the state transitions.

// chromium/src/net/quic/quic_chromium_client_session.cc

int QuicChromiumClientSession::Handle::RequestStream(
    bool requires_confirmation,
    CompletionOnceCallback callback,
    const NetworkTrafficAnnotationTag& traffic_annotation) {
  DCHECK(!stream_request_);

  if (!session_)
    return ERR_CONNECTION_CLOSED;

  // ... [Logic to confirm the connection before starting the stream if 0-RTT is disabled] ...

  // Instantiate a new StreamRequest object
  stream_request_ = base::WrapUnique(
      new StreamRequest(this, requires_confirmation, traffic_annotation)); // Memory allocation here
  return stream_request_->StartRequest(std::move(callback));
}

An object of type StreamRequest is created and assigned to the stream_request_ variable, allocating 0x58 bytes of memory, as shown in the snippet where edi is set to 0x58 just before calling the new operator (denoted by _Znwm):

0x00005596e5aaca98 <+216>:   mov    a1,BYTE PTR [rbp-0x19]
0x00005596e5aaca9b <+219>:   and    al,0x1
0x00005596e5aaca9d <+221>:   movzx  eax,al
0x00005596e5aaca0 <+224>:    or     eax,ecx
0x00005596e5aaca2 <+226>:    cmp    eax,0x0
0x00005596e5aaca5 <+229>:    setne  al
0x00005596e5aaca8 <+232>:    and    al,0x1
0x00005596e5aacaa <+234>:    mov    BYTE PTR [rbp-0x19],al
=> 0x00005596e5aacad <+237>:   mov    edi,0x58
0x00005596e5aacab2 <+242>:    call   0x5596e637f6d0 <_Znwm>
0x00005596e5aacab7 <+247>:    mov    rsi,QWORD PTR [rbp-0x78]
0x00005596e5aacabb <+251>:    mov    rdi,rax
0x00005596e5aacabe <+254>:    mov    QWORD PTR [rbp-0x88],rdi
0x00005596e5aacac5 <+261>:    mov    al,BYTE PTR [rbp-0x19]
0x00005596e5aacac8 <+264>:    mov    rcx,QWORD PTR [rbp-0x28]
gef➤  x/88wx 0x00003700000a5260

0x3700000a5260: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5270: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5280: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5290: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a52a0: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a52b0: 0xabababab                        0xabababab                        0xefbeadde                        0x0dd0feca
0x3700000a52c0: 0x05f03713                        0x1eab11ba                        0x00000000                        0x00000000

This snippet is from the disassembly of the RequestStream function where a new StreamRequest object is being created

0x5596e5aacac8 <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)0> mov rcx, QWORD PTR [rbp-0x28]
0x5596e5aacacc <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)4> and al, 0x1
0x5596e5aacace <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)6> movzx edx, al
0x5596e5aacad1 <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)9> call 0x5596e5aad1b0 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> push rbp
0x5596e5aad1b0 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov rbp, rsp
0x5596e5aad1b1 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> sub rsp, 0x30
0x5596e5aad1b4 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov al, dl
0x5596e5aad1b8 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov QWORD PTR [rbp-0x8], rdi
0x5596e5aad1ba <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov QWORD PTR [rbp-0x10], rsi

_ZN3net25QuicChromiumClientSession13StreamRequestC2EPNS0_6HandleEbRKNS_27NetworkTrafficAnnotationTagE (
QWORD var_0 = 0x000037e0000a5260 -> 0xabababababababab,
QWORD var_1 = 0x000037000064820 -> 0x00005596e573acc8 -> 0x00005596e5aac380 -> net::QuicChromiumClientSession::Handle::Handle()+0> push rbp,
bool var_2 = 0x0000000000000000,
QWORD var_3 = 0x00007ffccf6b074c -> 0x00007ffccf6b4492
)

In the newly allocated memory space, a pointer to QuicChromiumClientSession::Handle is stored. This is done by initializing a base::raw_ptr to point to an instance of QuicChromiumClientSession::Handle.

gef➤ ni
Thread 1 "net_unittests" hit Hardware watchpoint 4: *0x000037e0000a5260

Old value = 0xabababab
New value = 0x64820
0x00005596e5ac2a88 in base::raw_ptr<net::QuicChromiumClientSession::Handle, (partition_alloc::internal::RawPtrTraits)>::raw_ptr (this=0x37e0000a5260, p=0x37e000064820) at ../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr.h:460
460     : wrapped_ptr_(Impl::WrapRawPtr(p)) {}

gef➤ x/88wx 0x000037e0000a5260
0x37e0000a5260: 0x000064820   0xabababab  0xabababab  0xabababab
0x37e0000a5270: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a5280: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a5290: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a52a0: 0xabababab   0xabababab  0xfebdeadde 0xddd0feca
0x37e0000a52b0: 0xabababab   0x1eab11ba  0x00000000  0x00000000
0x37e0000a52c0: 0x05f03713   0xeab11ba   0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52d0: 0xcd037e000 0x8d051a00  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52e0: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52f0: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5300: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5310: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5320: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5330: 0xcdcdcdcd   0x00000001  0x00000000  0x00000000
0x37e0000a5340: 0x000646d00  0x000037e00  0xababab00  0x00000000
0x37e0000a5350: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5360: 0x00000001   0x00000000  0xababab00  0x00000000
0x37e0000a5370: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5380: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5390: 0x00000000   0xabababab  0xeab11ba   0x00000000

Free

// chromium/src/net/quic/quic_chromium_client_session.cc
QuicChromiumClientSession::Handle::~Handle() {
  if (session_)
    session_->RemoveHandle(this);
}

void QuicChromiumClientSession::RemoveHandle(Handle* handle) {
  DCHECK(base::Contains(handles_, handle));
  handles_.erase(handle);
}

Use

The stack trace entry #0 0x16cac4945 points to the OnRequestCompleteFailure function within QuicChromiumClientSession. The corresponding source code snippet suggests that if the callback_ member variable is not null, it schedules a callback for later execution. A UAF could occur if callback_ is referencing memory that has been freed prior to the callback's execution.

// chromium/src/net/quic/quic_chromium_client_session.cc
void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(
    int rv) {
  //DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_);
  // This method is called even when the request completes synchronously.
  if (callback_) {
    // Avoid re-entrancy if the callback calls into the session.
    base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
        FROM_HERE,
        base::BindOnce(&QuicChromiumClientSession::StreamRequest::DoCallback,
                       weak_factory_.GetWeakPtr(), rv));
  }
}

Credit

{rotiple, dch3ck} of CW Research Inc.

The original report as published on the Chromium issue tracker, by {rotiple, dch3ck} of CW Research Inc.. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

This is a use-after-free (UAF) in Chromium's QUIC client stack, tracked as CVE-2024-3837 and reported through the Chrome VRP. The affected component is net::QuicChromiumClientSession, the object that owns a QUIC session on the network side and hands out stream handles to the HTTP layer. When the HTTP layer wants a new QUIC stream it calls net::QuicChromiumClientSession::Handle::RequestStream, which creates a StreamRequest object to track the asynchronous stream request and its completion callback. The bug is in the lifecycle of that StreamRequest and of the callback_ it holds: the callback can be posted for later execution and then run after the object it belongs to has already been destroyed.

The report is an advisory-style write-up with a proof of concept, an Apple macOS crash report, a Chromium ASAN report and a short description of the faulty code path. The researcher is credited as {rotiple, dch3ck} of CW Research Inc. The severity is medium and the bounty was 7000.00 USD. Disclosure was on 2024-04-16.

Setup

The bug was reproduced on a developer build of Chrome, not on a release channel:

  • 121.0.6140.0 (Developer Build)
  • mac-release-asan-mac-release-1227262 from storage bucket
  • macOS 14.2 (23C5055b)

The build is an AddressSanitizer build, which is what turns the stale pointer access into a deterministic report rather than silent corruption. The report attaches three files:

  • Apple MacOS Crash Report: 1-apple-macos-crash-report.log
  • Chromium ASAN Report: 2-chromium-asan-report.log
  • Proof of Concept: 3-proof-of-concept.html

No account, role or special server configuration is described. The precondition is simply that the browser loads the proof of concept over QUIC and that the tab is closed at the right moment.

Finding it

The report states that net::QuicChromiumClientSession::Handle::RequestStream creates a StreamRequest object that is susceptible to a use-after-free. The ASAN report shows a heap-use-after-free read of size 8 in net::QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(int), reached from the destructor of QuicChromiumClientSession:

Text
==24101==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000588b30 at pc 0x00016cac4946 bp 0x000308b053f0 sp 0x000308b053e8
READ of size 8 at 0x608000588b30 thread T6
    #0 0x16cac4945 in net::QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(int)+0x3e5 (/Users/dch3ck/Desktop/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e5f945)
    #1 0x16cac9ded in net::QuicChromiumClientSession::~QuicChromiumClientSession()+0xb9d (/Users/dch3ck/Desktop/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e64ded)
  ...  [ For the complete details, please refer to the chromium-asan-report.log file. ]

The read happens while the session is being torn down: the use stack is reached from the destructor of QuicChromiumClientSession. The report notes that the freed 8-byte pointer is reused in OnRequestCompleteFailure, and that this can lead to the execution of a callback function. If an attacker can manipulate the callback_ object, the report says, it could be exploited to execute arbitrary code.

Exploitation

The proof of concept is a timing race. The report gives three reproduction steps.

Step 1: open the proof of concept

Open proof-of-concept.html in the ASAN developer build.

Step 2: wait for approximately 2 to 3 seconds

Wait for approximately 2 to 3 seconds. The report does not describe what the page does during this window beyond the timing.

Step 3: close the tab

Close the tab. The report notes that setTimeout(() => window.close(), 2500); can be used to automate this step, but that manually closing the window tends to reproduce better. It also warns that the bug is hard to trigger because it requires a tightly timed race condition.

Closing the tab tears down the session, and the posted callback may then run at a time when the StreamRequest it belongs to has already been destroyed.

Root cause

The report traces the object from allocation to free to use.

Allocation

The ASAN allocation stack shows the StreamRequest being created inside RequestStream:

Text
previously allocated by thread T6 here:
    #0 0x109e12900 in __asan_memmove+0x2d30 (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Helpers/Chromium Helper.app/Contents/MacOS/libclang_rt.asan_osx_dynamic.dylib:x86_64+0x52900)
    #1 0x16aa1b8f7 in operator new(unsigned long)+0x27 (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x10db68f7)
    #2 0x16cac0a4b in net::QuicChromiumClientSession::Handle::RequestStream(bool, base::OnceCallback<void (int)>, net::NetworkTrafficAnnotationTag const&)+0x20b (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e5ba4b)
    #3 0x16cb2e95f in net::QuicHttpStream::DoRequestStream()+0x3af (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12ec995f)
    #4 0x16cb289db in net::QuicHttpStream::DoLoop(int)+0x43b (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12ec39db)
    ...

The report explains that at #4 0x16cb289d, DoRequestStream() is called and the resulting integer value is stored in rv:

Text
// chromium/src/net/quic/quic_http_stream.cc

int QuicHttpStream::DoLoop(int rv) {
  // ... [Snipped for brevity] ...
  do {
    // ... [State machine logic snipped for brevity] ...
        rv = DoRequestStream();
        break;
    // ... [Rest of the state machine logic snipped for brevity] ...
  } while (rv is not pending and states are still transitioning);
  return rv;
}

At #3 0x16cb2e95f, RequestStream() is invoked:

Text
// chromium/src/net/quic/quic_http_stream.cc

int QuicHttpStream::DoRequestStream() {
  next_state_ = STATE_REQUEST_STREAM_COMPLETE; // Set next state

  return quic_session()->RequestStream(
      !can_send_early_, // Flag indicating if 0-RTT data can be sent
      base::BindOnce(&QuicHttpStream::OnIOComplete, weak_factory_.GetWeakPtr()), // Binding completion callback
      NetworkTrafficAnnotationTag(request_info_->traffic_annotation)); // Network traffic analysis tag
}

The memory for the StreamRequest is allocated using operator new(unsigned long). RequestStream is called from net::QuicHttpStream::DoRequestStream, which subsequently calls DoLoop to process the request loop and handle state transitions:

Text
// chromium/src/net/quic/quic_chromium_client_session.cc

int QuicChromiumClientSession::Handle::RequestStream(
    bool requires_confirmation,
    CompletionOnceCallback callback,
    const NetworkTrafficAnnotationTag& traffic_annotation) {
  DCHECK(!stream_request_);

  if (!session_)
    return ERR_CONNECTION_CLOSED;

  // ... [Logic to confirm the connection before starting the stream if 0-RTT is disabled] ...

  // Instantiate a new StreamRequest object
  stream_request_ = base::WrapUnique(
      new StreamRequest(this, requires_confirmation, traffic_annotation)); // Memory allocation here
  return stream_request_->StartRequest(std::move(callback));
}

The StreamRequest is assigned to stream_request_, allocating 0x58 bytes. The report shows the disassembly where edi is set to 0x58 just before the call to new (_Znwm):

Text
0x00005596e5aaca98 <+216>:   mov    a1,BYTE PTR [rbp-0x19]
0x00005596e5aaca9b <+219>:   and    al,0x1
0x00005596e5aaca9d <+221>:   movzx  eax,al
0x00005596e5aaca0 <+224>:    or     eax,ecx
0x00005596e5aaca2 <+226>:    cmp    eax,0x0
0x00005596e5aaca5 <+229>:    setne  al
0x00005596e5aaca8 <+232>:    and    al,0x1
0x00005596e5aacaa <+234>:    mov    BYTE PTR [rbp-0x19],al
=> 0x00005596e5aacad <+237>:   mov    edi,0x58
0x00005596e5aacab2 <+242>:    call   0x5596e637f6d0 <_Znwm>
0x00005596e5aacab7 <+247>:    mov    rsi,QWORD PTR [rbp-0x78]
0x00005596e5aacabb <+251>:    mov    rdi,rax
0x00005596e5aacabe <+254>:    mov    QWORD PTR [rbp-0x88],rdi
0x00005596e5aacac5 <+261>:    mov    al,BYTE PTR [rbp-0x19]
0x00005596e5aacac8 <+264>:    mov    rcx,QWORD PTR [rbp-0x28]

The report then shows a memory dump and, after the watchpoint fires, the same region with the Handle pointer written into it. First the uninitialised region:

Text
gef➤  x/88wx 0x00003700000a5260

0x3700000a5260: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5270: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5280: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5290: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a52a0: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a52b0: 0xabababab                        0xabababab                        0xefbeadde                        0x0dd0feca
0x3700000a52c0: 0x05f03713                        0x1eab11ba                        0x00000000                        0x00000000

The report says this snippet is from the disassembly of RequestStream where the new StreamRequest is created:

Text
0x5596e5aacac8 <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)0> mov rcx, QWORD PTR [rbp-0x28]
0x5596e5aacacc <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)4> and al, 0x1
0x5596e5aacace <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)6> movzx edx, al
0x5596e5aacad1 <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)9> call 0x5596e5aad1b0 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> push rbp
0x5596e5aad1b0 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov rbp, rsp
0x5596e5aad1b1 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> sub rsp, 0x30
0x5596e5aad1b4 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov al, dl
0x5596e5aad1b8 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov QWORD PTR [rbp-0x8], rdi
0x5596e5aad1ba <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov QWORD PTR [rbp-0x10], rsi

[redacted] (
QWORD var_0 = 0x000037e0000a5260 -> 0xabababababababab,
QWORD var_1 = 0x000037000064820 -> 0x00005596e573acc8 -> 0x00005596e5aac380 -> net::QuicChromiumClientSession::Handle::Handle()+0> push rbp,
bool var_2 = 0x0000000000000000,
QWORD var_3 = 0x00007ffccf6b074c -> 0x00007ffccf6b4492
)

In the newly allocated memory, a pointer to QuicChromiumClientSession::Handle is stored by initialising a base::raw_ptr to point at the handle. The report shows the watchpoint firing on that write:

Text
gef➤ ni
Thread 1 "net_unittests" hit Hardware watchpoint 4: *0x000037e0000a5260

Old value = 0xabababab
New value = 0x64820
0x00005596e5ac2a88 in base::raw_ptr<net::QuicChromiumClientSession::Handle, (partition_alloc::internal::RawPtrTraits)>::raw_ptr (this=0x37e0000a5260, p=0x37e000064820) at ../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr.h:460
460     : wrapped_ptr_(Impl::WrapRawPtr(p)) {}

gef➤ x/88wx 0x000037e0000a5260
0x37e0000a5260: 0x000064820   0xabababab  0xabababab  0xabababab
0x37e0000a5270: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a5280: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a5290: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a52a0: 0xabababab   0xabababab  0xfebdeadde 0xddd0feca
0x37e0000a52b0: 0xabababab   0x1eab11ba  0x00000000  0x00000000
0x37e0000a52c0: 0x05f03713   0xeab11ba   0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52d0: 0xcd037e000 0x8d051a00  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52e0: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52f0: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5300: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5310: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5320: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5330: 0xcdcdcdcd   0x00000001  0x00000000  0x00000000
0x37e0000a5340: 0x000646d00  0x000037e00  0xababab00  0x00000000
0x37e0000a5350: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5360: 0x00000001   0x00000000  0xababab00  0x00000000
0x37e0000a5370: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5380: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5390: 0x00000000   0xabababab   0xeab11ba   0x00000000

Free

The report shows the destructor of the handle and the session's RemoveHandle:

Text
// chromium/src/net/quic/quic_chromium_client_session.cc
QuicChromiumClientSession::Handle::~Handle() {
  if (session_)
    session_->RemoveHandle(this);
}

void QuicChromiumClientSession::RemoveHandle(Handle* handle) {
  DCHECK(base::Contains(handles_, handle));
  handles_.erase(handle);
}

Use

The stack trace entry #0 0x16cac4945 points to OnRequestCompleteFailure inside QuicChromiumClientSession. The report says the source suggests that if the callback_ member is not null, a callback is scheduled for later execution, and a UAF can occur if callback_ references memory that has been freed before the callback runs:

Text
// chromium/src/net/quic/quic_chromium_client_session.cc
void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(
    int rv) {
  //DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_);
  // This method is called even when the request completes synchronously.
  if (callback_) {
    // Avoid re-entrancy if the callback calls into the session.
    base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
        FROM_HERE,
        base::BindOnce(&QuicChromiumClientSession::StreamRequest::DoCallback,
                       weak_factory_.GetWeakPtr(), rv));
  }
}

The report says the UAF appears to stem from improper lifecycle management of callback_. The callback is scheduled for execution in OnRequestCompleteFailure, and because base::SingleThreadTaskRunner::PostTask posts a task for delayed execution, the callback may run at a time when the StreamRequest it belongs to has already been destroyed. The evidence cited is the stack trace pointing at OnRequestCompleteFailure and the use of base::BindOnce with callback_ for delayed execution.

Impact

The report describes a use-after-free in which an 8-byte pointer that has been previously freed is reused in OnRequestCompleteFailure, potentially leading to the execution of a callback function. If an attacker manipulates the callback_ object, the report says, it could be exploited to execute arbitrary code. The practical conditions are narrow: the bug requires a tightly timed race condition, and the report notes that it is hard to trigger. The severity assigned is medium.

Fix

The report does not describe the patch. It identifies the faulty lifecycle management of callback_ and the delayed PostTask as the source of the problem, which is where a fix would have to ensure the posted task cannot outlive the StreamRequest it references.

Variants to test

  • Look for other PostTask plus base::BindOnce pairs in asynchronous network code where the bound object can be destroyed before the task runs. A positive result is an ASAN heap-use-after-free report whose free stack is a destructor and whose use stack is the posted callback.
  • Exercise tab close and navigation during in-flight QUIC stream requests. A positive result is a crash or ASAN report during session teardown, as in the ~QuicChromiumClientSession frame here.
  • Check other Handle-style objects that register themselves with an owner and are removed in their destructor. A positive result is a callback or task that still references the removed handle after RemoveHandle has run.
  • Test the same pattern in other protocol clients that post completion callbacks to a task runner. A positive result is a use-after-free when the owning session is torn down between the post and the run.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 23 min read.

What happened, in plain words

Chrome has a feature that lets it talk to websites over a newer, faster network protocol called QUIC. Inside Chrome, a piece of code called net::QuicChromiumClientSession manages one of these QUIC conversations. When the part of Chrome that fetches web pages (the HTTP layer) wants to send a request over QUIC, it asks this session manager for a "stream", which is like a lane on a motorway dedicated to one request.

To keep track of that request while it is in progress, the session manager creates a small object called a StreamRequest. Think of it as a sticky note that says "this request is still running, and here is the phone number to call when it finishes". That phone number is a callback: a piece of code that should run later, when the request completes.

The problem is that the callback can be put on a to-do list to run a little later, and by the time it runs, the sticky note it belongs to may already have been thrown away. When the code then tries to read the phone number from the discarded note, it is reading memory that has already been freed and possibly reused for something else. This kind of bug is called a use-after-free: using something after you have given it back.

If an attacker can control what ends up in that reused memory, they might be able to make Chrome run code of their choosing. The report rates this as medium severity, credits the researchers as {rotiple, dch3ck} of CW Research Inc. and notes a bounty of 7000.00 USD. It was disclosed on 2024-04-16 under the identifier CVE-2024-3837.

The setup

The bug was reproduced on a special developer build of Chrome, not on the normal version people download:

  • 121.0.6140.0 (Developer Build)
  • mac-release-asan-mac-release-1227262 from storage bucket
  • macOS 14.2 (23C5055b)

That build includes a tool called AddressSanitizer, usually shortened to ASAN. ASAN is a debugging aid built into the program that watches memory closely. When a program touches memory it should not, ASAN stops it and prints a detailed report instead of letting the program carry on with corrupted data. It is like a smoke alarm for memory mistakes: without it, a small error might go unnoticed; with it, you get a loud, precise alarm.

The report attaches three files:

  • Apple MacOS Crash Report: 1-apple-macos-crash-report.log
  • Chromium ASAN Report: 2-chromium-asan-report.log
  • Proof of Concept: 3-proof-of-concept.html

A proof of concept, or PoC, is a small, deliberately harmless demonstration that triggers the bug. It is the difference between saying "this door might be unlocked" and actually opening it to show someone.

No account, role or special server setup is described. The only precondition is that the browser loads the proof of concept over QUIC and that the tab is closed at the right moment.

Finding it

The report states that when net::QuicChromiumClientSession::Handle::RequestStream creates a StreamRequest, the object is susceptible to a use-after-free. In other words, the sticky note can be thrown away while its callback is still waiting on the to-do list.

The ASAN report shows a heap-use-after-free read of size 8 in net::QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(int), reached from the destructor of QuicChromiumClientSession:

Text
==24101==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000588b30 at pc 0x00016cac4946 bp 0x000308b053f0 sp 0x000308b053e8
READ of size 8 at 0x608000588b30 thread T6
    #0 0x16cac4945 in net::QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(int)+0x3e5 (/Users/dch3ck/Desktop/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e5f945)
    #1 0x16cac9ded in net::QuicChromiumClientSession::~QuicChromiumClientSession()+0xb9d (/Users/dch3ck/Desktop/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e64ded)
  ...  [ For the complete details, please refer to the chromium-asan-report.log file. ]

Line by line:

  • The first line is ASAN announcing that it caught a use-after-free at a particular memory address, with the program counter (pc), base pointer (bp) and stack pointer (sp) recorded at the moment of the fault.
  • READ of size 8 means the program tried to read 8 bytes, which on a 64-bit system is the size of a pointer, an address in memory. thread T6 says which thread did it.
  • #0 is the innermost function where the bad read happened: OnRequestCompleteFailure, the function that handles a failed stream request.
  • #1 is the function that called it: the destructor ~QuicChromiumClientSession, which is the code that runs when the session object is being cleaned up.
  • The long paths in brackets are just where the code lives on the researcher's machine.

The read happens while the session is being torn down: the use stack is reached from the destructor of QuicChromiumClientSession. The report notes that the freed 8-byte pointer is reused in OnRequestCompleteFailure, and that this can lead to the execution of a callback function. If an attacker can manipulate the callback_ object, the report says, it could be exploited to execute arbitrary code.

Exploitation

The proof of concept is a timing race. A race condition is what happens when two things are supposed to happen in a certain order, but the program does not enforce that order. It is like two people reaching for the same door handle at the same moment: usually one gets there first, but occasionally the other does, and the result depends on split-second timing. Here, the two competing events are the queued callback and the teardown of the session.

The report gives three reproduction steps.

Step 1: open the proof of concept

Open proof-of-concept.html in the ASAN developer build.

Step 2: wait for approximately 2 to 3 seconds

Wait for approximately 2 to 3 seconds. The report does not describe what the page does during this window beyond the timing.

Step 3: close the tab

Close the tab. The report notes that setTimeout(() => window.close(), 2500); can be used to automate this step, but that manually closing the window tends to reproduce better. It also warns that the bug is hard to trigger because it requires a tightly timed race condition.

That line of JavaScript, in plain words: setTimeout asks the browser to run a function after a delay, given in milliseconds. The function here is () => window.close(), an arrow function that closes the current window. 2500 means 2500 milliseconds, or two and a half seconds. So the line says "close this window after two and a half seconds". The report still recommends closing it by hand, because human timing happened to hit the race more reliably.

Closing the tab tears down the session, and the posted callback may then run at a time when the StreamRequest it belongs to has already been destroyed.

Root cause

The report traces the object from allocation to free to use. Allocation means reserving memory for an object, free means giving that memory back, and use means reading or writing it. A use-after-free is exactly what it sounds like: a use that happens after the free.

Allocation

The ASAN allocation stack shows the StreamRequest being created inside RequestStream:

Text
previously allocated by thread T6 here:
    #0 0x109e12900 in __asan_memmove+0x2d30 (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Helpers/Chromium Helper.app/Contents/MacOS/libclang_rt.asan_osx_dynamic.dylib:x86_64+0x52900)
    #1 0x16aa1b8f7 in operator new(unsigned long)+0x27 (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x10db68f7)
    #2 0x16cac0a4b in net::QuicChromiumClientSession::Handle::RequestStream(bool, base::OnceCallback<void (int)>, net::NetworkTrafficAnnotationTag const&)+0x20b (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12e5ba4b)
    #3 0x16cb2e95f in net::QuicHttpStream::DoRequestStream()+0x3af (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12ec995f)
    #4 0x16cb289db in net::QuicHttpStream::DoLoop(int)+0x43b (/path/to/mac-release-asan-mac-release-1227262/Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/121.0.6140.0/Chromium Framework:x86_64+0x12ec39db)
    ...

This is the other half of the ASAN story. When ASAN catches a use-after-free, it also tells you where the memory was originally handed out, so you can see the whole life of the object. Reading from the bottom up:

  • #4 is DoLoop, a loop that steps through the stages of making a request.
  • #3 is DoRequestStream, the stage that asks for a stream.
  • #2 is RequestStream, which creates the StreamRequest.
  • #1 is operator new, the C++ function that reserves memory for a new object.
  • #0 is an ASAN internal function that appears in the trace.

The report explains that at #4 0x16cb289d, DoRequestStream() is called and the resulting integer value is stored in rv:

Text
// chromium/src/net/quic/quic_http_stream.cc

int QuicHttpStream::DoLoop(int rv) {
  // ... [Snipped for brevity] ...
  do {
    // ... [State machine logic snipped for brevity] ...
        rv = DoRequestStream();
        break;
    // ... [Rest of the state machine logic snipped for brevity] ...
  } while (rv is not pending and states are still transitioning);
  return rv;
}

Line by line:

  • int QuicHttpStream::DoLoop(int rv) declares a function that takes an integer rv and returns an integer. rv is short for return value, the result code of the previous step.
  • The do { ... } while (...) construct is a loop that runs its body at least once and then checks a condition to decide whether to repeat.
  • rv = DoRequestStream(); calls the next stage and stores its result code in rv.
  • break; leaves the loop after that call.
  • The while condition, as written in the report, keeps looping while the result is not pending and the states are still transitioning. A state machine is a way of writing code as a set of named stages, where each stage decides which stage comes next; this loop is the engine that moves from one stage to the next.
  • return rv; hands the final result code back to the caller.

At #3 0x16cb2e95f, RequestStream() is invoked:

Text
// chromium/src/net/quic/quic_http_stream.cc

int QuicHttpStream::DoRequestStream() {
  next_state_ = STATE_REQUEST_STREAM_COMPLETE; // Set next state

  return quic_session()->RequestStream(
      !can_send_early_, // Flag indicating if 0-RTT data can be sent
      base::BindOnce(&QuicHttpStream::OnIOComplete, weak_factory_.GetWeakPtr()), // Binding completion callback
      NetworkTrafficAnnotationTag(request_info_->traffic_annotation)); // Network traffic analysis tag
}

Line by line:

  • next_state_ = STATE_REQUEST_STREAM_COMPLETE; records which stage the state machine should move to next, namely the one that handles the completion of the stream request.
  • quic_session()->RequestStream(...) asks the QUIC session for a stream, passing three arguments.
  • !can_send_early_ is a true or false flag. The comment says it indicates whether 0-RTT data can be sent. 0-RTT means sending data on the very first message of a connection, before the secure handshake has fully finished, which saves a round trip but has weaker guarantees; the exclamation mark flips the flag, so this argument says whether confirmation is required before sending.
  • base::BindOnce(&QuicHttpStream::OnIOComplete, weak_factory_.GetWeakPtr()) builds the callback that should run when the request finishes. base::BindOnce is a Chrome helper that packages a function together with the arguments it will be called with, producing a callback that can be run exactly once. The function is OnIOComplete, and the extra argument is a weak pointer to the current object. A weak pointer is a reference that does not keep the object alive and knows when the object has gone away, so the callback can notice that and do nothing instead of touching freed memory.
  • NetworkTrafficAnnotationTag(request_info_->traffic_annotation) attaches a label describing what kind of network traffic this is, used for Chrome's internal traffic accounting.

The memory for the StreamRequest is allocated using operator new(unsigned long). RequestStream is called from net::QuicHttpStream::DoRequestStream, which subsequently calls DoLoop to process the request loop and handle state transitions:

Text
// chromium/src/net/quic/quic_chromium_client_session.cc

int QuicChromiumClientSession::Handle::RequestStream(
    bool requires_confirmation,
    CompletionOnceCallback callback,
    const NetworkTrafficAnnotationTag& traffic_annotation) {
  DCHECK(!stream_request_);

  if (!session_)
    return ERR_CONNECTION_CLOSED;

  // ... [Logic to confirm the connection before starting the stream if 0-RTT is disabled] ...

  // Instantiate a new StreamRequest object
  stream_request_ = base::WrapUnique(
      new StreamRequest(this, requires_confirmation, traffic_annotation)); // Memory allocation here
  return stream_request_->StartRequest(std::move(callback));
}

Line by line:

  • The function signature takes three things: requires_confirmation, a true or false flag saying whether the connection must be confirmed first; callback, the function to run when the request completes; and traffic_annotation, the traffic label.
  • DCHECK(!stream_request_); is a debug-only assertion that there is no stream request already in progress. DCHECK checks a condition and complains only in debug builds, so it catches programmer mistakes during development without slowing down normal users.
  • if (!session_) return ERR_CONNECTION_CLOSED; checks whether the session still exists. If it does not, it returns an error code meaning the connection is closed, rather than carrying on with nothing to talk to.
  • The snipped comment describes logic that confirms the connection before starting the stream when 0-RTT is disabled.
  • stream_request_ = base::WrapUnique(new StreamRequest(this, requires_confirmation, traffic_annotation)); is the allocation. new StreamRequest(...) reserves memory for a new StreamRequest and runs its constructor, passing this (a pointer to the handle), the confirmation flag and the traffic label. base::WrapUnique wraps the raw pointer in a smart pointer, an object that automatically frees the memory when it is no longer needed, so the programmer does not have to remember to do it by hand.
  • return stream_request_->StartRequest(std::move(callback)); starts the request and hands the callback over. std::move says the callback is being given away, so the original variable no longer owns it.

The StreamRequest is assigned to stream_request_, allocating 0x58 bytes. 0x58 is hexadecimal for 88, so the object takes 88 bytes of memory. The report shows the disassembly where edi is set to 0x58 just before the call to new (_Znwm):

Text
0x00005596e5aaca98 <+216>:   mov    a1,BYTE PTR [rbp-0x19]
0x00005596e5aaca9b <+219>:   and    al,0x1
0x00005596e5aaca9d <+221>:   movzx  eax,al
0x00005596e5aaca0 <+224>:    or     eax,ecx
0x00005596e5aaca2 <+226>:    cmp    eax,0x0
0x00005596e5aaca5 <+229>:    setne  al
0x00005596e5aaca8 <+232>:    and    al,0x1
0x00005596e5aacaa <+234>:    mov    BYTE PTR [rbp-0x19],al
=> 0x00005596e5aacad <+237>:   mov    edi,0x58
0x00005596e5aacab2 <+242>:    call   0x5596e637f6d0 <_Znwm>
0x00005596e5aacab7 <+247>:    mov    rsi,QWORD PTR [rbp-0x78]
0x00005596e5aacabb <+251>:    mov    rdi,rax
0x00005596e5aacabe <+254>:    mov    QWORD PTR [rbp-0x88],rdi
0x00005596e5aacac5 <+261>:    mov    al,BYTE PTR [rbp-0x19]
0x00005596e5aacac8 <+264>:    mov    rcx,QWORD PTR [rbp-0x28]

Disassembly is the list of machine instructions the processor actually runs, shown in a human-readable form. Each line has an address, an offset in angle brackets, the instruction, and its operands. In plain words:

  • The lines before the arrow load a byte from memory, mask it to its lowest bit with and al,0x1, widen it into a full register with movzx, combine it with another register using or, compare the result with zero using cmp, and set a byte to 1 or 0 depending on whether the comparison was not equal, using setne. This is the compiler's way of computing a true or false value.
  • The arrow marks the instruction of interest: mov edi,0x58 puts the number 88 into the register edi. On this platform, that register carries the first argument to the next function call.
  • call 0x5596e637f6d0 <_Znwm> calls the C++ memory allocator. _Znwm is the mangled name of operator new(unsigned long), and the unsigned long argument is the size, so the call asks for 88 bytes.
  • The remaining lines save the returned address and reload other values for the constructor call that follows.

The report then shows a memory dump and, after the watchpoint fires, the same region with the Handle pointer written into it. First the uninitialised region:

Text
gef➤  x/88wx 0x00003700000a5260

0x3700000a5260: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5270: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5280: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a5290: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a52a0: 0xabababab                        0xabababab                        0xabababab                        0xabababab
0x3700000a52b0: 0xabababab                        0xabababab                        0xefbeadde                        0x0dd0feca
0x3700000a52c0: 0x05f03713                        0x1eab11ba                        0x00000000                        0x00000000

This is output from GEF, a debugging extension for GDB, the standard debugger on Linux-style systems. x/88wx means examine 88 words of memory in hexadecimal. Each line shows an address on the left and four 32-bit values on the right. The repeated 0xabababab is a fill pattern that the allocator writes into fresh memory to make it obvious that nothing has been stored there yet. Seeing it means the object has been reserved but not yet filled in.

The report says this snippet is from the disassembly of RequestStream where the new StreamRequest is created:

Text
0x5596e5aacac8 <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)0> mov rcx, QWORD PTR [rbp-0x28]
0x5596e5aacacc <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)4> and al, 0x1
0x5596e5aacace <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)6> movzx edx, al
0x5596e5aacad1 <net::QuicChromiumClientSession::Handle::RequestStream(bool,+)9> call 0x5596e5aad1b0 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> push rbp
0x5596e5aad1b0 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov rbp, rsp
0x5596e5aad1b1 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> sub rsp, 0x30
0x5596e5aad1b4 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov al, dl
0x5596e5aad1b8 <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov QWORD PTR [rbp-0x8], rdi
0x5596e5aad1ba <net::QuicChromiumClientSession::StreamRequest::StreamRequest(net::QuicChromiumClientSession::Handle*,+)> mov QWORD PTR [rbp-0x10], rsi

[redacted] (
QWORD var_0 = 0x000037e0000a5260 -> 0xabababababababab,
QWORD var_1 = 0x000037000064820 -> 0x00005596e573acc8 -> 0x00005596e5aac380 -> net::QuicChromiumClientSession::Handle::Handle()+0> push rbp,
bool var_2 = 0x0000000000000000,
QWORD var_3 = 0x00007ffccf6b074c -> 0x00007ffccf6b4492
)

In plain words:

  • The first lines prepare arguments and then call the constructor of StreamRequest. The constructor is the function that sets up a newly allocated object.
  • Inside the constructor, push rbp saves the previous stack frame pointer, mov rbp, rsp starts a new frame, and sub rsp, 0x30 makes room on the stack for local variables. A stack frame is the scratch space a function uses while it runs.
  • mov al, dl, mov QWORD PTR [rbp-0x8], rdi and mov QWORD PTR [rbp-0x10], rsi copy the incoming arguments into local slots.
  • The block starting _ZN3net25... is the debugger showing the arguments to the constructor. The mangled name is the compiler's encoded form of the full C++ name. var_0 is the memory for the new object, still filled with 0xabababababababab. var_1 is a pointer to the handle, which the debugger follows through two more addresses to the handle's own constructor. var_2 is the confirmation flag, here false. var_3 is the traffic annotation.

In the newly allocated memory, a pointer to QuicChromiumClientSession::Handle is stored by initialising a base::raw_ptr to point at the handle. base::raw_ptr is Chrome's safer replacement for a plain pointer: it still points at an object, but it can be instrumented to notice certain kinds of misuse. The report shows the watchpoint firing on that write:

Text
gef➤ ni
Thread 1 "net_unittests" hit Hardware watchpoint 4: *0x000037e0000a5260

Old value = 0xabababab
New value = 0x64820
0x00005596e5ac2a88 in base::raw_ptr<net::QuicChromiumClientSession::Handle, (partition_alloc::internal::RawPtrTraits)>::raw_ptr (this=0x37e0000a5260, p=0x37e000064820) at ../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr.h:460
460     : wrapped_ptr_(Impl::WrapRawPtr(p)) {}

gef➤ x/88wx 0x000037e0000a5260
0x37e0000a5260: 0x000064820   0xabababab  0xabababab  0xabababab
0x37e0000a5270: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a5280: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a5290: 0xabababab   0xabababab  0xabababab  0xabababab
0x37e0000a52a0: 0xabababab   0xabababab  0xfebdeadde 0xddd0feca
0x37e0000a52b0: 0xabababab   0x1eab11ba  0x00000000  0x00000000
0x37e0000a52c0: 0x05f03713   0xeab11ba   0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52d0: 0xcd037e000 0x8d051a00  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52e0: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a52f0: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5300: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5310: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5320: 0xcdcdcdcd   0xcdcdcdcd  0xcdcdcdcd  0xcdcdcdcd
0x37e0000a5330: 0xcdcdcdcd   0x00000001  0x00000000  0x00000000
0x37e0000a5340: 0x000646d00  0x000037e00  0xababab00  0x00000000
0x37e0000a5350: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5360: 0x00000001   0x00000000  0xababab00  0x00000000
0x37e0000a5370: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5380: 0x00000000   0x00000000  0x00000000  0x00000000
0x37e0000a5390: 0x00000000   0xabababab   0xeab11ba   0x00000000

In plain words:

  • ni means step to the next machine instruction. A watchpoint is a debugger feature that stops the program whenever a chosen memory address is written to. Here the watchpoint is set on the first 8 bytes of the new object.
  • The debugger reports that the old value was 0xabababab, the fill pattern, and the new value is 0x64820, the address of the handle. So this is the exact moment the object starts pointing at its session handle.
  • The next line shows where the program stopped: inside the base::raw_ptr constructor, at line 460 of raw_ptr.h. The source line : wrapped_ptr_(Impl::WrapRawPtr(p)) {} is the constructor's initialiser list, which stores the wrapped pointer.
  • The memory dump afterwards shows the first word now holds 0x000064820 instead of the fill pattern, while the rest is still mostly fill. The 0xcdcdcdcd values further down are another debug fill pattern, used for memory that has been freed or is otherwise off limits. Seeing them next to live data is a reminder of how much of this kind of debugging is about reading the fill patterns.

Free

The report shows the destructor of the handle and the session's RemoveHandle:

Text
// chromium/src/net/quic/quic_chromium_client_session.cc
QuicChromiumClientSession::Handle::~Handle() {
  if (session_)
    session_->RemoveHandle(this);
}

void QuicChromiumClientSession::RemoveHandle(Handle* handle) {
  DCHECK(base::Contains(handles_, handle));
  handles_.erase(handle);
}

Line by line:

  • QuicChromiumClientSession::Handle::~Handle() is the destructor of the handle, the function that runs when the handle is being destroyed. The tilde in front of the name is how C++ marks a destructor.
  • if (session_) checks that the handle still has a session to talk to.
  • session_->RemoveHandle(this); tells the session to forget this handle. this means the current object.
  • void QuicChromiumClientSession::RemoveHandle(Handle* handle) is the function that does the forgetting. It takes a pointer to the handle to remove.
  • DCHECK(base::Contains(handles_, handle)); is a debug-only check that the handle really is in the session's collection of handles. handles_ is that collection.
  • handles_.erase(handle); removes it.

This is the free side of the story: the handle is taken out of the session's records.

Use

The stack trace entry #0 0x16cac4945 points to OnRequestCompleteFailure inside QuicChromiumClientSession. The report says the source suggests that if the callback_ member is not null, a callback is scheduled for later execution, and a UAF can occur if callback_ references memory that has been freed before the callback runs:

Text
// chromium/src/net/quic/quic_chromium_client_session.cc
void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure(
    int rv) {
  //DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_);
  // This method is called even when the request completes synchronously.
  if (callback_) {
    // Avoid re-entrancy if the callback calls into the session.
    base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
        FROM_HERE,
        base::BindOnce(&QuicChromiumClientSession::StreamRequest::DoCallback,
                       weak_factory_.GetWeakPtr(), rv));
  }
}

Line by line:

  • void ... OnRequestCompleteFailure(int rv) is the function that runs when a stream request has failed. rv is the result code describing the failure.
  • The commented-out DCHECK_EQ line is a disabled debug check that the state machine is at the completion stage.
  • The next comment explains that this method is called even when the request completes synchronously, meaning the failure can arrive immediately rather than later.
  • if (callback_) checks that there is a callback to run. callback_ is a member variable of the StreamRequest, the stored phone number from the sticky note.
  • The comment about re-entrancy explains why the callback is not simply called here. Re-entrancy is when a function ends up running again before its previous run has finished, like a phone call that interrupts another call on the same line. Calling the callback directly could let it call back into the session while the session is in the middle of something, so the code defers it.
  • base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(...) puts a task on the current thread's to-do list. PostTask means "do not run this now, run it when the thread next gets to it". This is the delay that creates the gap between scheduling and running.
  • FROM_HERE is a macro that records the source location of the call, so debugging tools can say where the task came from.
  • base::BindOnce(&QuicChromiumClientSession::StreamRequest::DoCallback, weak_factory_.GetWeakPtr(), rv) packages the DoCallback function with two arguments: a weak pointer to the StreamRequest, and the result code rv. base::BindOnce again produces a callback that runs exactly once.
  • The closing braces end the if and the function.

The report says the UAF appears to stem from improper lifecycle management of callback_. The callback is scheduled for execution in OnRequestCompleteFailure, and because base::SingleThreadTaskRunner::PostTask posts a task for delayed execution, the callback may run at a time when the StreamRequest it belongs to has already been destroyed. The evidence cited is the stack trace pointing at OnRequestCompleteFailure and the use of base::BindOnce with callback_ for delayed execution.

Impact

The report describes a use-after-free in which an 8-byte pointer that has been previously freed is reused in OnRequestCompleteFailure, potentially leading to the execution of a callback function. A primitive, in security writing, is the basic capability a bug gives an attacker, before it is turned into a full attack. If an attacker manipulates the callback_ object, the report says, it could be exploited to execute arbitrary code, meaning code the attacker chooses rather than code Chrome intended to run.

The practical conditions are narrow: the bug requires a tightly timed race condition, and the report notes that it is hard to trigger. The severity assigned is medium.

Fix

The report does not describe the patch. It identifies the faulty lifecycle management of callback_ and the delayed PostTask as the source of the problem, which is where a fix would have to ensure the posted task cannot outlive the StreamRequest it references.

Variants to test

These are follow-up ideas for anyone hunting similar bugs, each with a clear sign that it worked:

  • Look for other PostTask plus base::BindOnce pairs in asynchronous network code where the bound object can be destroyed before the task runs. A positive result is an ASAN heap-use-after-free report whose free stack is a destructor and whose use stack is the posted callback.
  • Exercise tab close and navigation during in-flight QUIC stream requests. A positive result is a crash or ASAN report during session teardown, as in the ~QuicChromiumClientSession frame here.
  • Check other Handle-style objects that register themselves with an owner and are removed in their destructor. A positive result is a callback or task that still references the removed handle after RemoveHandle has run.
  • Test the same pattern in other protocol clients that post completion callbacks to a task runner. A positive result is a use-after-free when the owning session is torn down between the post and the run.

Glossary

  • AddressSanitizer (ASAN): a debugging tool built into a program that detects memory errors such as use-after-free and prints a detailed report when one occurs.
  • Allocation: reserving a block of memory for an object to use.
  • API: an agreed way for one piece of software to ask another piece of software to do something, like a menu of allowed requests.
  • Arbitrary code execution: making a program run code the attacker chose, rather than code the programmer wrote.
  • Asynchronous: work that is started now but finishes later, so the program carries on in the meantime instead of waiting.
  • Callback: a function handed to another piece of code so it can be run later, when something finishes.
  • CVE: a public identifier for a known security vulnerability, so people can refer to it unambiguously.
  • Chrome VRP: Google Chrome's Vulnerability Reward Program, which pays researchers for reporting bugs in Chrome.
  • Constructor: the function that sets up a newly created object.
  • Destructor: the function that runs when an object is being destroyed, used to release what it holds.
  • Disassembly: the human-readable listing of the machine instructions a processor runs.
  • Free: giving a block of memory back so it can be reused.
  • GDB / GEF: GDB is a debugger, a tool for pausing and inspecting a running program; GEF is an extension that makes GDB friendlier.
  • Handle: an object that represents a connection or resource and lets other code use it without managing it directly.
  • Heap: the area of memory where objects created at run time are stored.
  • HTTP: the protocol browsers use to fetch web pages and other resources.
  • HTTP layer: the part of the browser that speaks HTTP and turns web requests into network activity.
  • Memory address: a number identifying a location in memory, like a house number on a street.
  • Pointer: a value that holds a memory address, pointing at where an object lives.
  • Proof of concept (PoC): a small demonstration that reliably triggers a bug.
  • QUIC: a modern network protocol used by Chrome that runs over UDP and aims to be faster and more robust than older protocols.
  • Race condition: a bug where the result depends on the exact timing of two events, so it may happen only occasionally.
  • Raw pointer: a plain memory address with no automatic safety checks.
  • Re-entrancy: when a function is entered again before its previous run has finished.
  • Severity: a rating of how serious a vulnerability is, often low, medium, high or critical.
  • Smart pointer: an object that holds a pointer and automatically frees the memory when it is no longer needed.
  • Stack frame: the scratch space a running function uses for its local variables and saved state.
  • Stack trace: a list of the functions that were running at a given moment, from the innermost to the outermost.
  • State machine: code organised as a set of named stages, where each stage decides which stage comes next.
  • Stream: one independent lane of data inside a connection, so several requests can travel at once without mixing.
  • Thread: one sequence of instructions a program is running; a program can run several at once.
  • Use-after-free (UAF): using memory after it has been given back, which can read or write data that no longer belongs to the program.
  • Watchpoint: a debugger setting that pauses the program when a chosen memory location is written to.
  • Weak pointer: a reference that does not keep an object alive and can tell when the object has gone away.
  • 0-RTT: sending data on the very first message of a connection, before the secure handshake has fully completed, which saves time but has weaker guarantees.

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.