Open Bug 2090055 Opened 13 days ago Updated 13 days ago

Crash in Element::GetAttrAssociatedElementsForBindings when an ARIA element reflection property is read from two JS worlds

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 159
defect

Tracking

()

ASSIGNED

People

(Reporter: bartosz.work, Assigned: bartosz.work)

Details

Attachments

(2 files, 1 external file)

Steps to reproduce:

  1. Load firefox-only/extension from https://github.com/bartech-lab/firefox-aria-reflection-crash as a temporary add-on. Its content script runs:

    document.getElementById('b')?.ariaLabelledByElements;
    
  2. Open this page over http:

    <!doctype html><span id="l">Save</span><button id="b" aria-labelledby="l"></button>
    <script>document.getElementById('b').ariaLabelledByElements;</script>
    

Scripted steps, with pinned downloads: firefox-only/reproduce.sh in the same repo.

Actual result:
The tab crashes with SIGSEGV.

Expected result:
Both reads return the element list, and the tab stays alive.

Cause:
The generated getter passes hasCachedValue ? &useCachedValue : nullptr, and hasCachedValue is per JS world. cachedAttrElements is per element. So the second world passes null, GetAttrAssociatedElementsForBindings finds elements == cachedAttrElements, and *aUseCachedValue = true writes through null. A local optimized build shows aUseCachedValue=0x0 in the crashing frame, with fault address 0x0.

Bug 2045887 fixed the same write in ElementInternals::GetAttrElements (06a3d64fbbef). Element.cpp still lacks that guard at d9bd6be9a67e.

Fix, attached with a chrome mochitest:

- if (elements && elements == cachedAttrElements) {
+ if (aUseCachedValue && elements && elements == cachedAttrElements) {

Results on d9bd6be9a67e, Linux x86-64, built locally:

Check Without the fix With the fix
New mochitest, optimized crash 49 passed
New mochitest, debug crash 49 passed
Extension and page, optimized 3 of 3 crash 3 of 3 alive
test_dom_xrays.html, debug not run 505 passed
test_reflected_attribute_frozenarray.html, debug not run 6 passed
WPT, aria element reflection, debug not run 32 checks as expected
WPT, wai-aria and aria reflection, debug not run 693 checks as expected

mach lint with clang-format, file-whitespace and license reports 0 problems. The before-fix mochitest logs show the crash as exit code 1, without a stack. The stack below comes from the extension scenario.

Other builds:

  • Release 159.0.1 and Nightly 162.0a1 (BuildID 20261105205004, ab3ff1cb2d01) crash 3 of 3.
  • Playwright's Firefox builds 157.0 and 159.0 crash on 7 of 8 reflected properties: ariaLabelledByElements, ariaDescribedByElements, ariaOwnsElements, ariaControlsElements, ariaFlowToElements, ariaDetailsElements, ariaErrorMessageElements. ariaActiveDescendantElement does not. On stock Firefox I tested ariaLabelledByElements only.

Crashing stack (159.0.1, libxul debug ID 4900D28DDC7A07781781182F6246E06D0):

0 mozilla::dom::Element::GetAttrAssociatedElementsForBindings
1 mozilla::dom::Element_Binding::get_ariaLabelledByElements
2 js::Call
3-6 js::Proxy::get
7 js::Interpret

Impact:
An extension or tool that reads these properties crashes the tab on a page that also reads them. Playwright 1.65.0 users hit it through getByRole. I will link the Playwright issue here once it is filed.

The missing guard is real: Element::GetAttrAssociatedElementsForBindings only checks elements == cachedAttrElements before writing through aUseCachedValue, while ElementInternals::GetAttrElements got the null check in bug 2045887. Crash-stats has 3 crashes with this signature in the last 28 days, all in release content processes (158.0 and 158.0.1).

Could you submit the patch to Phabricator so it can be reviewed?

(AI-assisted triage, with review.)

Severity: -- → S3
Flags: needinfo?(bartosz.work)

The generated getter passes a null aUseCachedValue when this JS world has
no cached value, but cachedAttrElements is per element. A read from a
second world, such as a content script after the page, then found a cache
hit and wrote through the null pointer.

Bug 2045887 fixed the same write in ElementInternals::GetAttrElements.

Assignee: nobody → bartosz.work
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Submitted for review: D340360. It adds a chrome mochitest that crashes without the fix.

Flags: needinfo?(bartosz.work)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: