UAF in nsWindow::LayerViewSupport::OnDetach
Categories
(GeckoView :: General, defect, P1)
Tracking
(firefox-esr68 unaffected, firefox-esr78 unaffected, firefox79 wontfix, firefox80 wontfix, firefox81 wontfix, firefox82+ wontfix, firefox83 fixed)
| Tracking | Status | |
|---|---|---|
| firefox-esr68 | --- | unaffected |
| firefox-esr78 | --- | unaffected |
| firefox79 | --- | wontfix |
| firefox80 | --- | wontfix |
| firefox81 | --- | wontfix |
| firefox82 | + | wontfix |
| firefox83 | --- | fixed |
People
(Reporter: bugzilla, Assigned: bugzilla)
References
Details
(Keywords: csectype-race, csectype-uaf, sec-high, Whiteboard: [geckoview:m80][geckoview:m81][geckoview:m82][post-critsmash-triage][adv-main83+r])
Attachments
(7 files, 2 obsolete files)
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
|
47 bytes,
text/x-phabricator-request
|
tjr
:
sec-approval+
|
Details | Review |
While working on bug 1637351 I discovered that this is pretty easy to reproduce when e10s-multi is turned on.
It's pretty clear to me that nsWindow::NativePtr and nsWindow::WindowPtr are not thread-safe as intended.
| Assignee | ||
Comment 1•5 years ago
|
||
Here we try to instantiate WindowPtr::Locked but its mutex is the good old 0x5e pattern.
I am rewriting these smart pointers so that they actually work.
Updated•5 years ago
|
| Assignee | ||
Updated•5 years ago
|
Comment 2•5 years ago
|
||
:aklotz triaging as reo for 79, do you have an update on this bug?
| Assignee | ||
Comment 3•5 years ago
|
||
Work in progress. This issue affects some very thorny code at the foundation of GeckoView, so it has been slow going. I've got it compiling again, but it still needs some touch-ups.
| Assignee | ||
Comment 4•5 years ago
|
||
The current patchset is passing on try. I do not intend to push until after the next merge.
| Assignee | ||
Comment 5•5 years ago
|
||
Given the access patterns involved on the native side, I think it is safest
to ensure that this field is access atomically by the VM.
| Assignee | ||
Comment 6•5 years ago
|
||
- We rename the existing
NativePtrstruct toNativePtrTraits, as that is
more descriptive of what that code actually does; - We introduce
NativeWeakPtras a smart pointer type that holds a pointer
to an object and allows its access in a thread-safe way. See comments. - We replace some explicit uses of template types with type deduction via
autoanddecltype(auto). This allows for more use of forward declarations.
Depends on D87360
| Assignee | ||
Comment 7•5 years ago
|
||
-
Having
AndroidViewandGeckoViewSupportas nested classes inside of
nsWindowmake it impossible to forward declare them. We move those classes
into their own headers. We also moveWindowEventinto its own header. -
We remove the old
NativePtrandWindowPtrimplementations fromnsWindow
and convert the class definitions in this patch to use the newNativeWeakPtr. -
GeckoViewSupporthad a unique quirk where it was owned bynsWindow
instead of its Java counterpart. To makeGeckoViewSupport's ownership work
like the other classes that useNativeWeakPtr(and to substantially simplify
the implementation ofNativeWeakPtritself), I have reversed that: now
nsWindowholds aNativeWeakPtrtoGeckoViewSupport, while
GeckoViewSupportis owned by its Java counterpart and holds a strong ref to
thensWindow. -
GeckoViewSupportno longer inherits fromSupportsWeakPtr, since using it
withNativeWeakPtrprovides stronger and safer guarantees.
Depends on D87361
| Assignee | ||
Comment 8•5 years ago
|
||
These conversions are pretty straight forward thanks to the type system.
Basically we take a NativeWeakPtr, call Access() on it, and if the
accessor is truthy, then we call whatever methods we need to call.
Creation of new pointers is done using NativeWeakPtrHolder::Attach() and
detaching of strong references is done by NativeWeakPtr::Detach().
Depends on D87362
| Assignee | ||
Comment 9•5 years ago
|
||
This patch is similar to part 4 but for GeckoEditableSupport.
Conversions over to NativeWeakPtr are pretty straight forward thanks to the
type system. Basically we take a NativeWeakPtr, call Access() on it, and
if the accessor is truthy, then we call whatever methods we need to call.
Creation of new pointers is done using NativeWeakPtrHolder::Attach() and
detaching of strong references is done by NativeWeakPtr::Detach().
Depends on D87363
| Assignee | ||
Comment 10•5 years ago
|
||
This patch is similar to part 4 but for Android a11y.
Conversions over to NativeWeakPtr are pretty straight forward thanks to the
type system. Basically we take a NativeWeakPtr, call Access() on it, and
if the accessor is truthy, then we call whatever methods we need to call.
Creation of new pointers is done using NativeWeakPtrHolder::Attach() and
detaching of strong references is done by NativeWeakPtr::Detach().
Depends on D87364
| Assignee | ||
Updated•5 years ago
|
| Assignee | ||
Comment 11•5 years ago
|
||
This patch is similar to part 4 but for MediaSessionSupport.
Conversions over to NativeWeakPtr are pretty straight forward thanks to the
type system. Basically we take a NativeWeakPtr, call Access() on it, and
if the accessor is truthy, then we call whatever methods we need to call.
Creation of new pointers is done using NativeWeakPtrHolder::Attach() and
detaching of strong references is done by NativeWeakPtr::Detach().
Depends on D87365
| Assignee | ||
Comment 12•5 years ago
|
||
Comment on attachment 9170527 [details]
Bug 1651705: Part 1 - Make JNIObject.mHandle volatile; r=#geckoview-reviewers
Security Approval Request
- How easily could an exploit be constructed based on the patch?: It would be really hard; this patch fixes a bunch of concurrency issues that are extremely timing sensitive. We have no evidence of them surfacing under single-process e10s (which is the current default on beta and release).
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: No
- Which older supported branches are affected by this flaw?: All supported
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: No
- If not, how different, hard to create, and risky will they be?: High risk. Given that we have not seen this bug without turning on e10s-multi, and given that we have no intention to do that on other branches, I do not think we should backport.
- How likely is this patch to cause regressions; how much testing does it need?: Test suite runs green, however we do want as close to a full Nightly cycle as we can get with these patches, hence landing early in the 82 cycle.
| Assignee | ||
Updated•5 years ago
|
Comment 13•5 years ago
|
||
Comment on attachment 9170527 [details]
Bug 1651705: Part 1 - Make JNIObject.mHandle volatile; r=#geckoview-reviewers
Approved to land
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Comment 14•5 years ago
|
||
This landed and got backed out mochitest failures on test_resizers_resizing_elements.html:
https://hg.mozilla.org/integration/autoland/rev/fbd07f0d19d2009779ebde0c676fcbce64607371
Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=314312882&repo=autoland
[task 2020-08-28T19:18:01.747Z] 19:18:01 INFO - 3698 INFO TEST-PASS | editor/libeditor/tests/test_resizers_resizing_elements.html | Resizers for <img>: The width should be increased by 0 pixels
[task 2020-08-28T19:18:01.747Z] 19:18:01 INFO - Buffered messages finished
[task 2020-08-28T19:18:01.747Z] 19:18:01 WARNING - 3699 INFO TEST-UNEXPECTED-FAIL | editor/libeditor/tests/test_resizers_resizing_elements.html | Resizers for <img>: The height should be increased by -10pixels - got 150, expected 140 epsilon: +/- 2
[task 2020-08-28T19:18:01.747Z] 19:18:01 INFO - SimpleTest.isfuzzy@SimpleTest/SimpleTest.js:513:14
[task 2020-08-28T19:18:01.748Z] 19:18:01 INFO - testResizer@editor/libeditor/tests/test_resizers_resizing_elements.html:159:14
etc.
It had landed as:
https://hg.mozilla.org/integration/autoland/rev/2d79f4348b36f4d6f7117b4ca2eedfc5cefdf35d
https://hg.mozilla.org/integration/autoland/rev/9ffca762753ccc17d8f00baa394a9176f2c728ae
https://hg.mozilla.org/integration/autoland/rev/7d9d2d44b2ee2274eb11e59901f77a7df3b3e2ab
https://hg.mozilla.org/integration/autoland/rev/84590e96de88128ecd3308e92c47da0cf979bb7c
https://hg.mozilla.org/integration/autoland/rev/531e71369f6842f64adbf4f89a070312ba497401
https://hg.mozilla.org/integration/autoland/rev/de4edbcb15c112562aa6a2556791f1b112842570
https://hg.mozilla.org/integration/autoland/rev/7fd32a3fb6e750ba944b7d1db9d688cc7cdcdfc7
| Assignee | ||
Updated•5 years ago
|
Comment 15•5 years ago
|
||
Backed out on request from Aaron:
https://hg.mozilla.org/integration/autoland/rev/da835fe18ce6dabc97bec756d50441c38547fcd3
Had landed before as https://treeherder.mozilla.org/#/jobs?repo=autoland&group_state=expanded&resultStatus=retry%2Ctestfailed%2Cbusted%2Cexception&revision=60730e8394ae160ac69287f4858e0c4de175cfa5
Comment 16•5 years ago
|
||
James I know Aaron is off for a few weeks. Do you know if there was a plan to hand off this work?
Comment 17•5 years ago
|
||
If there isn't I can pick it up and fix the test that's preventing this from landing.
Yeah, looks like Agi will try to finish it up.
Comment 19•5 years ago
|
||
I rebased the patches and now the browser crashes after every test run in WindowEvent: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=315775315&repo=try&lineNumber=2249 trying to figure out what's going on there.
Comment 20•5 years ago
|
||
Update: from what I can tell we're getting a SyncPauseCompositor for a dead window from here: https://searchfox.org/mozilla-central/rev/5efefd3ef214ed6d3234ba245c1da3004ead94e0/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java#5865
The window is dead because something calls disposeNative, which I think indicates that the object is GC'd?
I'll keep looking
Comment 21•5 years ago
•
|
||
OK I think I'm getting close, my current theory is that we call .close on the Session and then we get a onSurfaceDestroyed which causes us to call into a dead compositor.
Comment 22•5 years ago
|
||
Ok so Comment 21 seems to be correct, there's also another case where we call mWindow.close after we disposed of the window.
Comment 23•5 years ago
|
||
Ok so it looks like we get close and dispose in the right order but then we execute them out-of-order, so the close happens after dispose which seems wrong.
09-18 19:40:19.429 19984 19984 I Gecko : sferrog: WindowEvent constructor nativeClose 0x7de045156e20
09-18 19:40:19.430 19984 19984 I Gecko : sferrog OnNativeCall nativeDisposeNative
09-18 19:40:19.430 19984 19984 I Gecko : sferrog: WindowEvent constructor nativeDisposeNative 0x7de045634dd0
09-18 19:40:19.537 19984 19999 I Gecko : sferrog: IsStaleCall nativeClose 0x7de045156e20
09-18 19:40:19.537 19984 19999 I Gecko : sferrog: GetHandle 0x2008de
09-18 19:40:19.537 19984 19999 I Gecko : sferrog: CheckNativeHandle 0
09-18 19:40:19.537 19984 19999 I Gecko : sferrog: CheckNativeHandle 0 exception
Comment 24•5 years ago
|
||
I think I know what's going on. There is a Get which checks for a valid native handle and throws if there isn't one and GetNativeHandle which doesn't (Get uses GetNativeHandle internally)
- In the old code we used to use
GetNativeHandledirectly to determine if the window was still alive and ignored a null value - In the new code we use
Getwhich throws if the handle is invalid/null
Comment 25•5 years ago
|
||
The method erroneously returned false when the object has been disposed.
Comment 26•5 years ago
|
||
After we close the window we dispose of the native object, which causes the
compositor to be disposed too.
Comment 27•5 years ago
|
||
| Assignee | ||
Comment 28•5 years ago
|
||
Thanks Agi! I think what I'll do here is merge your follow-ups into the existing patchset and then land that.
Comment 29•5 years ago
|
||
Sounds good to me!
| Assignee | ||
Updated•5 years ago
|
| Assignee | ||
Updated•5 years ago
|
Comment 30•5 years ago
|
||
https://hg.mozilla.org/integration/autoland/rev/e7fcc0c7c7c459b1115f39e1e22dedc29c3e5737
https://hg.mozilla.org/integration/autoland/rev/2c2e52148ea8a8aac58496ab84896cf5722cbbae
https://hg.mozilla.org/integration/autoland/rev/19143773f4e3ef343cb9d0f296481211021d4516
https://hg.mozilla.org/integration/autoland/rev/5d613069b6489ed1fcb4e47e9d0a4884ec615c5e
https://hg.mozilla.org/integration/autoland/rev/630ca8cf5b076f1266d4dd05620061ac71a975e2
https://hg.mozilla.org/integration/autoland/rev/3984bf27be7fda20da9d6efed4d201af494ba96f
https://hg.mozilla.org/integration/autoland/rev/e90b3bde17b8f3464d8761673b86c38fc22ef34f
https://hg.mozilla.org/mozilla-central/rev/e7fcc0c7c7c4
https://hg.mozilla.org/mozilla-central/rev/2c2e52148ea8
https://hg.mozilla.org/mozilla-central/rev/19143773f4e3
https://hg.mozilla.org/mozilla-central/rev/5d613069b648
https://hg.mozilla.org/mozilla-central/rev/630ca8cf5b07
https://hg.mozilla.org/mozilla-central/rev/3984bf27be7f
https://hg.mozilla.org/mozilla-central/rev/e90b3bde17b8
| Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Description
•