Closed Bug 1833504 Opened 3 years ago Closed 3 years ago

Crash in [@ nsRefreshDriver::ObserverData::operator RefPtr] on poison value

Categories

(Core :: Layout, defect)

Unspecified
Windows 10
defect

Tracking

()

RESOLVED FIXED
116 Branch
Tracking Status
firefox-esr102 --- unaffected
firefox-esr115 117+ fixed
firefox115 --- wontfix
firefox116 + fixed
firefox117 + fixed

People

(Reporter: mccr8, Assigned: dholbert)

References

Details

(4 keywords, Whiteboard: [adv-esr115.2+r] [adv-main117+r])

Crash Data

Attachments

(1 obsolete file)

Crash report: https://crash-stats.mozilla.org/report/index/5b3caa8a-36e7-49d8-8bf2-dd7120230513

Reason: EXCEPTION_ACCESS_VIOLATION_READ

Top 10 frames of crashing thread:

0  xul.dll  mozilla::RefPtrTraits<nsARefreshObserver>::AddRef  mfbt/RefPtr.h:53
0  xul.dll  RefPtr<nsARefreshObserver>::ConstRemovingRefPtrTraits<nsARefreshObserver>::AddRef  mfbt/RefPtr.h:419
0  xul.dll  RefPtr<nsARefreshObserver>::RefPtr  mfbt/RefPtr.h:113
0  xul.dll  nsRefreshDriver::ObserverData::operator RefPtr  layout/base/nsRefreshDriver.h:478
0  xul.dll  nsRefreshDriver::Tick  layout/base/nsRefreshDriver.cpp:2567
1  xul.dll  mozilla::RefreshDriverTimer::TickDriver  layout/base/nsRefreshDriver.cpp:373
1  xul.dll  mozilla::RefreshDriverTimer::TickRefreshDrivers  layout/base/nsRefreshDriver.cpp:351
2  xul.dll  mozilla::RefreshDriverTimer::Tick  layout/base/nsRefreshDriver.cpp:367
3  xul.dll  mozilla::VsyncRefreshDriverTimer::RunRefreshDrivers  layout/base/nsRefreshDriver.cpp:911
3  xul.dll  mozilla::VsyncRefreshDriverTimer::TickRefreshDriver  layout/base/nsRefreshDriver.cpp:825

38 crashes in the last month on this signature. Almost entirely on poison values.

It looks like ObserverData::mObserver is a weak pointer, and we're crashing on a poison value when trying to turn it into a RefPtr. Maybe there's something that can be improved here.

Also present in a slightly different signature: bp-a39e1c6d-bb3f-4330-8110-501480230512

Crash Signature: [@ nsRefreshDriver::ObserverData::operator RefPtr] → [@ nsRefreshDriver::ObserverData::operator RefPtr] [@ nsRefreshDriver::ObserverData::operator RefPtr<T> ]A
Crash Signature: [@ nsRefreshDriver::ObserverData::operator RefPtr] [@ nsRefreshDriver::ObserverData::operator RefPtr<T> ]A → [@ nsRefreshDriver::ObserverData::operator RefPtr] [@ nsRefreshDriver::ObserverData::operator RefPtr<T> ]

Several of the crash reports for the "operator RefPtr" signature (no <T>) have comments about "back" navigation:
"I quickly switched to the previous tab using the "two-finger" touchpad function."
"I was just backtracking with the arrows"
"Firefox keeps crashing when I use my laptop's trackpad to move forward or backward to a different page. "

I looked at one of the crash report minidumps in Visual Studio, but unfortunately there's a not a lot that can be learned, since the object has been overwritten with a poison value, and it could be any nsARefreshObserver subclass (of which there are many).

Classifying as S2 for now, since this is a UAF. We may need to figure out some sort of way to gather more data before we can make this actionable.

Severity: -- → S2

Two notes:
(1) The RefreshDriver itself does not maintain an owning reference to its refresh observers. So if we forget to un-register a refresh observer before we free it, then the refresh driver will have a dangling raw-pointer to the now-deleted object, and this is the sort of crash we would expect to hit.

(2) Given the low amount of crash volume here, it's worth entertaining the possibility that some portion of the crash volume is explainable by bad memory -- where we've e.g. got a random bit-flip in the reference count of some refresh observer, which caused its reference count to reach 0 prematurely, and so it gets freed without ever having been unregistered, and then the next refresh-driver tick hits this crash when it iterates over that now-freed object.

(In reply to Daniel Holbert [:dholbert] from comment #2)

Several of the crash reports [...] have comments about "back" navigation:

There's one more reference to a back navigation in a crash from yesterday:

I was glancing through the Live Events tabs in Spotify's browser app and dragging two fingers to go 'back' a page. I think I did it too many times in a row too fast. Firefox became unresponsive for about 4 seconds, then crashed.

I tried this myself (repeatedly swiping to navigate forward-back in Spotify's Live Events pages, with Nightly in Win11 on a ThinkPad) but wasn't able to reproduce the crash as of yet, unfortunately.

(In reply to Daniel Holbert [:dholbert] from comment #3)

(1) The RefreshDriver itself does not maintain an owning reference to its refresh observers. So if we forget to un-register a refresh observer before we free it, then the refresh driver will have a dangling raw-pointer to the now-deleted object, and this is the sort of crash we would expect to hit.

smaug, do you have any ideas about how we might identify any information about what the nsARefreshObserver is in this scenario? (Not sure if we've hit this sort of issue in the past.)

(Either from the crash reports, or from adding some sort of diagnostic to the refresh driver, or something else?)

Flags: needinfo?(smaug)

SwipeTracker is one of them, it's in the parent process. I highly suspect it causes these crashes.

Let's make this a release assert then? That should relatively quickly confirm that I suspect.

Independently, one other general idea (kind of a generalization of the assert that comment 7 is pointing to): we might add a debug-only flag to the nsARefreshObserver superclass, to assert that it gets registered/unregistered the same number of times, and hope that the fuzzers might find ways to make that assertion fail.

Here's a Try run with that approach:
https://treeherder.mozilla.org/jobs?repo=try&revision=d3f164cfb7f7ca5d48bb5734eb264db7d5fd6af1
https://hg.mozilla.org/try/rev/eed830088a49aa61cceb812cd65301dffa58c179

(Looks like our existing test-suite doesn't run afoul of the assertion, which is good news.)

If that sounds reasonable, I'll likely spin that off as its own bug. Comment 7 seems like a good thing to do as well in its own bug, too.

How many times are these things registered and unregistered? It feels like you could just make that a release assert without causing performance issues, unless that's happening multiple times per frame or something.

I don't think there is any easy way to see what the concrete nsARefreshObserver is, other than possibly via minidumps.

Flags: needinfo?(smaug)

(In reply to Andrew McCreight [:mccr8] from comment #9)

How many times are these things registered and unregistered? It feels like you could just make that a release assert without causing performance issues, unless that's happening multiple times per frame or something.

They're not registered/unregistered super-often AFAIK; I'm not overly worried about overhead there.

The reason I've got my try-push-patch as being debug-only for now is to avoid the struct-size increase (from the new member-var, inserted as the sole member-var on the superclass, possibly consuming 64 bytes for alignment purposes), and also to avoid the overhead from the virtual destructor.

(I suppose the alternative would be to have every subclass have their own state to manage this, similar to the mRegisteredWithRefreshDriver bool and its assertion that emilio linked to. Then we can potentially mitigate some of that overhead, at the cost of having this checking spread out a bit more.)

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

Let's make this a release assert then? That should relatively quickly confirm that I suspect.

I spun off bug 1837226 for this part.

I have a theory about how we might be getting SwipeTracker to be destroyed without being unregistered:

(In reply to Daniel Holbert [:dholbert] from comment #13)

I have a theory about how we might be getting SwipeTracker to be destroyed without being unregistered:

I added a patch that'd address this scenario in bug 1837226 part 3, framed as a just-for-good-measure consistency improvement.

I spun off bug 1837244 for the more general (though debug-only) approach in my try push from comment 8.

Posted patches & triggered lando for both of those supporting bugs. We'll have to watch crash volume as those ride the trains, to find out if those patches helped.

Summing things up:

  • If our theory is correct about SwipeTracker being the problematic object here (and that seems likely per the crash report mentions about swipe back-navigation): then, bug 1837226 will either fix this or make us crash slightly sooner in a more-illuminating way.
  • Otherwise (if this is some other problematic object), bug 1837244 should hopefully make it possible for fuzzers to explore this space and discover scenarios that might trigger this crash.

(In reply to Daniel Holbert [:dholbert] from comment #16)

We'll have to watch crash volume as those ride the trains, to find out if those patches helped.

Specifically, we're watching to see if we get any crash volume for version 116.

So far so good; in the past 2 weeks (since patches landed), most of the crash volume is from 114 release, and we've got 2 individual crashes from 115 beta. Not enough to say anything definitive yet, since the overall volume is quite low. I'll check back here as 116 hits beta and then release. If we go for the whole 116 beta cycle without any crashes in 116beta, that'll be a pretty good sign that this is fixed.

Flags: needinfo?(dholbert)

(In reply to Daniel Holbert [:dholbert] from comment #17)

we've got 2 individual crashes from 115 beta.

Minor clarification: we have 4 total crashes from version 115 as-a-whole (2 from 115 beta, 1 from 115 Nightly, 1 from 115 rc).

I'll check back here as 116 hits beta..

Checking back: still zero crashes for version 116, which just completed its Nightly cycle and is now on beta. Hooray!

...and then release. If we go for the whole 116 beta cycle without any crashes in 116beta, that'll be a pretty good sign that this is fixed.

Still going with this plan. Let's call this fixed in a month (when 116 goes to release) if there's still zero crash volume for versions 116 & newer.

Depends on: 1837226, 1837244
Keywords: testcase-wanted

Minor clarification: we have 4 total crashes from version 115 as-a-whole (2 from 115 beta, 1 from 115 Nightly, 1 from 115 rc).

fwiw, with perhaps a slightly larger search window I see seven: 2 each from nightly, beta, and rc, plus one in 115.0.1 yesterday after your comment. For comparison, in 114 there were 10 during beta—getting better! Too soon to say for 116 but your plan to wait until release sounds reasonable.

Checking back: still zero crashes from 116 (or 117), hooray. Will continue with the plan to check back once 116 hits release and close if we're still good.

(In reply to Daniel Holbert [:dholbert] from comment #20)

Checking back: still zero crashes from 116 (or 117), hooray. Will continue with the plan to check back once 116 hits release and close if we're still good.

It's release week for 116, still no crashes in 116 or 117, so I think we can assume this was indeed fixed by bug 1837226. \o/

Status: NEW → RESOLVED
Closed: 3 years ago
Flags: needinfo?(dholbert)
Resolution: --- → FIXED

And that means we should probably uplift bug 1837226 to ESR.

ni=me to do that.

Flags: needinfo?(dholbert)
Assignee: nobody → dholbert
Group: layout-core-security → core-security-release
Target Milestone: --- → 116 Branch
Flags: needinfo?(dholbert)
QA Whiteboard: [post-critsmash-triage]
Flags: qe-verify-
Whiteboard: [adv-esr115.2+r]
Attached file advisory.txt (obsolete) —
Whiteboard: [adv-esr115.2+r] → [adv-esr115.2+r] [adv-main117+r]
Attachment #9350240 - Attachment is obsolete: true

(In reply to Daniel Holbert [:dholbert] from comment #20)

Checking back: still zero crashes from 116 (or 117), hooray. Will continue with the plan to check back once 116 hits release and close if we're still good.

(In reply to Daniel Holbert [:dholbert] from comment #21)

It's release week for 116, still no crashes in 116 or 117, so I think we can assume this was indeed fixed by bug 1837226. \o/

Bad news: we do now have a few crashes with this signature and a poison address for versions 117 and 118, and 115.2 and 115.3 ESR releases (all of which include the fix for bug 1837226 that we were hoping would take care of this).

So: there must be some other way to trigger this crash independent of the way that we closed off in bug 1837226. I'll spin off a new bug where we can pick things up.

Blocks: 1858805

I spun off bug 1858805 for the remaining crash volume here.

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: