Skip to content
Memory corruption Disclosed report Advanced

Flat-selection slot-parent confusion causes a heap-buffer-overflow read

A logic error in Firefox's flat-tree node comparison code allows a parent node that is not actually an HTML slot element to be treated as one, causing an out-of-bounds read of heap memory. An attacker could trigger this by loading a crafted HTML page, leading to a browser crash (ASan abort) but no further exploitation is demonstrated.

Hyeonjun Ahn Follow

Originally disclosed on Mozilla

  • Fixed in 11 days
  • Paid in 17 days
  • Disclosed after 11 days

Created attachment 9606962 repro.html

Root Cause Analysis

nsContentUtils::CompareChildNodes<TreeKind::FlatForSelection> obtains the assigned slots for two child references:

C++
// dom/base/nsContentUtils.cpp:3723
HTMLSlotElement* const slot1 = aChild1->GetAssignedSlot<aKind>();
HTMLSlotElement* const slot2 = aChild2->GetAssignedSlot<aKind>();
if (slot1 || slot2) {
  if (slot1 == slot2) {
    const auto* slot = HTMLSlotElement::FromNode(aParent);
    MOZ_ASSERT(slot);
    for (nsINode* node : slot->AssignedNodes()) {
      // ...
    }
  }
}

The outer condition plus slot1 == slot2 proves that slot1 and slot2 are the same non-null HTMLSlotElement. It does not prove that aParent is that slot.

The same-container fast path in ComparePoints can call CompareClosestCommonAncestorChildren with a range-boundary container as aParent. After range mutation, that container can be the ordinary shadow host while aChild1 and aChild2 are light-DOM children assigned to the same slot. An invariant trap used only during reduction repeatedly recorded the condition as parent=host, with two distinct assigned child IDs.

HTMLSlotElement::FromNode(aParent) is therefore allowed to fail its tag check. The only guard is MOZ_ASSERT(slot), which is absent in this optimized ASan build. The following member access treats storage at the slot-only mAssignedNodes offset as a FastFrontRemovableArray. In the recorded run, that offset is immediately beyond the smaller ordinary HTMLElement object, so nsTArray::Hdr() performs the reported 8-byte OOB read.

Reproduction Steps

tested firefox commit: 0ae9827c4d7bc8b28ccbfa58324ded73b68dccf6

Build firefox with:

mk_add_options MOZ_OBJDIR=/home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser

ac_add_options --enable-project=browser
ac_add_options --enable-address-sanitizer
ac_add_options --disable-install-strip
ac_add_options --disable-jemalloc
ac_add_options --disable-crashreporter
ac_add_options --disable-profiling

# Keep stack use reasonable while retaining useful line information.
ac_add_options --enable-optimize="-O1"
ac_add_options --enable-debug-symbols=-gline-tables-only

# Optional but useful for GC-sensitive SpiderMonkey reproduction work.
ac_add_options --enable-gczeal

Listen and serve the repro.html:

Shell
python3 -m http.server 8000 --bind 127.0.0.1 

Execute:

Shell
firefox http://localhost:8000/repro.html

Result:

LOG
console.error: (new TypeError("can't access property \"find\", this._searchProviderInfo is null", "moz-src:///browser/components/search/SearchSERPTelemetry.sys.mjs", 1209))
=================================================================
==4091453==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7346ac00ce40 at pc 0x727695137cd0 bp 0x7ffeaf003950 sp 0x7ffeaf003948
READ of size 8 at 0x7346ac00ce40 thread T0 (Isolated Web Co)
/home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/bin/llvm-symbolizer: error: '[anon:js-executable-memory]': No such file or directory
    #0 0x727695137ccf in Hdr /home/slave/firefox-bug-bounty/firefox/xpcom/ds/nsTArray.h:501:51
    #1 0x727695137ccf in Elements /home/slave/firefox-bug-bounty/firefox/xpcom/ds/nsTArray.h:1048:48
    #2 0x727695137ccf in Span<AutoTArray<RefPtr<nsINode>, 0UL>, void> /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/mozilla/Span.h:593:19
    #3 0x727695137ccf in AsSpan /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/mozilla/dom/FastFrontRemovableArray.h:27:12
    #4 0x727695137ccf in operator Span /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/mozilla/dom/FastFrontRemovableArray.h:23:43
    #5 0x727695137ccf in AssignedNodes /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dist/include/mozilla/dom/HTMLSlotElement.h:53:62
    #6 0x727695137ccf in mozilla::Maybe<int> nsContentUtils::CompareChildNodes<(TreeKind)3, void>(nsINode const&, nsIContent const*, nsIContent const*, nsContentUtils::ResizableNodeIndexCache<100ul>*) /home/slave/firefox-bug-bounty/firefox/dom/base/nsContentUtils.cpp:3735:36
    ...
    mozilla::dom::ScriptLoader::ProcessInlineScript(nsIScriptElement*, JS::loader::ScriptKind, nsTSubstring<char16_t> const&) /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dom/script/./../../../firefox/dom/script/ScriptLoader.cpp:1996:10
    #32 0x72769c7ce54f in mozilla::dom::ScriptLoader::ProcessScriptElement(nsIScriptElement*, nsTSubstring<char16_t> const&) /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dom/script/./../../../firefox/dom/script/ScriptLoader.cpp:1459:10
    #33 0x72769c7cd3ff in mozilla::dom::ScriptElement::MaybeProcessScript(nsTSubstring<char16_t> const&) /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dom/script/./../../../firefox/dom/script/ScriptElement.cpp:311:18
    #34 0x72769c7cc961 in mozilla::dom::ScriptElement::MaybeProcessScript(nsCOMPtr<nsIParser>) /home/slave/firefox-bug-bounty/obj-x86_64-pc-linux-gnu-asan-browser/dom/script/./../../../firefox/dom/script/ScriptElement.cpp:182:18

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/slave/firefox-bug-bounty/firefox/xpcom/ds/nsTArray.h:501:51 in Hdr
Shadow bytes around the buggy address:
  0x7346ac00cb80: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa
  0x7346ac00cc00: fa fa fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x7346ac00cc80: fd fd fd fd fa fa fa fa fa fa fa fa 00 00 00 00
  0x7346ac00cd00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fa fa
  0x7346ac00cd80: fa fa fa fa fa fa 00 00 00 00 00 00 00 00 00 00
=>0x7346ac00ce00: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
  0x7346ac00ce80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7346ac00cf00: 00 00 fa fa fa fa fa fa fa fa 00 00 00 00 00 00
  0x7346ac00cf80: 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa
  0x7346ac00d000: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x7346ac00d080: 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==4091453==ABORTING
[Parent 4091255, IPC I/O Parent] WARNING: process 4091453 exited with status 1: file firefox/ipc/chromium/src/chrome/common/process_watcher_posix_sigchld.cc:155
console.error: AboutHomeStartupCache: "A privileged about content process shut down while cache streams were still en route."

The original report as published on Mozilla's Bugzilla, by Hyeonjun Ahn. 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 code assumes that if two child nodes share the same assigned slot, then the parent node passed to the comparison must be that slot, but after range mutation the parent can be the ordinary shadow host, so a later cast to HTMLSlotElement is invalid and leads to an out-of-bounds read.

Impact

The bug causes a heap-buffer-overflow read that aborts the browser process under AddressSanitizer; the report does not demonstrate code execution or data leakage beyond the crash.

What the attacker needed

Victim loads a crafted HTML page; browser built with AddressSanitizer

How it was found

  1. Build Firefox with AddressSanitizer and the specified options.
  2. Serve the provided repro.html file using a local HTTP server.
  3. Open the page in the built Firefox.
  4. Observe the AddressSanitizer heap-buffer-overflow report.

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.

This is a bug in how Firefox compares the positions of elements in a web page's internal tree. When a page uses a feature called 'slots' (part of web components), the browser can mistakenly think a normal element is a slot and read memory that doesn't belong to it. That causes the browser to crash, but the report does not show an attacker gaining control.

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 Hyeonjun Ahn

View all

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