Access violation on mozilla::dom::Element::BindToTree after realloc failure on AttrArray::GrowBy
When parsing HTML with DOMParser under low virtual memory, a failed reallocation in AttrArray::GrowBy leaves a null pointer that is not handled, leading to an out-of-bounds read crash in Element::BindToTree. The reporter observed the crash at several addresses and believes it is an out-of-bounds read, though the reduced testcase triggers it only rarely.
Originally disclosed on Mozilla
- Fixed in 18 days
- Paid in 25 days
- Disclosed after 18 days
Created attachment 9342007 testcase1.html
When using DOMParser.parseFromString to parse HTML innerHTML with mimeType text/html on low virtual memory, it able to crash on mozilla::dom::Element::BindToTree at address e.g. 0x002ff004, 0x003ff004, 0x004ff004, 0x008ff004, 0xe11ff004, 0xffdff004, and more.., from the CPU register and crash address it looks like out-of-bound read.
From my observation the crash occur after mozilla::dom::DOMParser::ParseFromString it went through mozilla::dom::Element::SetAttrAndNotify then on AttrArray::GrowBy it do realloc but fail, then when newImpl is nullptr the NS_ENSURE_TRUE will return false.
The reduced testcase.html has very low success rate, for now it only for demonstrate HTML code that able to trigger BindToTree AV_READ crash. It's still unknown to me what key point that make the unreduced testcase more reliable, I decided to submit this for now, then figure that later.
Tested on:
- Firefox Nightly 116.0a1 (2023-06-30) (32-bit) on Windows 11
- Firefox 114.0.2 (32-bit)
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 failed reallocation in AttrArray::GrowBy returns a null pointer that is not handled before the attribute array is used during tree binding.
Impact
The browser could crash from an out-of-bounds read, though the reduced testcase has a very low success rate and the reporter has not shown code execution.
What the attacker needed
Low virtual memory; 32-bit Firefox build; attacker-supplied HTML parsed via DOMParser
How it was found
- Open the browser under conditions of low virtual memory.
- Parse HTML containing attributes via DOMParser.parseFromString with the text/html MIME type.
- The attribute array reallocation fails and the browser crashes in Element::BindToTree.
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 a program needs more memory it asks the operating system for some; if the request fails it gets nothing back. Here the browser did not properly check that failure and carried on using the empty result, which made it read from a memory location it should not touch. That kind of mistake usually crashes the browser rather than letting someone run their own code.
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.