No validation of array index (key) in xul!mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes leads to Stack Out-Of-Bounds write in the broker process (Sandbox Escape / LPE)
The crash reporter's shared-memory reader in the Firefox broker process used an unvalidated 32-bit annotation key as an index into a fixed-length stack array, so a malicious sandboxed content process could write a string out of bounds. By choosing the key, an attacker with code execution in a renderer could overwrite stack objects in the unsandboxed broker and potentially escape the sandbox.
Originally disclosed on Mozilla
- Fixed in 39 hours
- Paid in 14 days
- Disclosed after 39 hours
Created attachment 9121969 stackoobw.zip
Hi,
Vulnerability
Memory corruption (Sandbox escape) in mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes tested on Firefox 72.0.2.7321
The vulnerability is in the following function:
// https://github.com/mozilla/gecko-dev/blob/master/ipc/glue/CrashReporterMetadataShmem.cpp#L210
typedef mozilla::EnumeratedArray<Annotation, Annotation::Count, nsCString> AnnotationTable;
void CrashReporterMetadataShmem::ReadAppNotes(const Shmem& aShmem,
AnnotationTable& aNotes) {
for (MetadataShmemReader reader(aShmem); !reader.Done(); reader.Next()) {
switch (reader.Type()) {
case EntryType::Annotation: {
Annotation key; // no sanitization of key (uint32_t)
nsCString value;
if (!reader.Read(&key) || !reader.Read(value)) {
return;
}
// Stack OOB write due to key (neither EnumeratedArray[] or Array[] have bounds check in release build)
aNotes[key] = value; // EnumeratedArray (fixed length) stored in stack of mozilla::ipc::CrashReporterHost::FinalizeCrashReport
break;
}
default:
NS_ASSERTION(false, "Unknown metadata entry type");
break;
}
}
}
The key variable comes from the shared memory (ShMem) without any validation and it is used as array index for storing the value string. A malicious content process (sandboxed) can modify its CrashReporterClient shared memory, crash itself to trigger the vulnerable code path in the broker process (not sandboxed) and achieve code execution outside the sandbox.
Repro and Crash
To reproduce, install Python 2.7 64 bits and PythonForWindows (https://github.com/hakril/PythonForWindows), compile payload_corrupt.cc (change offset in GetShMem if running different version then nmake) then run inject.py with the payload_corrupt.dll path.
The POC (provided - see attached files) sets the key to 0xfffffff of the first annotation and crash the content process (NULL deref).
The broker process will crash when trying to read the annotation of the crashed child:
xul!nsTSubstring<char>::Assign+0x41:
00007ff9`c3bb1041 0fb7460c movzx eax,word ptr [rsi+0Ch] ds:00000085`32ffe164=????
this = 0x00000085`32ffe158 (nsTSubstring<char>::Assign)
00000084`32ffe168 class mozilla::EnumeratedArray<CrashReporter::Annotation,CrashReporter::Annotation::Count,nsTString<char> > annotations (CrashReporterHost::FinalizeCrashReport)
? 0xfffffff * 0x10 + 0x8432ffe168 + c
Evaluate expression: 572086280548 = 00000085`32ffe164
0:000> kc
# Call Site
00 xul!nsTSubstring<char>::Assign
01 xul!nsTSubstring<char>::Assign
02 xul!nsTString<char>::operator=
03 xul!mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes
04 xul!mozilla::ipc::CrashReporterHost::FinalizeCrashReport
05 xul!mozilla::ipc::CrashReporterHost::GenerateCrashReport
06 xul!mozilla::dom::ContentParent::ActorDestroy
07 xul!mozilla::ipc::IProtocol::DestroySubtree
08 xul!mozilla::dom::PContentParent::OnChannelError
09 xul!mozilla::dom::ContentParent::OnChannelError
0a xul!mozilla::detail::RunnableMethodArguments<>::applyImpl
0b xul!mozilla::detail::RunnableMethodArguments<>::apply
0c xul!mozilla::detail::RunnableMethodImpl<mozilla::ipc::MessageChannel *,void (mozilla::ipc::MessageChannel::*)(),0,mozilla::RunnableKind::Cancelable>::Run
0d xul!nsThread::ProcessNextEvent
0e xul!NS_ProcessNextEvent
0f xul!mozilla::ipc::MessagePump::Run
10 xul!MessageLoop::RunInternal
11 xul!MessageLoop::RunHandler
12 xul!MessageLoop::Run
13 xul!nsBaseAppShell::Run
14 xul!nsAppShell::Run
15 xul!nsAppStartup::Run
16 xul!XREMain::XRE_mainRun
17 xul!XREMain::XRE_main
18 xul!XRE_main
Exploitation
The exploitation assumes having code execution in sandboxed renderers processes (RCE -> LPE step targeted).
By modifying the key (array index), we can replace objects stored in the stack frame of caller functions.
On Firefox version 72.0.2.7321 on Windows 10 x86-64, some offsets are very interesting for exploitation:
xul!nsCOMPtr_base::~nsCOMPtr_base+0xb5d [inlined in xul!nsThread::ProcessNextEvent+0x14d8]:
00007ff9`c3beab08 ff5010 call qword ptr [rax+10h] ds:41414141`41414151=???????????????? // rax controlled via the string value
0:000> kc
# Call Site
00 xul!nsCOMPtr_base::~nsCOMPtr_base
01 xul!mozilla::dom::ScriptSettingsStackEntry::~ScriptSettingsStackEntry
02 xul!mozilla::dom::AutoNoJSAPI::~AutoNoJSAPI
03 xul!mozilla::Maybe<mozilla::dom::AutoNoJSAPI>::reset
04 xul!nsThread::ProcessNextEvent
05 xul!NS_ProcessNextEvent
Definitily with some work, it is possible to achieve code execution in Firefox main process (Sandbox escape).
Thank you
Context
Firefox separates its privileged browser process (the broker) from the sandboxed processes that render web content. When a content process crashes, the broker collects crash metadata from a shared memory region owned by the crashed child and turns it into a crash report. One piece of that metadata is the set of annotations, key/value pairs where the key identifies the annotation and the value is a string.
The report concerns mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes, the function in the broker that walks the shared memory and copies each annotation into a fixed-size table. The researcher tested on Firefox 72.0.2.7321 and describes the bug as a memory corruption that allows a sandbox escape, filed under the Toolkit: Crash Reporting component and rated high severity.
Setup
Reproducing the issue requires:
- Python 2.7, 64-bit.
- PythonForWindows, from
https://github.com/hakril/PythonForWindows. - The attached proof-of-concept files (the report includes an attachment named
stackoobw.zip). - Compiling
payload_corrupt.cc; if you run a Firefox version other than the one tested, the offset used inGetShMemmust be changed before building withnmake. - Running
inject.pywith the path to the resultingpayload_corrupt.dll.
The precondition for the attack is code execution inside a sandboxed content process. The researcher frames the work explicitly as the RCE to LPE step: the attacker already controls a renderer and wants to break out of the sandbox into the broker.
Finding it
The vulnerable function reads entries from the shared memory and, for each annotation entry, reads a key and a value:
// https://github.com/mozilla/gecko-dev/blob/master/ipc/glue/CrashReporterMetadataShmem.cpp#L210
typedef mozilla::EnumeratedArray<Annotation, Annotation::Count, nsCString> AnnotationTable;
void CrashReporterMetadataShmem::ReadAppNotes(const Shmem& aShmem,
AnnotationTable& aNotes) {
for (MetadataShmemReader reader(aShmem); !reader.Done(); reader.Next()) {
switch (reader.Type()) {
case EntryType::Annotation: {
Annotation key; // no sanitization of key (uint32_t)
nsCString value;
if (!reader.Read(&key) || !reader.Read(value)) {
return;
}
// Stack OOB write due to key (neither EnumeratedArray[] or Array[] have bounds check in release build)
aNotes[key] = value; // EnumeratedArray (fixed length) stored in stack of mozilla::ipc::CrashReporterHost::FinalizeCrashReport
break;
}
default:
NS_ASSERTION(false, "Unknown metadata entry type");
break;
}
}
}
The key is read straight out of the shared memory with no validation. It is then used as the index into aNotes, an EnumeratedArray of fixed length. In a release build neither EnumeratedArray[] nor Array[] performs a bounds check, so an out-of-range key turns the assignment into a write past the end of the array. The array lives on the stack of mozilla::ipc::CrashReporterHost::FinalizeCrashReport, which is where the corruption lands.
Because the shared memory belongs to the content process, a malicious renderer can write an arbitrary key into it, crash itself, and have the broker process the poisoned metadata. The vulnerable code then runs in the broker, which is not sandboxed.
Exploitation
Step 1: Poison the shared memory and crash the child
The proof of concept sets the key of the first annotation to 0xfffffff and then crashes the content process with a NULL dereference. That crash is what triggers the broker to read the annotations of the dead child.
Step 2: Observe the broker crash
When the broker reads the annotation, it crashes inside the string assignment:
xul!nsTSubstring<char>::Assign+0x41:
00007ff9`c3bb1041 0fb7460c movzx eax,word ptr [rsi+0Ch] ds:00000085`32ffe164=????
this = 0x00000085`32ffe158 (nsTSubstring<char>::Assign)
00000084`32ffe168 class mozilla::EnumeratedArray<CrashReporter::Annotation,CrashReporter::Annotation::Count,nsTString<char> > annotations (CrashReporterHost::FinalizeCrashReport)
? 0xfffffff * 0x10 + 0x8432ffe168 + c
Evaluate expression: 572086280548 = 00000085`32ffe164
The debugger output shows the arithmetic behind the fault: the array sits at 0x8432ffe168, each element is 0x10 bytes, and the index 0xfffffff gives 0x0000008532ffe164. The call stack confirms the path from the broker's event loop down to the vulnerable function:
0:000> kc
# Call Site
00 xul!nsTSubstring<char>::Assign
01 xul!nsTSubstring<char>::Assign
02 xul!nsTString<char>::operator=
03 xul!mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes
04 xul!mozilla::ipc::CrashReporterHost::FinalizeCrashReport
05 xul!mozilla::ipc::CrashReporterHost::GenerateCrashReport
06 xul!mozilla::dom::ContentParent::ActorDestroy
07 xul!mozilla::ipc::IProtocol::DestroySubtree
08 xul!mozilla::dom::PContentParent::OnChannelError
09 xul!mozilla::dom::ContentParent::OnChannelError
0a xul!mozilla::detail::RunnableMethodArguments<>::applyImpl
0b xul!mozilla::detail::RunnableMethodArguments<>::apply
0c xul!mozilla::detail::RunnableMethodImpl<mozilla::ipc::MessageChannel *,void (mozilla::ipc::MessageChannel::*)(),0,mozilla::RunnableKind::Cancelable>::Run
0d xul!nsThread::ProcessNextEvent
0e xul!NS_ProcessNextEvent
0f xul!mozilla::ipc::MessagePump::Run
10 xul!MessageLoop::RunInternal
11 xul!MessageLoop::RunHandler
12 xul!MessageLoop::Run
13 xul!nsBaseAppShell::Run
14 xul!nsAppShell::Run
15 xul!nsAppStartup::Run
16 xul!XREMain::XRE_mainRun
17 xul!XREMain::XRE_main
18 xul!XRE_main
Step 3: Turn the write into control flow
With the index under attacker control, the write can be aimed at objects stored in the stack frames of the calling functions rather than at the array itself. On Firefox 72.0.2.7321 on Windows 10 x86-64 the researcher identified offsets that give a useful primitive. One of them is reached through nsThread::ProcessNextEvent:
xul!nsCOMPtr_base::~nsCOMPtr_base+0xb5d [inlined in xul!nsThread::ProcessNextEvent+0x14d8]:
00007ff9`c3beab08 ff5010 call qword ptr [rax+10h] ds:41414141`41414151=???????????????? // rax controlled via the string value
0:000> kc
# Call Site
00 xul!nsCOMPtr_base::~nsCOMPtr_base
01 xul!mozilla::dom::ScriptSettingsStackEntry::~ScriptSettingsStackEntry
02 xul!mozilla::dom::AutoNoJSAPI::~AutoNoJSAPI
03 xul!mozilla::Maybe<mozilla::dom::AutoNoJSAPI>::reset
04 xul!nsThread::ProcessNextEvent
05 xul!NS_ProcessNextEvent
Here the corrupted object leads to an indirect call through [rax+10h], with rax derived from the attacker-supplied string value, visible in the faulting address 4141414141414151`. The researcher states that with some work this makes code execution in the Firefox main process, and therefore a sandbox escape, achievable.
Root cause
The key read from shared memory is trusted. It is a uint32_t with no sanitisation, and it is used directly as an index into a fixed-length EnumeratedArray. Release builds omit bounds checks on EnumeratedArray[] and Array[], so nothing rejects an out-of-range key. The array is a stack local of CrashReporterHost::FinalizeCrashReport, so the out-of-bounds store corrupts the broker's stack. The trust boundary is the problem: the data crosses from a sandboxed child into the unsandboxed broker, and the broker treats it as well-formed.
Impact
An attacker who already has code execution in a sandboxed content process can write an arbitrary annotation key into the crash reporter shared memory, crash the child, and cause an out-of-bounds write in the broker process. The researcher demonstrates that the write can be shaped into an indirect call with a controlled target, and states that code execution in the Firefox main process is possible with further work. The report is rated high severity.
Fix
The report does not describe the patch that was applied. The change it implies is to validate the key before using it as an index, rejecting any value outside the valid annotation range, so that untrusted shared memory can never drive an out-of-bounds store in the broker.
Variants to test
- Other metadata readers over shared memory in the same crash reporter path: look for any field taken from the child and used as an index, length or offset without validation. A positive result is a crash in the broker with an address derived from the supplied value.
- Other
EnumeratedArrayorArrayindexing sites fed by IPC data: grep for assignments of the formarray[untrusted] = ...in code reachable from content processes. A positive result is a controlled out-of-bounds write in a release build. - Different annotation counts and key values: try keys just past the end of the array as well as very large ones, to see whether small overruns corrupt adjacent stack objects more reliably. A positive result is a stable, repeatable corruption of a specific stack slot.
- Other platforms and builds: the offsets in the report are specific to Firefox 72.0.2.7321 on Windows 10 x86-64, so re-derive them on other versions and check whether the same indirect-call primitive exists. A positive result is a controlled call target on the new build.
Hunting notes
This class of bug hides where a privileged process consumes structured data produced by a less privileged one: crash reporting, telemetry, shared memory channels and any IPC message carrying an index or length. During recon, the signal is a parser in the broker that reads a fixed-layout structure from a child-owned buffer and uses its fields directly, especially where the code comments or types hint at a fixed-size table. The researcher showed impact by starting from a realistic precondition (code execution in a renderer), demonstrating the out-of-bounds write with a debugger, computing the exact fault address from the array base and element size, and then pointing to a concrete indirect call whose target came from the attacker-controlled string. That chain, from sandboxed input to a control-flow primitive in the unsandboxed process, is what makes the case for a sandbox escape rather than a plain crash.
What happened, in plain words
Firefox is built so that the part of the browser that shows you web pages is kept apart from the part that has full power over your computer. The powerful part is called the broker (or browser process). The parts that load websites are called content processes, and they run inside a sandbox: a set of restrictions that stops them from touching files, other programs or the operating system directly. The idea is that if a website manages to take over a content process, the damage is contained.
When a content process crashes, the broker wants to write a crash report so the problem can be diagnosed. To do that, the crashed process leaves behind a small block of shared memory containing notes about the crash, called annotations. Each annotation is a pair: a key (a number that says which note it is) and a value (a piece of text). The broker reads those notes and copies them into a fixed-size table.
The bug is that the broker trusts the key completely. A malicious content process can put a huge number in the key field, crash itself on purpose, and the broker will then use that number as a position in its table. Because the number is far outside the table, the broker writes the text somewhere else in its own memory. That is a memory corruption, and because it happens in the unsandboxed broker, it can be turned into a sandbox escape: code running in the sandboxed process could, with further work, run code in the powerful process.
The researcher tested this on Firefox 72.0.2.7321 and filed it under the Toolkit: Crash Reporting component. It was rated high severity.
Context
To follow the rest of this article you only need a few ideas.
- Process: a running program. Your computer runs many at once, and each has its own private memory.
- Sandbox: a cage around a process. The process can still do its job, but it cannot reach outside the cage.
- Shared memory: a block of memory that two processes can both read and write. It is a fast way to pass data, but it means one process can hand the other data it did not create itself.
- Crash report: the summary Firefox sends when something goes wrong, including notes about what was happening.
- Annotation: one of those notes, stored as a key and a value.
- Memory corruption: when a program writes data to a place it did not intend, overwriting something else. Think of writing a long address on an envelope and having the postman deliver your letter into a stranger's house.
- Out-of-bounds write: a specific kind of memory corruption where the program writes past the end of a list or table.
- Stack: the area of memory a program uses for the short-lived data of the functions it is currently running. Overwriting it can change the values those functions rely on.
- RCE (remote code execution): an attacker gets a program to run their code. LPE (local privilege escalation): an attacker who already runs code with low privileges gets higher privileges. Here the researcher assumes the attacker already has RCE inside a sandboxed content process, and the bug provides the LPE step out of the sandbox.
Firefox keeps the broker and the content processes apart on purpose. When a content process dies, the broker collects the crash metadata from a shared memory region that the dead child owned, and turns it into a crash report. One part of that metadata is the set of annotations: key/value pairs where the key identifies the annotation and the value is a string.
The report is about mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes, the function in the broker that walks the shared memory and copies each annotation into a fixed-size table. The researcher tested on Firefox 72.0.2.7321 and describes the bug as a memory corruption that allows a sandbox escape.
Setup
To reproduce the issue you need:
- Python 2.7, 64-bit.
- PythonForWindows, from
https://github.com/hakril/PythonForWindows. - The attached proof-of-concept files. The report includes an attachment named
stackoobw.zip. - Compiling
payload_corrupt.cc. If you run a Firefox version other than the one tested, the offset used inGetShMemmust be changed before building withnmake. An offset here is a distance in bytes from a known starting point in memory; because programs are laid out slightly differently from build to build, a hard-coded offset only works for one specific version. - Running
inject.pywith the path to the resultingpayload_corrupt.dll.
The precondition for the attack is code execution inside a sandboxed content process. The researcher frames the work explicitly as the RCE to LPE step: the attacker already controls a renderer and wants to break out of the sandbox into the broker.
Finding it
The vulnerable function reads entries from the shared memory and, for each annotation entry, reads a key and a value:
// https://github.com/mozilla/gecko-dev/blob/master/ipc/glue/CrashReporterMetadataShmem.cpp#L210
typedef mozilla::EnumeratedArray<Annotation, Annotation::Count, nsCString> AnnotationTable;
void CrashReporterMetadataShmem::ReadAppNotes(const Shmem& aShmem,
AnnotationTable& aNotes) {
for (MetadataShmemReader reader(aShmem); !reader.Done(); reader.Next()) {
switch (reader.Type()) {
case EntryType::Annotation: {
Annotation key; // no sanitization of key (uint32_t)
nsCString value;
if (!reader.Read(&key) || !reader.Read(value)) {
return;
}
// Stack OOB write due to key (neither EnumeratedArray[] or Array[] have bounds check in release build)
aNotes[key] = value; // EnumeratedArray (fixed length) stored in stack of mozilla::ipc::CrashReporterHost::FinalizeCrashReport
break;
}
default:
NS_ASSERTION(false, "Unknown metadata entry type");
break;
}
}
}
Line by line, in plain words:
- The
typedefline gives a short name,AnnotationTable, to a table type.EnumeratedArrayis a fixed-length array: it has a set number of slots, decided when the program is compiled.Annotation::Countis that number. Each slot holds annsCString, which is Firefox's string type. void CrashReporterMetadataShmem::ReadAppNotes(...)declares the function. It takes the shared memory (aShmem) and the table to fill (aNotes).- The
forloop creates areaderthat walks through the shared memory entry by entry, stopping whenreader.Done()is true and moving on withreader.Next(). - The
switchlooks at the type of the current entry. Only entries of typeAnnotationare handled here. Annotation key;declares the variable that will hold the key. The comment notes there is no sanitisation: nothing checks that the number is sensible.nsCString value;declares the variable for the text.if (!reader.Read(&key) || !reader.Read(value))reads the key and then the value out of the shared memory. If either read fails, the function returns.aNotes[key] = value;is the dangerous line. It uses the key as a position in the table and stores the value there. The comment explains that this is a stack out-of-bounds write, because neitherEnumeratedArray[]norArray[]checks bounds in a release build, and because the table lives on the stack ofmozilla::ipc::CrashReporterHost::FinalizeCrashReport.- The
defaultbranch handles any other entry type and just records an assertion.
The key is read straight out of the shared memory with no validation. It is then used as the index into aNotes, an EnumeratedArray of fixed length. In a release build neither EnumeratedArray[] nor Array[] performs a bounds check, so an out-of-range key turns the assignment into a write past the end of the array. The array lives on the stack of mozilla::ipc::CrashReporterHost::FinalizeCrashReport, which is where the corruption lands.
Because the shared memory belongs to the content process, a malicious renderer can write an arbitrary key into it, crash itself, and have the broker process the poisoned metadata. The vulnerable code then runs in the broker, which is not sandboxed.
Exploitation
Step 1: Poison the shared memory and crash the child
The proof of concept sets the key of the first annotation to 0xfffffff and then crashes the content process with a NULL dereference. That crash is what triggers the broker to read the annotations of the dead child.
Why this order matters: the broker only reads the annotations when a child dies. So the attacker first writes the bad key into the shared memory, then deliberately kills the child. The broker does the rest on its own, without any further action from the attacker.
Step 2: Observe the broker crash
When the broker reads the annotation, it crashes inside the string assignment:
xul!nsTSubstring<char>::Assign+0x41:
00007ff9`c3bb1041 0fb7460c movzx eax,word ptr [rsi+0Ch] ds:00000085`32ffe164=????
this = 0x00000085`32ffe158 (nsTSubstring<char>::Assign)
00000084`32ffe168 class mozilla::EnumeratedArray<CrashReporter::Annotation,CrashReporter::Annotation::Count,nsTString<char> > annotations (CrashReporterHost::FinalizeCrashReport)
? 0xfffffff * 0x10 + 0x8432ffe168 + c
Evaluate expression: 572086280548 = 00000085`32ffe164
This is debugger output. A debugger is a tool that lets you pause a program and inspect its memory. Reading it in plain words:
- The first line says the crash happened inside a function called
nsTSubstring<char>::Assign, at 0x41 bytes into it.xulis the Firefox library where the code lives. - The second line is the machine instruction that faulted.
movzx eax,word ptr [rsi+0Ch]means "read a 16-bit value from the address held inrsiplus 0x0C and put it ineax". The address it tried to read,0000008532ffe164`, is marked with question marks, meaning the debugger could not read it: it is not valid memory. this = ...shows the object the function was working on.- The next line shows the table,
annotations, and where it lives:0x8432ffe168. - The line starting with
?is the researcher asking the debugger to do arithmetic: index times element size, plus the table's address, plus a small offset. Each element is0x10bytes, and the index is0xfffffff. - The result,
0000008532ffe164`, is the address that faulted.
The call stack confirms the path from the broker's event loop down to the vulnerable function:
0:000> kc
# Call Site
00 xul!nsTSubstring<char>::Assign
01 xul!nsTSubstring<char>::Assign
02 xul!nsTString<char>::operator=
03 xul!mozilla::ipc::CrashReporterMetadataShmem::ReadAppNotes
04 xul!mozilla::ipc::CrashReporterHost::FinalizeCrashReport
05 xul!mozilla::ipc::CrashReporterHost::GenerateCrashReport
06 xul!mozilla::dom::ContentParent::ActorDestroy
07 xul!mozilla::ipc::IProtocol::DestroySubtree
08 xul!mozilla::dom::PContentParent::OnChannelError
09 xul!mozilla::dom::ContentParent::OnChannelError
0a xul!mozilla::detail::RunnableMethodArguments<>::applyImpl
0b xul!mozilla::detail::RunnableMethodArguments<>::apply
0c xul!mozilla::detail::RunnableMethodImpl<mozilla::ipc::MessageChannel *,void (mozilla::ipc::MessageChannel::*)(),0,mozilla::RunnableKind::Cancelable>::Run
0d xul!nsThread::ProcessNextEvent
0e xul!NS_ProcessNextEvent
0f xul!mozilla::ipc::MessagePump::Run
10 xul!MessageLoop::RunInternal
11 xul!MessageLoop::RunHandler
12 xul!MessageLoop::Run
13 xul!nsBaseAppShell::Run
14 xul!nsAppShell::Run
15 xul!nsAppStartup::Run
16 xul!XREMain::XRE_mainRun
17 xul!XREMain::XRE_main
18 xul!XRE_main
A call stack is the list of functions currently running, newest at the top. Read from the bottom up, it tells the story: the program started (XRE_main), entered its main loop, was processing an event (nsThread::ProcessNextEvent), noticed the content process had gone away (ContentParent::OnChannelError), began tearing it down (ActorDestroy), decided to generate a crash report (GenerateCrashReport), finalised it (FinalizeCrashReport), called ReadAppNotes, and finally crashed while assigning the string. Every step is normal broker behaviour; only the data was hostile.
Step 3: Turn the write into control flow
With the index under attacker control, the write can be aimed at objects stored in the stack frames of the calling functions rather than at the array itself. On Firefox 72.0.2.7321 on Windows 10 x86-64 the researcher identified offsets that give a useful primitive. One of them is reached through nsThread::ProcessNextEvent:
xul!nsCOMPtr_base::~nsCOMPtr_base+0xb5d [inlined in xul!nsThread::ProcessNextEvent+0x14d8]:
00007ff9`c3beab08 ff5010 call qword ptr [rax+10h] ds:41414141`41414151=???????????????? // rax controlled via the string value
0:000> kc
# Call Site
00 xul!nsCOMPtr_base::~nsCOMPtr_base
01 xul!mozilla::dom::ScriptSettingsStackEntry::~ScriptSettingsStackEntry
02 xul!mozilla::dom::AutoNoJSAPI::~AutoNoJSAPI
03 xul!mozilla::Maybe<mozilla::dom::AutoNoJSAPI>::reset
04 xul!nsThread::ProcessNextEvent
05 xul!NS_ProcessNextEvent
Here the corrupted object leads to an indirect call through [rax+10h], with rax derived from the attacker-supplied string value, visible in the faulting address 4141414141414151`. The researcher states that with some work this makes code execution in the Firefox main process, and therefore a sandbox escape, achievable.
What this means in plain words: an indirect call is a jump to an address that is read from memory at the moment of the jump, rather than fixed in the program. If an attacker can control that address, they can make the program jump wherever they like. That is the moment a memory corruption becomes a way to steer the program.
Root cause
The key read from shared memory is trusted. It is a uint32_t (an unsigned 32-bit number) with no sanitisation, and it is used directly as an index into a fixed-length EnumeratedArray. Release builds omit bounds checks on EnumeratedArray[] and Array[], so nothing rejects an out-of-range key. The array is a stack local of CrashReporterHost::FinalizeCrashReport, so the out-of-bounds store corrupts the broker's stack. The trust boundary is the problem: the data crosses from a sandboxed child into the unsandboxed broker, and the broker treats it as well-formed.
A trust boundary is any line where data passes from a less trusted place to a more trusted one. Data crossing it should always be checked, the way a bank checks a withdrawal slip rather than trusting the number written on it.
Impact
An attacker who already has code execution in a sandboxed content process can write an arbitrary annotation key into the crash reporter shared memory, crash the child, and cause an out-of-bounds write in the broker process. The researcher demonstrates that the write can be shaped into an indirect call with a controlled target, and states that code execution in the Firefox main process is possible with further work. The report is rated high severity.
Fix
The report does not describe the patch that was applied. The change it implies is to validate the key before using it as an index, rejecting any value outside the valid annotation range, so that untrusted shared memory can never drive an out-of-bounds store in the broker.
Variants to test
- Other metadata readers over shared memory in the same crash reporter path: look for any field taken from the child and used as an index, length or offset without validation. A positive result is a crash in the broker with an address derived from the supplied value.
- Other
EnumeratedArrayorArrayindexing sites fed by IPC data: grep for assignments of the formarray[untrusted] = ...in code reachable from content processes. A positive result is a controlled out-of-bounds write in a release build. IPC stands for inter-process communication: the messages processes send each other. - Different annotation counts and key values: try keys just past the end of the array as well as very large ones, to see whether small overruns corrupt adjacent stack objects more reliably. A positive result is a stable, repeatable corruption of a specific stack slot.
- Other platforms and builds: the offsets in the report are specific to Firefox 72.0.2.7321 on Windows 10 x86-64, so re-derive them on other versions and check whether the same indirect-call primitive exists. A positive result is a controlled call target on the new build.
Hunting notes
This class of bug hides where a privileged process consumes structured data produced by a less privileged one: crash reporting, telemetry, shared memory channels and any IPC message carrying an index or length. During recon, the signal is a parser in the broker that reads a fixed-layout structure from a child-owned buffer and uses its fields directly, especially where the code comments or types hint at a fixed-size table. The researcher showed impact by starting from a realistic precondition (code execution in a renderer), demonstrating the out-of-bounds write with a debugger, computing the exact fault address from the array base and element size, and then pointing to a concrete indirect call whose target came from the attacker-controlled string. That chain, from sandboxed input to a control-flow primitive in the unsandboxed process, is what makes the case for a sandbox escape rather than a plain crash.
Glossary
- Annotation: a key/value note attached to a crash report; the key says which note it is, the value is the text.
- Broker (browser process): the privileged Firefox process that manages windows, files and the content processes.
- Call stack: the list of functions currently running, newest first, used to trace how the program reached a point.
- Content process: the sandboxed Firefox process that loads and renders web pages.
- Crash report: the summary Firefox produces when a process dies, including annotations.
- Debugger: a tool that pauses a running program and lets you inspect its memory and step through its code.
- DLL: a library file on Windows that a program can load to gain extra code.
- EnumeratedArray: a fixed-length array whose slots are named by an enumeration; its size is set at compile time.
- Indirect call: a jump to an address read from memory at run time, rather than a fixed one.
- IPC: inter-process communication, the messages processes exchange.
- LPE: local privilege escalation, going from low privileges to higher ones on the same machine.
- Memory corruption: writing data to a place the program did not intend, overwriting something else.
- Offset: a distance in bytes from a known starting point in memory.
- Out-of-bounds write: writing past the end of a list or table.
- Process: a running program with its own private memory.
- RCE: remote code execution, getting a program to run an attacker's code.
- Sandbox: restrictions that stop a process from reaching the rest of the system.
- Sandbox escape: getting code out of a sandbox into a more privileged process.
- Shared memory: a block of memory two processes can both read and write.
- Stack: the memory area holding the short-lived data of the functions currently running.
- Trust boundary: a point where data passes from a less trusted place to a more trusted one and should be checked.
- uint32_t: an unsigned 32-bit integer, a whole number from 0 to about 4.29 billion.