Closed Bug 1935471 Opened 1 year ago Closed 1 year ago

Crash in [@ mozilla::StyleCssUrl::LoadData] due to CSS <url> custom property substitution off the main thread

Categories

(Core :: CSS Parsing and Computation, defect, P2)

Unspecified
All
defect

Tracking

()

VERIFIED FIXED
136 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr128 135+ verified
firefox133 --- wontfix
firefox134 --- wontfix
firefox135 + verified
firefox136 + verified

People

(Reporter: aryx, Assigned: emilio)

References

(Blocks 1 open bug)

Details

(4 keywords, Whiteboard: [adv-main135+r][adv-ESR128.7+r])

Crash Data

Attachments

(3 files)

Low frequency crash which has existed for some time.

Crash report: https://crash-stats.mozilla.org/report/index/6d58d526-5366-434e-abee-311210241204

MOZ_CRASH Reason:

MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread() || dom::IsCurrentThreadRunningWorker())

Top 10 frames:

0  xul.dll  mozilla::StyleCssUrl::LoadData() const  layout/style/ServoStyleConstsInlines.h:385
1  xul.dll  mozilla::StyleCssUrl::GetURI() const  layout/style/ServoStyleConstsInlines.h:396
2  xul.dll  mozilla::StyleComputedUrl::GetURI() const  layout/style/ServoStyleConstsInlines.h:428
2  xul.dll  Gecko_GetComputedImageURLSpec(mozilla::StyleComputedUrl const*, nsTString<cha...  layout/style/GeckoBindings.cpp:1119
3  xul.dll  style::gecko::url::ComputedUrl::serialize_with<alloc::string::String>(void (*...  servo/components/style/gecko/url.rs:347
4  xul.dll  style::gecko::url::impl$19::to_css(style::gecko::url::ComputedUrl*, style_tra...  servo/components/style/gecko/url.rs:359
4  xul.dll  style::properties_and_values::value::impl$44::to_css<style::values::computed:...  servo/components/style/properties_and_values/value.rs:94
5  xul.dll  style::properties_and_values::value::impl$18::to_css(enum2$<style::properties...  servo/components/style/properties_and_values/value.rs:239
5  xul.dll  style_traits::values::CssWriter<alloc::string::String>::new(alloc::string::St...  servo/components/style/properties_and_values/value.rs:203
5  xul.dll  style_traits::values::ToCss::to_css_string(style::properties_and_values::valu...  servo/components/style_traits/values.rs:95

The severity field is not set for this bug.
:jwatt, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(jwatt)

The bug is linked to a topcrash signature, which matches the following criterion:

  • Top 10 content process crashes on beta

For more information, please visit BugBot documentation.

Keywords: topcrash
Attached file Test-case

Some crashes look like bad hardware but there's a real bug here. Test-case attached.

Relevant code is here

If we substitute <url> custom properties off the main thread we can hit this assert.

I think this is at most a leak as it stands, but it can cause correctness issues if multiple threads race to the same url data (one could incorrectly get an invalid URI).

I think we'd need to make StyleCssUrl::GetURI use some sort of synchronization to make it thread-safe.

Zach, I don't know if you happen to have cycles for this? I think the easiest fix is to make this assignment an atomic compare-and-swap loop, and tweak the flag setup so it also uses atomic or / and with the right memory ordering.

If you don't have the cycles ni? me and I can try to pick it up asap.

Flags: needinfo?(jwatt) → needinfo?(zach)
Summary: Crash in [@ mozilla::StyleCssUrl::LoadData] → Crash in [@ mozilla::StyleCssUrl::LoadData] due to CSS <url> custom property substitution off the main thread

Tagging as security sensitive just in case I've missed anything and since this is technically a race. But per the links in comment 3 it seems it's just a leak at most. Tom, mind sanity-checking?

Group: layout-core-security
Severity: -- → S2
Flags: needinfo?(tom)
Priority: -- → P2

(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)

Created attachment 9460614 [details]
Zach, I don't know if you happen to have cycles for this? I think the easiest fix is to make this assignment an atomic compare-and-swap loop, and tweak the flag setup so it also uses atomic or / and with the right memory ordering.

If you don't have the cycles ni? me and I can try to pick it up asap.

I do have the cycles and will start on it right away, but feel free to pick it up if I'm taking too long for any reason.

Flags: needinfo?(zach)

Sorry, I misunderstood the scope of this, and I do not have cycles. Emilio, would you please pick it up?

Flags: needinfo?(emilio)

We can resolve them off the main thread now due to registered custom
properties (which requires the computed <url> serialization).

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Flags: needinfo?(emilio)

Races in refcounting an object could lead to use-after-frees. The fact that this is a top crash means the race can be triggered without too much difficulty. I'll leave it as sec-moderate because I don't know how exploitable it really is.

Yeah the nice thing is that this is not a smart pointer, turns out. As in, there's no Release() in the assignment at all, so at worst it can be a leak AIUI.

Flags: needinfo?(tom)

What's the right time to add a reminder to add a test for this bug? The test-case above is trivial-ish

Flags: needinfo?(continuation)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a2ad43996a02 Make resolving image urls thread-safe. r=dshin

(In reply to Emilio Cobos Álvarez (:emilio) from comment #10)

What's the right time to add a reminder to add a test for this bug? The test-case above is trivial-ish

135 ships on Feb 4, so assuming you can get this on beta, maybe a week after that?

Flags: needinfo?(continuation)
Group: layout-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 136 Branch

The patch landed in nightly and beta is affected.
:emilio, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox135 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(emilio)

Comment on attachment 9460692 [details]
Bug 1935471 - Make resolving image urls thread-safe. r=#style

Beta/Release Uplift Approval Request

  • User impact if declined/Reason for urgency: Reproducible crash
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: Load test-case
  • List of other uplifts needed: none
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Relatively straight-forward / targeted fix.
  • String changes made/needed: none
  • Is Android affected?: Yes
Flags: needinfo?(emilio)
Attachment #9460692 - Flags: approval-mozilla-beta?
Flags: qe-verify+
Attachment #9460692 - Flags: approval-mozilla-esr128?

Comment on attachment 9460692 [details]
Bug 1935471 - Make resolving image urls thread-safe. r=#style

Approved for 135.0rc1 and 128.7esr.

Attachment #9460692 - Flags: approval-mozilla-esr128?
Attachment #9460692 - Flags: approval-mozilla-esr128+
Attachment #9460692 - Flags: approval-mozilla-beta?
Attachment #9460692 - Flags: approval-mozilla-beta+
QA Whiteboard: [post-critsmash-triage]

Reproduced the crash using an old Beta build 135.0b6 (https://crash-stats.mozilla.org/report/index/ec52e369-0e20-49c9-9fcc-6b19e0250128) verified that using latest RC 135.0 build, 128.7.0esr and latest Nightly 136.0a1 the testcase does not crash anymore across platforms (Windows 11, macOS 13 and Ubuntu 22.04).

Status: RESOLVED → VERIFIED
Flags: qe-verify+
Whiteboard: [adv-main135+r]
Whiteboard: [adv-main135+r] → [adv-main135+r][adv-ESR128.7+r]
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/59ef2812d34f Add crashtest. r=layout-reviewers,jfkthame

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: