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

Use after free in Performance Manager (CVE-2024-2400)

A heap use-after-free exists in Chromium's Performance Manager: a PageResourceMonitor object owned by the graph is freed during shutdown, but a battery-status update can still call ScopedResourceUsageQuery::NotifyObservers and use the freed object. An attacker who can influence timing could trigger memory corruption in the browser process.

zh1x1an1221 Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 12 days

Steps to reproduce the problem

  1. In order to reproduce this vulnerability stably, we need to compile an asan chrome locally. The commit I chose to reproduce the vulnerability is:

git checkout 80a4b049ae9d4b5abea7333a661a1644f11b5a70 2. git apply trigger.diff can trigger vulnerabilities more stably and conveniently 3. Start chrome like this: ./out/asan/Chromium.app/Contents/MacOS/Chromium --user-data-dir=/tmp/noexists1.When this line of log is printed:in ScopedResourceUsageQuery::NotifyObservers === === zh1x1an:, UAF can be triggered by closing chromium.Triggering this vulnerability does not require enabling any additional features

Problem Description

RCA and Bisect here

The object: performance_manager::metrics::PageResourceMonitor that triggers the UAF vulnerability is created here [1]

[1] https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.cc;l=206-207?q=chrome_browser_main_extra_parts_performance_manager.cc:207

  graph->PassToGraph(
      std::make_unique<performance_manager::metrics::PageResourceMonitor>());

In the GraphImpl class, a graph_owned_ is stored:

[2] https://source.chromium.org/chromium/chromium/src/+/main:components/performance_manager/graph/graph_impl.h;l=281-285

  // Graph-owned objects. For now we only expect O(10) clients, hence the
  // flat_map.
  OwnedObjects<GraphOwned,
               /* CallbackArgType = */ Graph*,
               &GraphOwned::OnPassedToGraph,
               &GraphOwned::OnTakenFromGraph>
      graph_owned_ GUARDED_BY_CONTEXT(sequence_checker_);

When Chrome starts, the GraphImpl object will be created and call GraphImpl::PassToGraphImpl [3], adding multiple objects (approximately more than 30) to graph_owned_, which will also add my latest at the position of [1] The performance_manager::metrics::PageResourceMonitor object mentioned at the beginning.

[3] https://source.chromium.org/chromium/chromium/src/+/main:components/performance_manager/graph/graph_impl.cc;l=273-276;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090;bpv=0;bpt=1

When chrome is closed, graph_owned_.ReleaseObjects(this); in GraphImpl::TearDown will be called to release all objects initially added.

[4] https://source.chromium.org/chromium/chromium/src/+/main:components/performance_manager/graph/graph_impl.cc;l=193;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090;bpv=0;bpt=1

The implementation of ReleaseObjects is as follows:

[5] https://source.chromium.org/chromium/chromium/src/+/main:components/performance_manager/owned_objects.h;l=83-91;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090;bpv=1;bpt=1

  // Releases all the objects owned by this container, invoking their
  // OnTakenFunctionPtr as they are released.
  template <typename... ArgTypes>
  void ReleaseObjects(ArgTypes... args) {
    // Release the last object first to be friendly with base::flat_set, which
    // is actually a std::vector.
    while (!objects_.empty())
      TakeObject(objects_.rbegin()->get(), std::forward<ArgTypes>(args)...);
  }

This will free performance_manager::metrics::PageResourceMonitor.

However, we can still use this object after it is released. Take a look at the code at this location [6]

[6] https://source.chromium.org/chromium/chromium/src/+/main:components/performance_manager/resource_attribution/queries.cc;l=226-231?q=queries.cc:226

void ScopedResourceUsageQuery::NotifyObservers(
    scoped_refptr<ObserverList> observer_list,
    const QueryResultMap& results) {
  observer_list->Notify(FROM_HERE, &QueryResultObserver::OnResourceUsageUpdated,
                        results);
}

When the battery status of the device is updated, such as unplugging the device, or restarting charging, etc., ScopedResourceUsageQuery::NotifyObservers will be called to notify observers of the change in status. However, at this time, performance_manager::metrics::PageResourceMonitor may have been released, eventually leading to UAF.

Triggering this vulnerability does not require any feature to be enabled. Since this is a UAF caused by a conditional race, I added sleep to the trigger.diff file to trigger this vulnerability more conveniently. As I mentioned in the reproduction steps, when the log in the trigger.diff file prints, if chrome is closed at that point, then the object is released, eventually successfully triggering the UAF at the ScopedResourceUsageQuery::NotifyObservers location.

I'll provide Bisect commit information later.

Summary

Security: heap-use-after-free in ScopedResourceUsageQuery::NotifyObservers

Additional Data

Category: Security
Chrome Channel: Stable
Regression: N/A

The original report as published on the Chromium issue tracker, by zh1x1an1221 of Ant Group Tianqiong Security Lab. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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

How it worked

Root cause

Likely the graph-owned PageResourceMonitor is released during GraphImpl::TearDown while a pending battery-status callback can still reach ScopedResourceUsageQuery::NotifyObservers, which uses the freed observer.

Impact

A heap use-after-free in the browser process could crash Chromium and may allow memory corruption, though the report does not demonstrate code execution.

What the attacker needed

ASan Chromium build at the given commit; trigger patch applied; battery or charging state change; close browser at the right moment

How it was found

  1. Build an ASan Chromium at the stated commit and apply the provided trigger patch.
  2. Launch Chromium with a fresh user-data directory.
  3. Wait until the patched log line about ScopedResourceUsageQuery::NotifyObservers is printed.
  4. Close Chromium at that moment to free the graph-owned objects and trigger the use-after-free.

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

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

When Chrome shuts down it frees some internal objects. A background event, here a change in the device's battery or charging state, can still fire and try to notify those objects after they have been freed. Using memory that has already been released is called a use-after-free and can crash the browser or, in principle, let an attacker run their own code.

What is Memory corruption?

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

More by zh1x1an1221

View all

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