Use after free in Media Router (CVE-2024-8637)
A use-after-free occurs in Chrome's Media Router on Android because the Java dialog controller holds a raw pointer to a native object that can be destroyed while the dialog remains open. An attacker could trigger a crash or potentially execute code by causing the dialog to stay open after the native controller is freed.
- Fix shipped in 19 days
Steps to reproduce the problem
repro:
- apply patch.
- host poc.html
- click
presentationRequst.start()button - wait tab close. then uaf.
see mov.
Problem Description
- variant of pattern the issue 358296941. there didn't dismiss view after
MediaRouterDialogControllerAndroiddestuct.
MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {}
- Then the java port exists a
raw pointertoMediaRouterDialogControllerAndroid
public class BrowserMediaRouterDialogController implements MediaRouteDialogDelegate {
private static final String MEDIA_ROUTE_CONTROLLER_DIALOG_FRAGMENT =
"android.support.v7.mediarouter:MediaRouteControllerDialogFragment";
private final long mNativeDialogController;
private BaseMediaRouteDialogManager mDialogManager;
private WebContents mWebContents;
-------------------------------------------------------------------------------------
MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid(
WebContents* web_contents)
: content::WebContentsUserData<MediaRouterDialogControllerAndroid>(
*web_contents),
MediaRouterDialogController(web_contents) {
JNIEnv* env = base::android::AttachCurrentThread();
java_dialog_controller_.Reset(Java_BrowserMediaRouterDialogController_create(
env, reinterpret_cast<jlong>(this), web_contents->GetJavaWebContents()));
- So if you call the JNI callback here after destruction, it will cause UAF
@Override
public void onSinkSelected(String sourceUrn, MediaSink sink) {
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onSinkSelected(
mNativeDialogController,
BrowserMediaRouterDialogController.this,
sourceUrn,
sink.getId());
}
@Override
public void onRouteClosed(String mediaRouteId) {
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onRouteClosed(
mNativeDialogController,
BrowserMediaRouterDialogController.this,
mediaRouteId);
}
@Override
public void onDialogCancelled() {
// For MediaRouteControllerDialog this method will be called in case the route is closed
// since it only call onDismiss() and there's no way to distinguish between the two.
// Here we can figure it out: if mDialogManager is null, onRouteClosed() was called and
// there's no need to tell the native controller the dialog has been cancelled.
if (mDialogManager == null) return;
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onDialogCancelled(
mNativeDialogController, BrowserMediaRouterDialogController.this);
}
[0].https://source.chromium.org/chromium/chromium/src/+/main:components/media_router/browser/android/media_router_dialog_controller_android.cc;l=135;bpv=0;bpt=1 [1].https://source.chromium.org/chromium/chromium/src/+/main:components/media_router/browser/android/java/src/org/chromium/components/media_router/BrowserMediaRouterDialogController.java;l=28?q=OnMediaSourceNotSupported&ss=chromium%2Fchromium%2Fsrc [2].https://source.chromium.org/chromium/chromium/src/+/main:components/media_router/browser/android/java/src/org/chromium/components/media_router/BrowserMediaRouterDialogController.java;l=117?q=OnMediaSourceNotSupported&ss=chromium%2Fchromium%2Fsrc
bitset: https://source.chromium.org/chromium/chromium/src/+/52efd93fe1dee30d791a21f844b563fa4d375b50
why need patch:
I don't have a device that my phone can scan, so I had to fake a few devices, but it seems that I didn't add them successfully. I originally wanted to trigger the onSinkSelected callback, but it seems that this works, and the patch does not affect the code logic.
Summary
heap-use-after-free on media_router::MediaRouterDialogControllerAndroid::CancelPresentationRequest
Custom Questions
Type of crash:
browser
Crash state:
see asan.log
Additional Data
Category: Security
Chrome Channel: Not sure
Regression: N/A
Context
This report describes a use after free in Chrome's Media Router component on Android, tracked as CVE-2024-8637 and disclosed on 10 September 2024 through the Chrome VRP. The researcher is credited as lime (@limeSec_) from TIANGONG Team of Legendsec at QI-ANXIN Group. The platform records the severity as high and the bounty as 11,000.00 USD. The report itself does not state a CVSS score.
Media Router is the Chrome feature that lets a page discover and control remote playback devices, for example casting media to a television. On Android, the browser side of this feature is split between native C++ code and Java code. The C++ class MediaRouterDialogControllerAndroid owns a Java object, BrowserMediaRouterDialogController, and the Java object holds a raw handle back to the native controller. The dialog that the user sees when choosing a route is managed across that boundary.
The bug is a lifetime problem: the native controller can be destroyed while the Java object still holds its handle, and a later JNI callback from Java into native code then touches freed memory. The crash state given in the report is heap-use-after-free on media_router::MediaRouterDialogControllerAndroid::CancelPresentationRequest.
Setup
The report gives very little environment detail. It does not name a Chrome version, a build configuration, an Android version or a device. What it does say is:
- The researcher needed a patch applied to the build before reproducing.
- A proof of concept page,
poc.html, has to be hosted. - The reproduction is driven by clicking a button on that page.
- The crash is observed after the tab closes.
- The researcher refers to a video ("see mov") showing the run, but no media is attached to the text supplied here.
The researcher writes that they did not have a device that their phone could scan, so they had to fake a few devices, but it seems they did not add them successfully. The original intention was to trigger the onSinkSelected callback, but the researcher notes that the reproduction works anyway and that the patch does not affect the code logic. In other words, the patch is a test aid for creating fake media sinks, not part of the vulnerability.
The report references a specific Chromium revision for the source links: [redacted].
Finding it
The researcher describes the issue as a variant of an earlier pattern, issue 358296941. The observation is that the view is not dismissed after MediaRouterDialogControllerAndroid is destroyed. The destructor in the report is empty:
MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {}
Because the destructor does nothing to invalidate the Java side, the Java port keeps a raw pointer to the native controller. The report shows the Java class holding a native handle as a long:
public class BrowserMediaRouterDialogController implements MediaRouteDialogDelegate {
private static final String MEDIA_ROUTE_CONTROLLER_DIALOG_FRAGMENT =
"android.support.v7.mediarouter:MediaRouteControllerDialogFragment";
private final long mNativeDialogController;
private BaseMediaRouteDialogManager mDialogManager;
private WebContents mWebContents;
The native constructor passes its own address into Java when it creates the Java object:
MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid(
WebContents* web_contents)
: content::WebContentsUserData<MediaRouterDialogControllerAndroid>(
*web_contents),
MediaRouterDialogController(web_contents) {
JNIEnv* env = base::android::AttachCurrentThread();
java_dialog_controller_.Reset(Java_BrowserMediaRouterDialogController_create(
env, reinterpret_cast<jlong>(this), web_contents->GetJavaWebContents()));
The reinterpret_cast<jlong>(this) is the raw pointer in question. It is stored in mNativeDialogController on the Java object and is used as the first argument of every JNI call back into native code. If the native object is gone but the Java object survives, those calls pass a dangling address.
The researcher's conclusion is direct: if you call the JNI callback after destruction, it causes a use after free.
Exploitation
Step 1: apply the patch
The first step in the reproduction is to apply the patch. The report does not include the patch contents. It only explains the motivation: the researcher had no scannable device and wanted to fake media devices, and the patch does not change the code logic. Treat this as a lab aid for producing a media sink, not as part of the attack.
Step 2: host the proof of concept page
The second step is to host poc.html. The report does not include the page source, so the exact HTML and JavaScript are not available here. What the report does show is the user interaction it relies on: a button that calls presentationRequst.start(). The name is spelled that way in the original.
Step 3: click the button
The third step is to click the presentationRequst.start() button. This is the action that starts a presentation request, which is what brings the Media Router dialog machinery into play on Android. The report does not describe the page's response or any network traffic.
Step 4: wait for the tab to close
The fourth step is to wait for the tab to close. The report states that the use after free follows: "wait tab close. then uaf." The crash state recorded is heap-use-after-free on media_router::MediaRouterDialogControllerAndroid::CancelPresentationRequest, and the report points to an asan.log for the crash state, though that log is not included in the text supplied here.
The mechanism the researcher describes is that the native controller is destroyed while the Java dialog controller still exists, and a subsequent JNI callback from Java into native code dereferences the stale handle. The report shows three Java callbacks that forward to native code through mNativeDialogController:
@Override
public void onSinkSelected(String sourceUrn, MediaSink sink) {
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onSinkSelected(
mNativeDialogController,
BrowserMediaRouterDialogController.this,
sourceUrn,
sink.getId());
}
@Override
public void onRouteClosed(String mediaRouteId) {
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onRouteClosed(
mNativeDialogController,
BrowserMediaRouterDialogController.this,
mediaRouteId);
}
@Override
public void onDialogCancelled() {
// For MediaRouteControllerDialog this method will be called in case the route is closed
// since it only call onDismiss() and there's no way to distinguish between the two.
// Here we can figure it out: if mDialogManager is null, onRouteClosed() was called and
// there's no need to tell the native controller the dialog has been cancelled.
if (mDialogManager == null) return;
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onDialogCancelled(
mNativeDialogController, BrowserMediaRouterDialogController.this);
}
Each of these passes mNativeDialogController as the native receiver. If the native object has already been freed, the native side of the call operates on freed memory. The report's summary names CancelPresentationRequest as the function where the crash is observed, which is consistent with the dialog being torn down around the time the tab closes.
It also does not state whether the crash is reachable from a normal web page without the patch, only that the patch was needed in the researcher's environment to provide fake devices.
Root cause
The root cause is a lifetime mismatch across the C++/Java boundary. The native MediaRouterDialogControllerAndroid is a WebContentsUserData tied to the WebContents. Its destructor is empty, so it does not tell the Java BrowserMediaRouterDialogController that the native object is going away. The Java object keeps mNativeDialogController, a raw jlong copy of the native this pointer, and uses it for every JNI callback.
When the native controller is destroyed first, for example as the tab closes, the Java object can still receive dialog delegate callbacks such as onSinkSelected, onRouteClosed or onDialogCancelled. Those callbacks forward the stale handle to native code, and the native side dereferences freed memory. The report's own summary is that the view is not dismissed after destruction, which is what leaves the Java side alive long enough to call back.
Why existing defences did not stop it: the report does not discuss any. The empty destructor is shown as the code that fails to invalidate the Java side, and the raw pointer is shown as the value that becomes stale. Whether any other check exists on the native side is not stated in the report.
Impact
The report classifies the crash as a browser crash and records the severity as high. The practical effect demonstrated is a use after free in the browser process triggered by a page that starts a presentation request and by the tab being closed, in the researcher's environment where a patch was applied.
Fix
It only identifies the defect: the destructor does not dismiss or invalidate the Java dialog controller, and the Java side keeps a raw pointer to the native object. The report does not include a patch for the vulnerability itself.
Variants to test
- Other
WebContentsUserDataclasses that handreinterpret_cast<jlong>(this)to a Java object and are destroyed with the tab. A positive result is a Java callback arriving after the native destructor and an ASan report naming the native method. - Other dialog delegate callbacks on the same Java class, beyond the three shown. A positive result is any callback that forwards
mNativeDialogControllerafter the native object is freed. - Presentation request flows that leave the dialog open while the tab or
WebContentsis torn down. A positive result is the same use after free withCancelPresentationRequestor a neighbouring function in the stack. - The earlier issue referenced as 358296941, to see whether the same pattern was only partially fixed. A positive result is a related lifetime gap in the same dialog controller code.
- Fake or emulated media sinks in a test build, as the researcher did, to check whether the callback path is reachable without physical casting hardware. A positive result is a reliable crash with the test aid applied and no change to the code logic under test.
What happened, in plain words
This is a bug report about Google Chrome, the web browser. It describes a memory safety bug in a Chrome feature called Media Router, which is the part of Chrome that lets a web page find and control playback devices on your network, for example a television you can cast a video to. On Android phones, this feature is built from two halves that talk to each other: a lower level half written in C++ and a higher level half written in Java. The bug is that one half can be thrown away while the other half still keeps a note of where it used to be, and then tries to use that note. When a program uses a note that points to memory it has already given back, that is called a use after free. It is like writing down a friend's old address, the friend moves out, and you keep posting letters there: the letters go to whoever lives there now, which is not your friend and may not be friendly at all.
The bug is tracked as CVE-2024-8637. A CVE is a public catalogue number for a known security flaw, so people can refer to the same bug unambiguously. It was disclosed on 10 September 2024 through the Chrome VRP. The VRP, the Vulnerability Reward Program, is Google's scheme that pays people for finding and reporting security bugs in Chrome. The researcher is credited as lime (@limeSec_) from TIANGONG Team of Legendsec at QI-ANXIN Group. The platform records the severity as high and the bounty as 11,000.00 USD. The report itself does not state a CVSS score. CVSS is a standard scoring system for how serious a vulnerability is; the report simply does not give one.
Media Router is the Chrome feature that lets a page discover and control remote playback devices, for example casting media to a television. On Android, the browser side of this feature is split between native C++ code and Java code. C++ and Java are two programming languages. Native code here means the C++ code that runs directly on the device, as opposed to Java code that runs inside the Android runtime. The C++ class MediaRouterDialogControllerAndroid owns a Java object, BrowserMediaRouterDialogController, and the Java object holds a raw handle back to the native controller. A class is a blueprint for an object in object oriented programming; an object is one concrete thing built from that blueprint. A raw handle, or raw pointer, is just a number that records a memory address, with no safety net: nothing checks that the address still points at something valid. The dialog that the user sees when choosing a route is managed across that boundary. A dialog is the pop up window that asks you to pick something, here the playback route.
The bug is a lifetime problem: the native controller can be destroyed while the Java object still holds its handle, and a later JNI callback from Java into native code then touches freed memory. JNI, the Java Native Interface, is the standard bridge that lets Java code call into C++ code and the other way round. A callback is a function that one side hands to the other so it can be called later, for example when something happens. The crash state given in the report is heap-use-after-free on media_router::MediaRouterDialogControllerAndroid::CancelPresentationRequest. The heap is the region of memory a program uses for objects it creates while running; a use after free on the heap means the program read or wrote memory there after handing it back.
Setup
The report gives very little environment detail. It does not name a Chrome version, a build configuration, an Android version or a device. What it does say is:
- The researcher needed a patch applied to the build before reproducing. A patch is a small change to source code, applied before compiling the program. A build is the compiled program produced from source code.
- A proof of concept page,
poc.html, has to be hosted. A proof of concept, or PoC, is a minimal example that demonstrates a bug. Hosting means putting the file on a web server so a browser can load it. - The reproduction is driven by clicking a button on that page.
- The crash is observed after the tab closes.
- The researcher refers to a video ("see mov") showing the run, but no media is attached to the text supplied here.
The researcher writes that they did not have a device that their phone could scan, so they had to fake a few devices, but it seems they did not add them successfully. The original intention was to trigger the onSinkSelected callback, but the researcher notes that the reproduction works anyway and that the patch does not affect the code logic. In other words, the patch is a test aid for creating fake media sinks, not part of the vulnerability. A media sink is the device that receives and plays the media, such as a television or a speaker. Faking one means making the software believe such a device exists when no real hardware is present.
The report references a specific Chromium revision for the source links: [redacted]. Chromium is the open source project that Chrome is built from. A revision is a specific saved state of the source code, identified by a long hash string, so links point at exactly the code the researcher looked at.
Finding it
The researcher describes the issue as a variant of an earlier pattern, issue 358296941. A variant means the same kind of mistake appearing again in a related place. The observation is that the view is not dismissed after MediaRouterDialogControllerAndroid is destroyed. The view here is the on screen dialog. Dismissed means closed and cleaned up. The destructor in the report is empty:
MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {}
Line by line: MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() is the destructor of the class. A destructor is the special function that runs automatically when an object is destroyed, and it is where cleanup is normally done. The ~ symbol marks it as a destructor. The braces {} are empty, meaning the function does nothing at all. So when the native controller is destroyed, no cleanup happens on the Java side.
Because the destructor does nothing to invalidate the Java side, the Java port keeps a raw pointer to the native controller. To invalidate here means to mark the handle as no longer usable, so later code knows not to touch it. The report shows the Java class holding a native handle as a long:
public class BrowserMediaRouterDialogController implements MediaRouteDialogDelegate {
private static final String MEDIA_ROUTE_CONTROLLER_DIALOG_FRAGMENT =
"android.support.v7.mediarouter:MediaRouteControllerDialogFragment";
private final long mNativeDialogController;
private BaseMediaRouteDialogManager mDialogManager;
private WebContents mWebContents;
Line by line: public class BrowserMediaRouterDialogController implements MediaRouteDialogDelegate { declares a Java class named BrowserMediaRouterDialogController. public means other code can use it. implements MediaRouteDialogDelegate means it promises to provide the methods that the MediaRouteDialogDelegate interface requires; an interface is a contract listing methods a class must have. The next line, private static final String MEDIA_ROUTE_CONTROLLER_DIALOG_FRAGMENT =, declares a constant text value. private means only this class can see it, static means it belongs to the class rather than to one object, and final means it cannot be changed after it is set. The following line is the text value itself, "android.support.v7.mediarouter:MediaRouteControllerDialogFragment", which is an identifier string for the dialog fragment. A fragment is an Android building block for a piece of a screen. Then private final long mNativeDialogController; declares a field named mNativeDialogController of type long, a 64 bit integer. This is the raw handle: a number that is really a memory address on the native side. private means only this class can read it, and final means it is set once and never reassigned. private BaseMediaRouteDialogManager mDialogManager; declares a field holding a reference to a dialog manager object, or nothing at all. private WebContents mWebContents; declares a field holding a reference to the WebContents object. WebContents is Chrome's internal representation of the contents of one tab.
The native constructor passes its own address into Java when it creates the Java object:
MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid(
WebContents* web_contents)
: content::WebContentsUserData<MediaRouterDialogControllerAndroid>(
*web_contents),
MediaRouterDialogController(web_contents) {
JNIEnv* env = base::android::AttachCurrentThread();
java_dialog_controller_.Reset(Java_BrowserMediaRouterDialogController_create(
env, reinterpret_cast<jlong>(this), web_contents->GetJavaWebContents()));
Line by line: MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( starts the definition of the constructor, the function that runs when a new object of this class is created. WebContents* web_contents) is its parameter: a pointer to a WebContents, the tab contents. : content::WebContentsUserData<MediaRouterDialogControllerAndroid>( begins the initialiser list, which sets up base classes before the body runs. WebContentsUserData is a helper template that ties an object's lifetime to a WebContents; a template is a blueprint that can be specialised for different types. *web_contents), passes the tab contents by reference to that base class. MediaRouterDialogController(web_contents) { initialises the other base class with the same tab contents, then opens the constructor body. JNIEnv* env = base::android::AttachCurrentThread(); gets a handle to the current thread's JNI environment, which is needed for any JNI call, and stores it in env. java_dialog_controller_.Reset( resets a holder that keeps a reference to the Java object, so it points at a new Java object. Java_BrowserMediaRouterDialogController_create( is the generated JNI function that calls the Java side to create the Java object. env, passes the JNI environment. reinterpret_cast<jlong>(this) takes the address of the current native object, this, and reinterprets it as a Java long. This is the raw pointer in question. web_contents->GetJavaWebContents())); passes the Java side counterpart of the tab contents and closes the call.
The reinterpret_cast<jlong>(this) is the raw pointer in question. It is stored in mNativeDialogController on the Java object and is used as the first argument of every JNI call back into native code. If the native object is gone but the Java object survives, those calls pass a dangling address. Dangling means the address no longer refers to a live object.
The researcher's conclusion is direct: if you call the JNI callback after destruction, it causes a use after free.
Exploitation
Step 1: apply the patch
The first step in the reproduction is to apply the patch. The report does not include the patch contents. It only explains the motivation: the researcher had no scannable device and wanted to fake media devices, and the patch does not change the code logic. Treat this as a lab aid for producing a media sink, not as part of the attack. In other words, the patch is only there so the test machine has something to cast to, like a stand in television.
Step 2: host the proof of concept page
The second step is to host poc.html. The report does not include the page source, so the exact HTML and JavaScript are not available here. HTML is the language web pages are written in, and JavaScript is the programming language browsers run inside pages. What the report does show is the user interaction it relies on: a button that calls presentationRequst.start(). The name is spelled that way in the original. A presentation request is the browser feature that asks to start showing content on another screen or device; start() is the method that begins that request.
Step 3: click the button
The third step is to click the presentationRequst.start() button. This is the action that starts a presentation request, which is what brings the Media Router dialog machinery into play on Android. The report does not describe the page's response or any network traffic.
Step 4: wait for the tab to close
The fourth step is to wait for the tab to close. The report states that the use after free follows: "wait tab close. then uaf." The crash state recorded is heap-use-after-free on media_router::MediaRouterDialogControllerAndroid::CancelPresentationRequest, and the report points to an asan.log for the crash state, though that log is not included in the text supplied here. ASan, AddressSanitizer, is a debugging tool built into the program that detects memory errors such as use after free and writes a log describing them.
The mechanism the researcher describes is that the native controller is destroyed while the Java dialog controller still exists, and a subsequent JNI callback from Java into native code dereferences the stale handle. To dereference means to follow a pointer to read or write the memory it points at. The report shows three Java callbacks that forward to native code through mNativeDialogController:
@Override
public void onSinkSelected(String sourceUrn, MediaSink sink) {
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onSinkSelected(
mNativeDialogController,
BrowserMediaRouterDialogController.this,
sourceUrn,
sink.getId());
}
@Override
public void onRouteClosed(String mediaRouteId) {
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onRouteClosed(
mNativeDialogController,
BrowserMediaRouterDialogController.this,
mediaRouteId);
}
@Override
public void onDialogCancelled() {
// For MediaRouteControllerDialog this method will be called in case the route is closed
// since it only call onDismiss() and there's no way to distinguish between the two.
// Here we can figure it out: if mDialogManager is null, onRouteClosed() was called and
// there's no need to tell the native controller the dialog has been cancelled.
if (mDialogManager == null) return;
mDialogManager = null;
BrowserMediaRouterDialogControllerJni.get()
.onDialogCancelled(
mNativeDialogController, BrowserMediaRouterDialogController.this);
}
Line by line: @Override is an annotation telling the compiler this method replaces one declared by the interface; the compiler checks that a matching method really exists. public void onSinkSelected(String sourceUrn, MediaSink sink) { declares a method that runs when a sink is chosen. void means it returns nothing. String sourceUrn is the identifier of the media source, and MediaSink sink is the chosen sink object. mDialogManager = null; clears the reference to the dialog manager, marking that the dialog is no longer managed here. BrowserMediaRouterDialogControllerJni.get() gets the generated JNI bridge object that lets Java call the native methods. .onSinkSelected( calls the native method of the same name. mNativeDialogController, passes the stored raw handle as the native receiver, which is the address the native side will treat as the object. BrowserMediaRouterDialogController.this, passes the Java object itself back to native code. sourceUrn, passes the source identifier. sink.getId()); passes the sink's identifier and closes the call. } closes the method.
The second block, @Override public void onRouteClosed(String mediaRouteId) {, declares the method that runs when a route is closed, taking the route identifier as text. mDialogManager = null; clears the dialog manager reference. BrowserMediaRouterDialogControllerJni.get().onRouteClosed( calls the native method of the same name. mNativeDialogController, passes the raw handle again. BrowserMediaRouterDialogController.this, passes the Java object. mediaRouteId); passes the route identifier and closes the call. } closes the method.
The third block, @Override public void onDialogCancelled() {, declares the method that runs when the dialog is cancelled. The comment lines explain that for the controller dialog this method is also called when the route is closed, because that path only calls onDismiss() and there is no way to tell the two apart. The comment says the code can work it out: if mDialogManager is null, onRouteClosed() was already called, so there is no need to tell the native controller the dialog was cancelled. if (mDialogManager == null) return; checks that condition and returns early if true. mDialogManager = null; clears the reference. BrowserMediaRouterDialogControllerJni.get().onDialogCancelled( calls the native method. mNativeDialogController, BrowserMediaRouterDialogController.this); passes the raw handle and the Java object, then closes the call. } closes the method.
Each of these passes mNativeDialogController as the native receiver. If the native object has already been freed, the native side of the call operates on freed memory. The report's summary names CancelPresentationRequest as the function where the crash is observed, which is consistent with the dialog being torn down around the time the tab closes.
A stack trace is the list of function calls that led to the crash. An allocation site is where memory was handed out, and a free site is where it was handed back. It also does not state whether the crash is reachable from a normal web page without the patch, only that the patch was needed in the researcher's environment to provide fake devices.
Root cause
The root cause is a lifetime mismatch across the C++/Java boundary. The native MediaRouterDialogControllerAndroid is a WebContentsUserData tied to the WebContents. Its destructor is empty, so it does not tell the Java BrowserMediaRouterDialogController that the native object is going away. The Java object keeps mNativeDialogController, a raw jlong copy of the native this pointer, and uses it for every JNI callback. jlong is the JNI type name for a Java long used across the bridge.
When the native controller is destroyed first, for example as the tab closes, the Java object can still receive dialog delegate callbacks such as onSinkSelected, onRouteClosed or onDialogCancelled. Those callbacks forward the stale handle to native code, and the native side dereferences freed memory. The report's own summary is that the view is not dismissed after destruction, which is what leaves the Java side alive long enough to call back.
Why existing defences did not stop it: the report does not discuss any. The empty destructor is shown as the code that fails to invalidate the Java side, and the raw pointer is shown as the value that becomes stale. Whether any other check exists on the native side is not stated in the report.
Impact
The report classifies the crash as a browser crash and records the severity as high. Code execution means making the program run an attacker's instructions. A sandbox is the isolation layer that limits what a compromised part of the browser can do. Data disclosure means leaking information. The practical effect demonstrated is a use after free in the browser process triggered by a page that starts a presentation request and by the tab being closed, in the researcher's environment where a patch was applied. Stock device means an ordinary phone with normal software, not a modified test build.
Fix
It only identifies the defect: the destructor does not dismiss or invalidate the Java dialog controller, and the Java side keeps a raw pointer to the native object. The report does not include a patch for the vulnerability itself.
Variants to test
- Other
WebContentsUserDataclasses that handreinterpret_cast<jlong>(this)to a Java object and are destroyed with the tab. A positive result is a Java callback arriving after the native destructor and an ASan report naming the native method. - Other dialog delegate callbacks on the same Java class, beyond the three shown. A positive result is any callback that forwards
mNativeDialogControllerafter the native object is freed. - Presentation request flows that leave the dialog open while the tab or
WebContentsis torn down. A positive result is the same use after free withCancelPresentationRequestor a neighbouring function in the stack. - The earlier issue referenced as 358296941, to see whether the same pattern was only partially fixed. A positive result is a related lifetime gap in the same dialog controller code.
- Fake or emulated media sinks in a test build, as the researcher did, to check whether the callback path is reachable without physical casting hardware. A positive result is a reliable crash with the test aid applied and no change to the code logic under test.
Glossary
- API: a defined set of functions one piece of software offers to another so they can talk to each other.
- ASan (AddressSanitizer): a debugging tool built into a program that detects memory errors such as use after free and writes a log.
- Bounty: money paid by a company to a researcher who reports a valid security bug.
- Build: the compiled program produced from source code.
- Callback: a function handed to another part of the program so it can be called later when something happens.
- Chrome VRP: Google's Vulnerability Reward Program for Chrome, which pays for security bug reports.
- Chromium: the open source project that Chrome is built from.
- Class: a blueprint in object oriented programming that describes the data and methods of an object.
- Code execution: making a program run instructions chosen by an attacker.
- Constructor: the function that runs when a new object is created.
- C++: a compiled programming language used for native code.
- CVE: a public catalogue number for a known security vulnerability.
- CVSS: a standard scoring system for the severity of a vulnerability.
- Dangling pointer: a pointer whose target memory has already been freed.
- Data disclosure: leaking information to someone who should not have it.
- Dereference: following a pointer to read or write the memory it points at.
- Destructor: the function that runs automatically when an object is destroyed, normally used for cleanup.
- Dialog: a pop up window that asks the user to choose or confirm something.
- Dismiss: close and clean up a dialog.
- Fragment: an Android building block for a piece of a screen.
- Heap: the region of memory a program uses for objects created while it runs.
- HTML: the language web pages are written in.
- Interface: a contract listing methods a class must provide.
- Invalidate: mark a handle or value as no longer usable.
- Java: a programming language that runs inside the Android runtime.
- JavaScript: the programming language browsers run inside web pages.
- JNI (Java Native Interface): the standard bridge that lets Java code call C++ code and the other way round.
- jlong: the JNI type name for a Java
longpassed across the bridge. - Media Router: the Chrome feature that discovers and controls remote playback devices.
- Media sink: the device that receives and plays media, such as a television or speaker.
- Native code: code that runs directly on the device, here the C++ side.
- Object: one concrete thing built from a class.
- Patch: a small change to source code, usually applied before compiling.
- Pointer: a number that records a memory address.
- Proof of concept (PoC): a minimal example that demonstrates a bug.
- Raw pointer / raw handle: a memory address stored with no safety checks.
- Revision: a specific saved state of source code, identified by a hash string.
- Sandbox: the isolation layer that limits what a compromised part of the browser can do.
- Severity: a rating of how serious a vulnerability is.
- Stack trace: the list of function calls that led to a crash.
- Template: a blueprint in C++ that can be specialised for different types.
- Use after free: a memory safety bug where a program uses memory after handing it back.
- Variant: the same kind of mistake appearing again in a related place.
- WebContents: Chrome's internal representation of the contents of one tab.