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

Use after free in Mojo (CVE-2024-1670)

Cassidy Kim Follow

Originally disclosed on Chrome VRP

Bounty$5,000 High View original
  • Fix shipped in 3 months

Steps to reproduce the problem:
tested os: Ubuntu 22.04
tested chromium version:
Chromium 121.0.6129.0
Chromium 121.0.6163.0(gs://chromium-browser-asan/linux-release/asan-linux-release-1232441.zip)

Repro Steps:
Due to the instability of the reproduction, I used a Puppeteer script to simultaneously open multiple browsers. The script requires modifications based on the actual environment, such as changing the Chrome path and the URL of the PoC (Proof of Concept).

  • Install Node.js and Puppeteer.
  • Execute the script with: node ./test.js 2>&1 | grep -E 'AddressSanitizer'

On my local machine, the issue can be reproduced in over 10 minutes. If you're unable to reproduce it after several attempts, consider adjusting the number of browsers the script opens, as well as the number of iframes in the main.html file, to suit your specific environment.

Problem Description:
Normally, when mojo::Remotemojom::blink::Blob[0] is created, it also creates a mojo::WaitSet::State::Context[2]. When blob.Unbind()[1] is called, it is supposed to release the corresponding Context. However,in the ASAN log, you can see the call to blob Unbind() actually released the Context created by mojo::Remoteblink::mojom::blink::StorageArea::Bind()[c], ultimately resulting in UAF. I haven't identified the root cause yet. If there is any progress, I will update again.

void BlobDataHandle::CloneBlobRemote(  
    mojo::PendingReceiver<mojom::blink::Blob> receiver) {  
  base::AutoLock locker(blob_remote_lock_);  
  if (!blob_remote_.is_valid())  
    return;  
  mojo::Remote<mojom::blink::Blob> blob(std::move(blob_remote_));  --->[0]  
  blob->Clone(std::move(receiver));  
  blob_remote_ = blob.Unbind();                                    --->[1]  
}  

[a]https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/blob/blob_data.cc;l=390?q=third_party%2Fblink%2Frenderer%2Fplatform%2Fblob%2Fblob_data.cc:390:23

MojoResult AddHandle(Handle handle, MojoHandleSignals signals) {  
    DCHECK(trap_handle_.is_valid());  
    ```  
    scoped_refptr<Context> context = new Context(this, handle);      --->[2]  
  
    {  
      base::AutoLock lock(lock_);  
  
      if (handle_to_context_.count(handle))  
        return MOJO_RESULT_ALREADY_EXISTS;  
      DCHECK(!contexts_.count(context->context_value()));  
  
      handle_to_context_[handle] = context;  
      contexts_[context->context_value()] = context;  
    }  
    ```  
    return rv;  
  }  

[b]https://source.chromium.org/chromium/chromium/src/+/main:mojo/public/cpp/system/wait_set.cc;l=60?q=mojo%2Fpublic%2Fcpp%2Fsystem%2Fwait_set.cc:60:38
[c]https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/storage/cached_storage_area.cc;l=244?q=third_party%2Fblink%2Frenderer%2Fmodules%2Fstorage%2Fcached_storage_area.cc:244:18

Additional Comments:

**Chrome version: ** 121.0.6129.0 **Channel: ** Not sure

OS: Linux

The original report as published on the Chromium issue tracker, by Cassidy Kim(@cassidy6564). 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. 5 min read.

Context

This is a use-after-free (UAF) in Mojo, Chrome's inter-process communication system, reported through the Chrome Vulnerability Rewards Program and disclosed on 20 February 2024 as CVE-2024-1670. The affected component is Mojo itself, and the report is rated high severity, with a bounty of 5,000 USD.

Mojo is the IPC layer that Chrome's processes use to talk to each other. Blink, the renderer's engine, exposes Mojo interfaces such as mojom::blink::Blob and blink::mojom::blink::StorageArea to renderer code. Each mojo::Remote<T> wraps a message pipe endpoint, and the Mojo wait set machinery tracks handles through mojo::WaitSet::State::Context objects. When a remote is created, a context is allocated for its handle; when the remote is unbound, that context is supposed to be released.

The report describes a case where that bookkeeping goes wrong: unbinding one remote releases the context that belongs to a different remote, and the resulting dangling state leads to a UAF.

Setup

The researcher tested on Ubuntu 22.04 against two Chromium builds:

  • Chromium 121.0.6129.0
  • Chromium 121.0.6163.0, from the ASAN build at gs://chromium-browser-asan/linux-release/asan-linux-release-1232441.zip

The reproduction is described as unstable. To raise the odds, the researcher used a Puppeteer script that opens several browsers at the same time. The script needs to be adjusted to the local environment, in particular the Chrome path and the URL of the proof of concept. The report does not include the script or the PoC files themselves.

Finding it

The researcher's observation is about the lifetime of wait set contexts. Normally, when a mojo::Remote<mojom::blink::Blob> is created, a mojo::WaitSet::State::Context is created alongside it. When blob.Unbind() is called, the corresponding context is supposed to be released.

In the ASAN log, however, the call to blob.Unbind() released the context that had been created by mojo::Remote<blink::mojom::blink::StorageArea>::Bind(). The wrong context is freed, which ultimately results in a UAF. The researcher states plainly that the root cause had not been identified at the time of writing, and that the report would be updated if there was progress.

The relevant code is in BlobDataHandle::CloneBlobRemote:

void BlobDataHandle::CloneBlobRemote(
    mojo::PendingReceiver<mojom::blink::Blob> receiver) {
  base::AutoLock locker(blob_remote_lock_);
  if (!blob_remote_.is_valid())
    return;
  mojo::Remote<mojom::blink::Blob> blob(std::move(blob_remote_));  --->[0]
  blob->Clone(std::move(receiver));
  blob_remote_ = blob.Unbind();                                    --->[1]
}

Marker [0] is the point where the mojo::Remote<mojom::blink::Blob> is created. Marker [1] is the blob.Unbind() call that is supposed to release that same context. The researcher links this to third_party/blink/renderer/platform/blob/blob_data.cc at line 390.

The context allocation side is in AddHandle:

MojoResult AddHandle(Handle handle, MojoHandleSignals signals) {
    DCHECK(trap_handle_.is_valid());
    ```
    scoped_refptr<Context> context = new Context(this, handle);      --->[2]

    {
      base::AutoLock lock(lock_);

      if (handle_to_context_.count(handle))
        return MOJO_RESULT_ALREADY_EXISTS;
      DCHECK(!contexts_.count(context->context_value()));

      handle_to_context_[handle] = context;
      contexts_[context->context_value()] = context;
    }
    ```
    return rv;
  }

Marker [2] is the new Context(this, handle) allocation. The context is then stored in two maps, handle_to_context_ keyed by handle and contexts_ keyed by the context value. The researcher links this to mojo/public/cpp/system/wait_set.cc at line 60.

The third reference, [c], points to third_party/blink/renderer/modules/storage/cached_storage_area.cc at line 244, the site of the mojo::Remote<blink::mojom::blink::StorageArea>::Bind() whose context is wrongly freed.

Exploitation

The report gives reproduction steps rather than an exploit chain. The steps are:

  1. Install Node.js and Puppeteer.
  2. Run the script with:
Bash
node ./test.js 2>&1 | grep -E 'AddressSanitizer'

The command runs the Puppeteer script and filters its output down to AddressSanitizer lines, so that a crash report is easy to spot. On the researcher's local machine the issue could be reproduced in over 10 minutes. If several attempts fail, the advice is to adjust the number of browsers the script opens and the number of iframes in the main.html file to suit the environment. The report does not show the contents of test.js or main.html, nor any request, response or ASAN output beyond the description above.

Root cause

The report does not identify the root cause. What it establishes is the symptom: the context released by blob.Unbind() is the one created by mojo::Remote<blink::mojom::blink::StorageArea>::Bind(), not the one created for the blob remote. The report leaves the mechanism open. Any explanation beyond that would be speculation.

Impact

The platform records this as a high severity UAF in Mojo with a 5,000 USD bounty. The report itself does not describe what an attacker could achieve with the bug, under which conditions, or whether it is reachable from web content beyond the PoC setup. The researcher notes the instability of the reproduction, so reliability is a limiting factor in what is shown.

Fix

The report does not describe a fix or a patch. The researcher's own next step, as stated, was to keep investigating the root cause and update the report if there was progress.

Variants to test

These follow from the report's own observation and are worth trying on similar Mojo-backed interfaces:

  1. Interleave creation and unbinding of two different mojo::Remote types in the same renderer context, for example a blob remote and a storage area remote, and watch for a context being freed by the wrong Unbind(). A positive result is an ASAN report showing the free attributed to a remote other than the one whose context was allocated.
  2. Exercise BlobDataHandle::CloneBlobRemote repeatedly under load, since the report's reproducer relies on many browsers and iframes. A positive result is a UAF report from the ASAN build within a comparable time window.
  3. Vary the number of browsers and iframes as the report suggests, to find the threshold at which the race becomes reliable. A positive result is a reproduction that no longer needs the long run time described.
  4. Look for other call sites that move a mojo::Remote into a local and then call Unbind() on it, as CloneBlobRemote does, and check whether the wait set context released matches the one allocated. A positive result is the same mismatch between the allocating and freeing remote.

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. 12 min read.

What happened, in plain words

A security researcher found a bug in Google Chrome, the web browser most people use every day. The bug is a type called a use-after-free, which is one of the most serious kinds of memory bug a program can have. The researcher was paid a bounty of 5,000 USD through the Chrome Vulnerability Rewards Program, a scheme that pays people for finding and reporting security problems. The bug was made public on 20 February 2024 under the identifier CVE-2024-1670. A CVE is a public catalogue number given to a known security flaw so that everyone can refer to the same thing.

The affected part of Chrome is called Mojo. Mojo is the internal messaging system that Chrome uses to let its different parts talk to each other. Chrome is built as many separate processes (independent programs running side by side) rather than one giant program, because that is safer: if one part crashes or is compromised, the others keep running. Mojo is the postal service between those processes.

The bug is in how Mojo keeps track of certain internal records called contexts. When Chrome opens a connection, Mojo creates a small record for it. When the connection is closed, that record should be deleted. In this bug, closing one connection deleted the record belonging to a different connection. The result is that a piece of memory is freed while something else still thinks it is in use. That is exactly what use-after-free means: the program uses memory after it has been handed back, and the memory may by then contain something else entirely.

The researcher did not work out the exact underlying cause. They described what they saw in the crash logs and said they would update the report if they made progress. So this article explains the symptom and the reproduction, not a full explanation of why it happens.

The setup

The researcher tested on Ubuntu 22.04, a version of the Linux operating system. They used two builds of Chromium, the open-source project that Chrome is based on:

  • Chromium 121.0.6129.0
  • Chromium 121.0.6163.0, taken from an AddressSanitizer build at gs://chromium-browser-asan/linux-release/asan-linux-release-1232441.zip

AddressSanitizer, usually shortened to ASAN, is a tool built into a special version of a program that watches memory very closely. When the program reads or writes memory it should not touch, ASAN notices and prints a detailed report. Think of it as a smoke detector for memory bugs: it does not stop the fire, but it tells you exactly where the smoke started. Researchers use ASAN builds because a bug that might silently corrupt data in a normal build produces a clear, loud report in an ASAN build.

The reproduction was unstable, meaning it did not happen every time. To improve the odds, the researcher wrote a Puppeteer script that opens several browsers at the same time. Puppeteer is a tool that lets a program control a browser automatically, clicking and loading pages without a human. The script has to be adjusted to the local machine, in particular the path to the Chrome program and the URL of the proof of concept. A proof of concept, or PoC, is a small demonstration that triggers the bug, made to prove the problem is real without doing any harm.

The report does not include the script or the PoC files themselves, so we cannot see exactly what they contained.

Finding it

The researcher's observation is about the lifetime of those wait set contexts. A wait set is a Mojo feature that lets one part of Chrome wait for activity on several connections at once, like a receptionist watching several phone lines. Each line it watches gets a context record.

Normally, when a mojo::Remote<mojom::blink::Blob> is created, a mojo::WaitSet::State::Context is created alongside it. A mojo::Remote is a handle to a connection to another process; the angle brackets say what kind of messages travel over that connection. Here it is a Blob, which is a chunk of binary data such as a file or an image held in memory. When blob.Unbind() is called, the corresponding context is supposed to be released. Unbind means closing the connection and giving back the resources.

In the ASAN log, however, the call to blob.Unbind() released the context that had been created by mojo::Remote<blink::mojom::blink::StorageArea>::Bind(). A StorageArea is the storage Chrome gives a website, such as the place where a site keeps data in your browser. So closing a blob connection freed the record belonging to a storage connection. The wrong context is freed, which ultimately results in a use-after-free. The researcher states plainly that the root cause had not been identified at the time of writing, and that the report would be updated if there was progress.

The relevant code is in BlobDataHandle::CloneBlobRemote:

Text
void BlobDataHandle::CloneBlobRemote(
    mojo::PendingReceiver<mojom::blink::Blob> receiver) {
  base::AutoLock locker(blob_remote_lock_);
  if (!blob_remote_.is_valid())
    return;
  mojo::Remote<mojom::blink::Blob> blob(std::move(blob_remote_));  --->[0]
  blob->Clone(std::move(receiver));
  blob_remote_ = blob.Unbind();                                    --->[1]
}

Line by line, in plain words:

  • void BlobDataHandle::CloneBlobRemote( starts the definition of a function called CloneBlobRemote that belongs to a class called BlobDataHandle. A class is a blueprint for an object; a function is a named block of instructions. void means the function gives nothing back when it finishes.
  • mojo::PendingReceiver<mojom::blink::Blob> receiver) { says the function takes one input, called receiver, which is a pending receiver for a Blob connection. A receiver is the other end of a connection: one side sends, the other receives. Pending means it is set up but not yet connected.
  • base::AutoLock locker(blob_remote_lock_); takes a lock. A lock is like a key to a single-occupancy toilet: only one piece of code can hold it at a time, so two parts of the program cannot change the same data at once. This protects the blob connection from being changed by two threads (parallel streams of execution) simultaneously.
  • if (!blob_remote_.is_valid()) checks whether the stored blob connection is valid. The ! means not.
  • return; if it is not valid, the function stops here and does nothing else.
  • mojo::Remote<mojom::blink::Blob> blob(std::move(blob_remote_)); --->[0] creates a new local mojo::Remote for a Blob and moves the stored connection into it. std::move transfers ownership rather than copying. Marker [0] is the point where the remote is created.
  • blob->Clone(std::move(receiver)); asks the remote to clone itself into the new receiver, so the caller gets a working connection.
  • blob_remote_ = blob.Unbind(); --->[1] unbinds the local remote and stores the result back. Marker [1] is the blob.Unbind() call that is supposed to release the same context that was allocated at [0].

The researcher links this to third_party/blink/renderer/platform/blob/blob_data.cc at line 390. That is a file path inside the Chromium source code; Blink is the part of Chrome that turns web pages into what you see on screen.

The context allocation side is in AddHandle:

Text
MojoResult AddHandle(Handle handle, MojoHandleSignals signals) {
    DCHECK(trap_handle_.is_valid());
    ```
    scoped_refptr<Context> context = new Context(this, handle);      --->[2]

    {
      base::AutoLock lock(lock_);

      if (handle_to_context_.count(handle))
        return MOJO_RESULT_ALREADY_EXISTS;
      DCHECK(!contexts_.count(context->context_value()));

      handle_to_context_[handle] = context;
      contexts_[context->context_value()] = context;
    }
    ```
    return rv;
  }

Line by line:

  • MojoResult AddHandle(Handle handle, MojoHandleSignals signals) { defines a function called AddHandle that takes a handle (a reference to a connection) and a set of signals (events to watch for, such as readable or writable). It returns a MojoResult, which is a status code saying whether it worked.
  • DCHECK(trap_handle_.is_valid()); is a debug check. DCHECK only runs in debug builds and stops the program if the condition is false. Here it checks that the trap handle is valid.
  • scoped_refptr<Context> context = new Context(this, handle); --->[2] creates a new context record for this handle. new allocates fresh memory. scoped_refptr is a smart pointer that automatically frees the memory when the last reference to it goes away, like a library book that is returned automatically when the last borrower is done. Marker [2] is this allocation.
  • { opens a block so the lock below is released automatically at the closing brace.
  • base::AutoLock lock(lock_); takes the lock, so only one thread can change the maps at a time.
  • if (handle_to_context_.count(handle)) checks whether this handle is already in the map. A map is a lookup table that pairs a key with a value, like a phone book pairing a name with a number.
  • return MOJO_RESULT_ALREADY_EXISTS; if it is already there, stop and report that it already exists.
  • DCHECK(!contexts_.count(context->context_value())); checks in debug builds that the context value is not already in the second map.
  • handle_to_context_[handle] = context; stores the context in the first map, keyed by handle.
  • contexts_[context->context_value()] = context; stores the same context in the second map, keyed by the context value.
  • } closes the block, releasing the lock.
  • return rv; returns the status code.

The researcher links this to mojo/public/cpp/system/wait_set.cc at line 60.

The third reference, [c], points to third_party/blink/renderer/modules/storage/cached_storage_area.cc at line 244, the site of the mojo::Remote<blink::mojom::blink::StorageArea>::Bind() whose context is wrongly freed.

Exploitation

The report gives reproduction steps rather than an exploit chain. An exploit chain is a sequence of steps that turns a bug into a real attack; here the researcher only shows how to make the bug happen, not how to abuse it.

The steps are:

  1. Install Node.js and Puppeteer. Node.js is a program that runs JavaScript outside a browser, and Puppeteer is the library that lets that JavaScript drive a browser.
  2. Run the script with:
Bash
node ./test.js 2>&1 | grep -E 'AddressSanitizer'

Line by line:

  • node ./test.js runs the file test.js with Node.js. That file is the Puppeteer script.
  • 2>&1 sends the error output to the same place as the normal output, so both are captured together. Programs normally have two output streams: one for normal results and one for errors.
  • | is a pipe, which passes the output of the left command into the right command.
  • grep -E 'AddressSanitizer' filters the output, keeping only lines that contain the word AddressSanitizer. -E means use extended regular expressions, a pattern-matching language.

The command runs the Puppeteer script and filters its output down to AddressSanitizer lines, so that a crash report is easy to spot. On the researcher's local machine the issue could be reproduced in over 10 minutes. If several attempts fail, the advice is to adjust the number of browsers the script opens and the number of iframes in the main.html file to suit the environment. An iframe is a web page embedded inside another web page, like a picture-in-picture window. The report does not show the contents of test.js or main.html, nor any request, response or ASAN output beyond the description above.

Root cause

The report does not identify the root cause. What it establishes is the symptom: the context released by blob.Unbind() is the one created by mojo::Remote<blink::mojom::blink::StorageArea>::Bind(), not the one created for the blob remote. The report leaves the mechanism open. Any explanation beyond that would be speculation.

Impact

The platform records this as a high severity use-after-free in Mojo with a 5,000 USD bounty. The report itself does not describe what an attacker could achieve with the bug, under which conditions, or whether it is reachable from web content beyond the PoC setup. The researcher notes the instability of the reproduction, so reliability is a limiting factor in what is shown.

Fix

The report does not describe a fix or a patch. The researcher's own next step, as stated, was to keep investigating the root cause and update the report if there was progress.

Variants to test

These follow from the report's own observation and are worth trying on similar Mojo-backed interfaces:

  1. Interleave creation and unbinding of two different mojo::Remote types in the same renderer context, for example a blob remote and a storage area remote, and watch for a context being freed by the wrong Unbind(). A positive result is an ASAN report showing the free attributed to a remote other than the one whose context was allocated.
  2. Exercise BlobDataHandle::CloneBlobRemote repeatedly under load, since the report's reproducer relies on many browsers and iframes. A positive result is a use-after-free report from the ASAN build within a comparable time window.
  3. Vary the number of browsers and iframes as the report suggests, to find the threshold at which the race becomes reliable. A race is when two things happen at nearly the same time and the outcome depends on which wins. A positive result is a reproduction that no longer needs the long run time described.
  4. Look for other call sites that move a mojo::Remote into a local and then call Unbind() on it, as CloneBlobRemote does, and check whether the wait set context released matches the one allocated. A positive result is the same mismatch between the allocating and freeing remote.

Glossary

  • AddressSanitizer (ASAN): a tool built into a special version of a program that detects memory errors and prints a detailed report when they happen.
  • Blink: the part of Chrome that turns web pages into what you see on screen.
  • Blob: a chunk of binary data, such as a file or an image, held in memory.
  • Bounty: money paid to a researcher for finding and reporting a security problem.
  • Build: a compiled version of a program, made from source code.
  • Chrome Vulnerability Rewards Program: Google's scheme that pays people for reporting security bugs in Chrome.
  • Class: a blueprint for an object in a program, describing what data and functions it has.
  • Context: a small internal record that Mojo keeps for each connection it watches.
  • CVE: a public catalogue number given to a known security flaw.
  • Exploit chain: a sequence of steps that turns a bug into a real attack.
  • Function: a named block of instructions in a program.
  • Handle: a reference to a connection or resource inside a program.
  • Iframe: a web page embedded inside another web page.
  • IPC (inter-process communication): the way separate processes in a program talk to each other.
  • Lock: a mechanism that lets only one piece of code use a resource at a time.
  • Map: a lookup table that pairs a key with a value.
  • Mojo: Chrome's internal messaging system that lets its processes talk to each other.
  • Node.js: a program that runs JavaScript outside a browser.
  • Process: an independent running program; Chrome uses many of them for safety.
  • Proof of concept (PoC): a small demonstration that triggers a bug to prove it is real.
  • Puppeteer: a tool that lets a program control a browser automatically.
  • Race: when two things happen at nearly the same time and the outcome depends on which wins.
  • Receiver: the end of a connection that receives messages.
  • Remote: a handle to a connection to another process.
  • Render: to turn web page code into what you see on screen.
  • Renderer: the Chrome process that renders web pages.
  • Severity: how serious a security bug is judged to be.
  • Smart pointer: a pointer that automatically frees memory when it is no longer needed.
  • StorageArea: the storage Chrome gives a website, such as where a site keeps data in your browser.
  • Thread: a parallel stream of execution inside a program.
  • Unbind: to close a connection and give back its resources.
  • Use-after-free (UAF): a bug where a program uses memory after it has been freed, which can lead to crashes or attacks.
  • Wait set: a Mojo feature that lets one part of Chrome wait for activity on several connections at once.

More by Cassidy Kim

View all

29 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.