Use after free in Receiver (CVE-2026-87578)
A use-after-free was identified in CastMessagePortImpl::MaybeClose, where calling the client error callback can synchronously tear down and delete the object, after which the code still reads and runs its on_close_ closure. An attacker controlling a renderer could close the Mojo pipe to trigger this and potentially hijack the instruction pointer in the browser process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 3 months
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. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A potential Use-After-Free (UAF) vulnerability exists in CastMessagePortImpl::MaybeClose in the browser process. Calling client_->OnError can trigger a synchronous destruction cascade that deletes the CastMessagePortImpl instance. The code subsequently continues to execute and evaluate the on_close_ callback from the freed memory of the deleted instance.
Affected files:
components/cast_streaming/browser/cast_message_port_impl.cccomponents/cast_streaming/browser/cast_message_port_impl.h
Estimated timestamp from git blame: 2020-12-04
Description
A potential Use-After-Free (UAF) vulnerability has been identified in CastMessagePortImpl::MaybeClose() within components/cast_streaming/browser/cast_message_port_impl.cc. Under specific conditions, invoking the error callback on client_ initiates a synchronous teardown sequence on the same call stack. This sequence results in the deletion of the CastMessagePortImpl instance. When the execution unwinds back to the caller frame, the method attempts to read and execute the in-object on_close_ closure member variable on the already-freed this pointer.
Because on_close_ is a base::OnceClosure (which wraps a reference-counted BindStateBase pointer) rather than a raw_ptr, MiraclePtr (BackupRefPtr) does not protect against or mitigate this memory safety violation.
Potential Step-by-Step Sequence
(Note: These are potential steps identified through static code analysis; we do not currently have a running proof-of-concept exploit.)
- During the initial connection handshake phase when
is_initialized_is stillfalse, a connection error or channel closure is encountered on theMessagePortchannel (for example, if a compromised Renderer process abruptly closes the Mojo IPC pipe of theMessagePort). - This triggers
CastMessagePortImpl::OnPipeError(), which synchronously callsCastMessagePortImpl::MaybeClose(). - Inside
MaybeClose(),client_->OnError()is called on line 104 withkCastV2CastSocketError. client_(aReceiverSessionMessengerinstance) synchronously executesReportError(), propagating the error to the registered Open Screen callback lambda, which synchronously callsReceiverSessionClient::OnError().- Because initialization is not yet complete (
is_initialized_ == false),OnError()synchronously callsEndSession(), which triggers a sequence of termination events:ReceiverSessionImpl::OnSessionEnded()StreamingReceiverSessionClient::OnStreamingSessionEnded()StreamingRuntimeApplication::OnError()StreamingRuntimeApplication::StopApplication()
- Inside
StopApplication(),receiver_session_client_.reset()is called. This triggers a synchronous destruction cascade of all owned components, includingStreamingReceiverSessionClient,ReceiverSessionImpl,CastStreamingSession, and eventuallyCastMessagePortImpl(thisis deallocated). - The execution flow unwinds back to
CastMessagePortImpl::MaybeClose()(line 107) and evaluatesif (on_close_). Sincethishas been deleted, it performs a Use-After-Free read and subsequently callsstd::move(on_close_).Run()on line 110, allowing a potential instruction pointer hijack in the unsandboxed Browser process.
Proposed Remediation
To prevent this vulnerability, use a base::WeakPtr to check for the instance's liveness before accessing any member variables or running callbacks after client_->OnError() is called.
Add a base::WeakPtrFactory<CastMessagePortImpl> weak_factory_{this}; to CastMessagePortImpl and update MaybeClose to:
void CastMessagePortImpl::MaybeClose() {
base::WeakPtr<CastMessagePortImpl> weak_this = weak_factory_.GetWeakPtr();
if (message_port_) {
message_port_.reset();
}
if (client_) {
client_->OnError(
openscreen::Error(openscreen::Error::Code::kCastV2CastSocketError));
}
if (weak_this && weak_this->on_close_) {
std::move(weak_this->on_close_).Run();
}
}
Evaluated with Chrome root at commit: b1520ef4a76878853a31f0943b565e42060edec8
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
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.
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 error callback runs synchronously and destroys the object, but the method does not check that the instance is still alive before touching its members.
Impact
A compromised renderer could potentially hijack the instruction pointer in the unsandboxed browser process, though no working exploit was demonstrated.
What the attacker needed
Compromised renderer; error during initial handshake
The fix
It should be fixed by holding a weak pointer and checking liveness before accessing members or running callbacks after the error callback.
How it was found
- A connection error or channel closure occurs on the MessagePort while the object is not yet initialised.
- OnPipeError synchronously calls MaybeClose.
- MaybeClose calls the client error callback.
- The error propagates and, since initialisation is incomplete, EndSession runs and tears down the session.
- StopApplication resets the session client, destroying CastMessagePortImpl.
- Execution returns to MaybeClose, which reads and runs on_close_ on the freed object.
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 a program frees an object but keeps using it, that is a use-after-free. Here, reporting an error causes the object to be destroyed while the same function is still running, so it then reads memory that no longer belongs to it. Because this happens in the browser process, which has more privileges, an attacker might be able to take control of the program.
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.