Crash in [@ nsRefreshDriver::ObserverData::operator RefPtr] on poison value
Categories
(Core :: Layout, defect)
Tracking
()
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.
| Reporter | ||
Comment 1•3 years ago
|
||
Also present in a slightly different signature: bp-a39e1c6d-bb3f-4330-8110-501480230512
| Reporter | ||
Updated•3 years ago
|
| Assignee | ||
Comment 2•3 years ago
•
|
||
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.
| Assignee | ||
Comment 3•3 years ago
|
||
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.
| Assignee | ||
Comment 4•3 years ago
|
||
(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.
| Assignee | ||
Comment 5•3 years ago
|
||
(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?)
Comment 6•3 years ago
|
||
SwipeTracker is one of them, it's in the parent process. I highly suspect it causes these crashes.
Comment 7•3 years ago
|
||
Let's make this a release assert then? That should relatively quickly confirm that I suspect.
| Assignee | ||
Comment 8•3 years ago
|
||
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.
| Reporter | ||
Comment 9•3 years ago
|
||
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.
Comment 10•3 years ago
|
||
I don't think there is any easy way to see what the concrete nsARefreshObserver is, other than possibly via minidumps.
| Assignee | ||
Comment 11•3 years ago
|
||
(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.)
| Assignee | ||
Comment 12•3 years ago
|
||
(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.
| Assignee | ||
Comment 13•3 years ago
|
||
I have a theory about how we might be getting SwipeTracker to be destroyed without being unregistered:
- We hit this code, which unregisters (good, we're safe) and then queues up a runnable to call
SwipeFinishedon us:
https://searchfox.org/mozilla-central/rev/aec3a901e6f6b3041b5ec457c9111a042cef1fb1/widget/SwipeTracker.cpp#155-160 - When that runnable gets serviced, we'll potentially get deallocated via the fact that we call into SwipeFinished() on our widget which is here:
https://searchfox.org/mozilla-central/rev/aec3a901e6f6b3041b5ec457c9111a042cef1fb1/widget/nsBaseWidget.cpp#2232 - ...but if, in the meantime, we somehow get re-registered with our refresh driver (before the runnable gets serviced), then we'll be deallocated while still being registered.
| Assignee | ||
Comment 14•3 years ago
|
||
(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.
| Assignee | ||
Comment 15•3 years ago
|
||
I spun off bug 1837244 for the more general (though debug-only) approach in my try push from comment 8.
| Assignee | ||
Comment 16•3 years ago
|
||
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.
| Assignee | ||
Comment 17•3 years ago
•
|
||
(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.
| Assignee | ||
Comment 18•3 years ago
|
||
(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.
Updated•3 years ago
|
Comment 19•3 years ago
|
||
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.
| Assignee | ||
Comment 20•3 years ago
|
||
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.
Updated•3 years ago
|
| Assignee | ||
Comment 21•3 years ago
|
||
(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/
| Assignee | ||
Comment 22•3 years ago
|
||
And that means we should probably uplift bug 1837226 to ESR.
ni=me to do that.
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 23•3 years ago
|
||
Updated•3 years ago
|
Updated•3 years ago
|
| Assignee | ||
Comment 24•3 years ago
•
|
||
(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.
| Assignee | ||
Comment 25•3 years ago
|
||
I spun off bug 1858805 for the remaining crash volume here.
Updated•2 years ago
|
Description
•