Closed Bug 1547472 Opened 5 years ago Closed 5 years ago

UAF when saving file in Gecko Profiler when capturing with screenshots on

Categories

(Core :: Gecko Profiler, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla69
Tracking Status
firefox-esr60 --- unaffected
firefox67 --- wontfix
firefox68 - fixed
firefox69 --- fixed

People

(Reporter: jesup, Assigned: barret)

Details

(Keywords: csectype-uaf, sec-moderate, Whiteboard: [post-critsmash-triage][adv-main68+])

Crash Data

Attachments

(1 file)

Start Gecko Profiler with Screenshots on. Capture a profile. Save the profile to a file.

Twice in a row I crashed doing this; the second time in gdb and it appears that the ProfilerScreenshots instance captured in a lambda via "[this, " had been freed.

It needs to have a longer lifetime than the runnable (which might be tricky to ensure) or hold a reference to the object (perhaps via RefPtr<ProfilerScreenshots> self(this); .... [self, ...)

While this is a UAF, assigning sec-moderate due to needing to install the Profiler, be capturing, and have screenshots on (not the default IIRC), which can't be done under external control.

I thought I had commented on this before but I can't find it.

ProfilerScreenshots is not reference counted. The initial implementation made sure that the thread only exists while the ProfilerScreenshots object exists. But then thread shutdown got moved to a main thread runnable, and now the thread exists for too long, and that's allowing this UAF.

I see two possible fixes:

  • The ProfilerScreenshots destructor could block until all runnables on the thread have been processed, and only then schedule the thread shutdown.
  • Alternatively, we could make ProfilerScreenshots reference counted and only pass the object around via strong pointers, as suggested in comment 0.
Crash Signature: [@ mozilla::detail::MutexImpl::lock | mozilla::detail::RunnableFunction<T>::Run ]

I'm going to take this over since Markus is going to be away.

Assignee: mstange → brennie
Status: NEW → ASSIGNED
Group: core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Flags: needinfo?(brennie)
Resolution: --- → FIXED
Target Milestone: --- → mozilla69

[Tracking Requested - why for this release]:

Fixes a use-after-free crash present in 68

Flags: needinfo?(brennie)

Comment on attachment 9067429 [details]
Bug 1547472 - Ref count the ProfilerScreenshots structure r?gerald

Beta/Release Uplift Approval Request

  • User impact if declined: Possible use-after-free when using the gecko profiler, which could be used to exploit or crash the browser.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This is not risky due to this code path only being hit while running the Gecko Profiler with the screenshots feature enabled, which most of our users will not be doing.
  • String changes made/needed:
Attachment #9067429 - Flags: approval-mozilla-beta?

This patch should apply cleanly to release if the changes to RendererScreenshotGrabber.{cpp,h} are dropped. Should we target uplift into release after uplift into beta?

Flags: needinfo?(aryx.bugmail)

That's a call for the release managers. The patch applies mostly on release, only patching the RendererScreenshotGrabber.* files fails because those didn't exist yet in 67.

Flags: needinfo?(aryx.bugmail)

We don't normally uplift security fixes to release unless we're in a chemspill situation.

Comment on attachment 9067429 [details]
Bug 1547472 - Ref count the ProfilerScreenshots structure r?gerald

uaf fix for profiler, approved for 68.0b6

Attachment #9067429 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Flags: qe-verify+
Whiteboard: [post-critsmash-triage]

Unfortunately I couldn’t reproduce this issue with Fx 68.0a1 (2019-04-27) or Fx 67.0b8 using Windows 10 x64 and macOS 10.13. I used Gecko Profiler add-on, version 0.30. I don’t know what I am missing here, steps look pretty straightforward. The only thing that seems different is that on an older version I can see a different UI, the Save as file button is usable directly from the header, not through the Publish - Download buttons, but then again, the actual version was already available when the bug was submitted. Was this crash triggered intermittent, or maybe I misunderstood something here?

Flags: needinfo?(brennie)

Yes, this is intermittent as it is a race condition.

Flags: needinfo?(brennie)
QA Whiteboard: [qa-triaged]

Since this issue is triggered intermittent as per comment 13, it is very unlikely to be able to reproduce it or to verified it properly. Therefore I will remove the qa+ flag.
Randell, maybe, if time permits can you please verify that this issue no longer occurs on your side on the latest available Beta ? Thank you!

Flags: qe-verify+ → needinfo?(rjesup)

I'm not seeing it, but it is rather random. I'll keep a watch

Flags: needinfo?(rjesup)
Whiteboard: [post-critsmash-triage] → [post-critsmash-triage][adv-main68+]
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: