Race condition in google_breakpad::CrashGenerationServer::AddClient leading to UAF write in broker (Sandbox escape / LPE)
A race condition in the Windows crash generation server allows a sandboxed process to cause a use-after-free write in the Firefox main process. An attacker with code execution in a sandboxed renderer could potentially corrupt heap memory and escape the sandbox.
Originally disclosed on Mozilla
- Fixed in 12 days
- Paid in 15 days
- Disclosed after 12 days
Created attachment 9056367
race_asan_report.txt
Hi,
There is a race condition in the Windows implementation of the CrashGenerationServer leading to a write of a freed object in Firefox main process. This crash server is enabled by default on Firefox release build and any sandboxed processes can send messages on a pipe : "\\.\pipe\gecko-crash-server-pipe.{ParentPID}" (passed to the sandbox in the command line).
The vulnerability exists in the following function:
'''cpp
bool CrashGenerationServer::AddClient(ClientInfo* client_info) {
HANDLE request_wait_handle = NULL;
/* ... */
// OnClientEnd will be called when the client process terminates.
HANDLE process_wait_handle = NULL;
if (!RegisterWaitForSingleObject(&process_wait_handle,
client_info->process_handle(),
OnClientEnd, // This callback can FREE client_info (no lock)
client_info,
INFINITE,
WT_EXECUTEONLYONCE)) {
return false;
}
client_info->set_process_exit_wait_handle(process_wait_handle); // UAF write (crash)
/* ... */
}
'''
The OnClientEnd callback frees the client_info by calling the following function:
'''cpp
CrashGenerationServer::HandleClientProcessExit(ClientInfo* client_info) { // Called by CrashGenerationServer::OnClientEnd
/* ... code that doesn't block / wait */
delete client_info; // FREE client_info
}
'''
Crash:
To compile an ASAN build of the client, you need to remove this line from the build config:
`ac_add_options --disable-crashreporter`
See attachment the ASAN crash report "race_asan_report.txt" reproduced on a local build (changeset 527669:bd1e28b0143b from Mar 29).
Exploitability:
The exploitation assumes having code execution in sandboxed renderers processes (RCE -> *LPE* step targeted).
The only way to trigger the `OnClientEnd` callback is to terminate the process being registered.
The pipe is created with maximum one instance (`nMaxInstances=1` and `FILE_FLAG_FIRST_PIPE_INSTANCE`), so you have one shot by process (you can't spray connections to `AddClient`) but the crash generation server doesn't check if the registered client is already registered and if its PID matches the caller on the pipe (one process can register anyone see `HandleReadDoneState`).
To exploit this, you can either have two threads in one process, one sending the `ProtocolMessage` to add the client and the other one terminating the process OR two sandboxed process, one registering the other process and the other killing itself.
If it's not successful, ask the broker to create a new tab (new process), replay your RCE to gain code execution and retry.
If successful, the UAF gives you a `HANDLE` write at a fixed offset in the broker heap.
By spraying an exploit convenient object (semi controlled by another IPC channel to the broker like IPDL), you can use this vulnerability to corrupt a field (size/flags) in it and with some work, achieve code execution in Firefox main process (Sandbox escape).
Thank you
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 a missing lock or synchronisation between the callback that frees the client_info object and the code that writes to it after registering the wait handle.
Impact
An attacker with code execution in a sandboxed renderer could potentially achieve code execution in the Firefox main process (sandbox escape), though the race is difficult to win and requires heap spraying.
What the attacker needed
Code execution in a sandboxed renderer; ability to send messages on the crash server pipe; winning a race condition
How it was found
- Have code execution in a sandboxed renderer process.
- Send a ProtocolMessage over the crash server pipe to register a client.
- Terminate the registered process (either from another thread or by having the process kill itself) to trigger OnClientEnd.
- If the race is won, the freed client_info is written to, causing a use-after-free write in the broker.
- If not successful, ask the broker to create a new tab (new process), replay the RCE, and retry.
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 sandboxed process (like a web page renderer) can talk to a privileged process (the broker) through a named pipe. The broker registers a callback to clean up when the sandboxed process exits, but it doesn't lock properly, so the cleanup can free memory while the broker is still writing to it. This lets an attacker who already controls a sandboxed process corrupt memory in the more privileged broker, potentially escaping the sandbox.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.