Skip to content
Memory corruption Advisory Advanced CVE-2026-6317

Use after free in Cast (CVE-2026-6317)

A use-after-free exists in the browser process's Cast Activity Manager because the return value of a map insertion is not checked, so a dangling pointer is stored when a route ID collision occurs. An attacker could trigger this collision via concurrent auto-join requests and potentially exploit the dangling pointer to achieve remote code execution.

Google Chrome

Originally disclosed on Chrome VRP

  • Fix shipped in 10 days

Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports without the security team.

Overview: A potential Use-After-Free (UAF) exists in the browser process's Cast Activity Manager due to unsafe handling of base::flat_map::emplace. If a route ID collision occurs when adding a new Cast activity, the activity object is freed, but its raw pointer is incorrectly stored in the app_activities_ map. An attacker can reliably trigger this collision via concurrent "auto-join" requests and subsequently exploit the dangling pointer to achieve Remote Code Execution.

Affected files:

  • chrome/browser/media/router/providers/cast/cast_activity_manager.cc
  • chrome/browser/media/router/providers/cast/cast_activity_manager.h

Estimated timestamp from git blame: 2020-07-15

Description

A potential Use-After-Free (UAF) vulnerability exists in CastActivityManager::AddAppActivity, which executes in the highly privileged browser process. The issue stems from failing to check the return value of a base::flat_map::emplace operation, leading to the storage of a dangling pointer when a key collision occurs.

In chrome/browser/media/router/providers/cast/cast_activity_manager.cc, the AddAppActivity method creates a new AppActivity and attempts to insert it into the activities_ map:

C++
AppActivity* CastActivityManager::AddAppActivity(const MediaRoute& route,
                                                 const std::string& app_id) {
  std::unique_ptr<AppActivity> activity = ...;
  auto* const activity_ptr = activity.get();
  activities_.emplace(route.media_route_id(), std::move(activity));
  app_activities_[route.media_route_id()] = activity_ptr;
  return activity_ptr;
}

When base::flat_map::emplace is called, it constructs a temporary std::pair containing the moved unique_ptr. If the key (route.media_route_id()) already exists in the map, emplace returns early without inserting the temporary pair. At the end of the expression, this temporary pair is destroyed, immediately freeing the AppActivity. However, AddAppActivity proceeds unconditionally to store the previously captured activity_ptr into the app_activities_ map.

Because app_activities_ is a standard map storing bare AppActivity* pointers, MiraclePtr (BackupRefPtr) does not protect these entries. When this dangling pointer is later accessed, it results in an exploitable UAF.

Potential Trigger and Exploitation Steps

Note: Our automated tooling agent cannot run code, so these are theoretical steps to trigger the vulnerability based on static code analysis.

An attacker can reliably trigger a route ID collision by exploiting how predictable route IDs are generated for "auto-join" presentation IDs.

  1. Setup: The victim visits an attacker-controlled site which opens two separate tabs (Tab A and Tab B) in the same origin. The victim initiates Cast Tab Mirroring from both tabs to the same local Cast sink.
  2. Race Window: Tab B's connection will prompt the receiver to terminate Tab A's session. Before the browser asynchronously cleans up Tab A's internal state, the attacker executes a ReconnectPresentation IPC from both tabs.
  3. Identical Route IDs: Both IPCs use presentation_id="auto-join" and a Cast URL specifying autoJoinPolicy=page_scoped. The kPageScoped policy causes FindActivityForAutoJoin to return nullptr, causing JoinSession to fall back to the active mirroring sinks.
  4. Collision: Both requests generate the exact same route_id (e.g., cast:auto-join/<sink_id>/<source_id>) and call LaunchSession, which delegates to AddAppActivity.
  5. The UAF: The first request successfully inserts the activity. The second request hits the emplace collision, freeing the second AppActivity but storing its dangling pointer into app_activities_, overwriting the first request's pointer.
  6. Exploitation: The attacker sprays the browser process heap to replace the freed AppActivity chunk with a controlled fake object.
  7. Execution: The attacker sends a final ReconnectPresentation request with autoJoinPolicy=origin_scoped. JoinSession iterates through app_activities_ and dereferences the dangling pointer. After passing validation checks against the fake object, the virtual method activity->AddClient(...) is invoked, allowing the attacker to hijack the control flow and achieve arbitrary Remote Code Execution (RCE) / Sandbox Escape.

Suggested Fix

Check the return value of emplace or insert to determine if the insertion was successful. Only insert the pointer into app_activities_ if the initial insertion into activities_ succeeded.

C++
AppActivity* CastActivityManager::AddAppActivity(const MediaRoute& route,
                                                 const std::string& app_id) {
  std::unique_ptr<AppActivity> activity = ...;
  auto* const activity_ptr = activity.get();
  auto result = activities_.emplace(route.media_route_id(), std::move(activity));
  if (result.second) {
    app_activities_[route.media_route_id()] = activity_ptr;
    return activity_ptr;
  }
  // Handle insertion failure (e.g., log error, return existing activity, or return nullptr)
  return nullptr;
}

Alternatively, consider changing app_activities_ to store base::WeakPtr<AppActivity> or using a safe reference holding mechanism instead of raw pointers.

Evaluated with Chrome root at commit: f200f57a19490707ff8bc7aa5de3cbc443a3afad


Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.

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

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

How it worked

Root cause

The code fails to check whether the insertion into the activities map succeeded, so it stores a pointer to an object that was freed when the insertion failed due to a duplicate key.

Impact

An attacker could potentially achieve remote code execution and sandbox escape by exploiting the dangling pointer, though the report notes the steps are theoretical and based on static analysis.

What the attacker needed

Victim visits attacker-controlled site; victim has Cast-capable browser; local Cast sink available; attacker can send IPC messages

The fix

The code should check the return value of the insertion and only store the pointer if the insertion succeeded, or use a safe reference mechanism instead of raw pointers.

How it was found

  1. The victim visits an attacker-controlled site that opens two tabs and starts Cast Tab Mirroring from both to the same local Cast sink.
  2. Tab B's connection prompts the receiver to terminate Tab A's session; before cleanup, the attacker sends a ReconnectPresentation IPC from both tabs.
  3. Both IPCs use the same presentation ID and a Cast URL with page-scoped auto-join policy, causing the same route ID to be generated.
  4. Both requests call LaunchSession, which delegates to AddAppActivity; the first inserts the activity, the second hits the emplace collision and stores a dangling pointer.
  5. The attacker sprays the heap to replace the freed object with a controlled fake object.
  6. The attacker sends a final ReconnectPresentation request with origin-scoped auto-join policy, causing the dangling pointer to be dereferenced and a virtual method to be called.

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.

A use-after-free happens when a program frees an object but keeps a pointer to it and later uses that pointer. Here, a map insertion fails because the key already exists, so the new object is freed, but its address is still saved and later used. An attacker who can cause the same key to be used twice might then control what happens when the stale pointer is used, potentially running 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 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.