Closed Bug 1664149 Opened 5 years ago Closed 4 years ago

Crash in [@ nsDataObj::DropTempFile]

Categories

(Core :: Widget: Win32, defect, P1)

Unspecified
Windows
defect

Tracking

()

VERIFIED FIXED
97 Branch
Tracking Status
firefox-esr91 96+ verified
firefox95 --- wontfix
firefox96 + verified
firefox97 + verified
firefox98 --- verified

People

(Reporter: sg, Assigned: bobowen)

References

Details

(Keywords: crash, csectype-uaf, sec-high, Whiteboard: [sec-survey][adv-main96+r][adv-ESR91.5+r])

Crash Data

Attachments

(3 files)

Crash report: https://crash-stats.mozilla.org/report/index/27dcd26a-c8ef-49f7-869f-ab13a0200908

Top 10 frames of crashing thread:

0 xul.dll nsDataObj::DropTempFile widget/windows/nsDataObj.cpp:1775
1 xul.dll nsDataObj::GetFile widget/windows/nsDataObj.cpp:1542
2 xul.dll nsDataObj::GetData widget/windows/nsDataObj.cpp:690
3 ole32.dll HandleFromHandle com\ole32\ole232\clipbrd\clipapi.cpp:2048
4 ole32.dll RenderCurrentFormat com\ole32\ole232\clipbrd\clipapi.cpp:4052
5 ole32.dll RenderFormat com\ole32\ole232\clipbrd\clipapi.cpp:4185
6 ole32.dll ClipboardWndProc com\ole32\ole232\clipbrd\clipapi.cpp:683
7 user32.dll int64_t UserCallWinProcCheckWow 
8 user32.dll DispatchClientMessage 
9 user32.dll _fnDWORD 

There are multiple reports saying this happens when copying an image to the clipboard.

Some of the crashes are either UAFs (e5e5...) or wildptr's, sec bug
https://crash-stats.mozilla.org/report/index/97817a92-5ca7-462b-800d-de86c0211103

Group: core-security
Flags: needinfo?(jmathies)
Group: core-security → dom-core-security
Assignee: nobody → bobowencode
Severity: -- → S2
Priority: -- → P2

I've had a look at the code here and I can't immediately see the issue, assuming this is all happening on the main thread, which I think it will be.
There is some passing around of raw pointers, but it at least seems to be doing the Addrefing and Releasing correctly.
I guess I could change it to use smart pointers for those bits to be sure.

I've found steps that flow through this code and I've tried various different ways to trigger a problem, but no luck so far.
I'll spend a bit more time on this to see if I get anywhere.

One thing I've just noticed is that all of the crashes where it looks like a UAF are x86.

Coming back with fresh eyes, I think I've found something that might be the issue.
The read here can cause the event loop to be spun here.

Now in theory the caller should be holding a reference, but perhaps some apps process things async and don't expect us to process the events out of turn/recursively.

Anyway, we can hopefully just hold a reference to ourselves and see if that resolves the problem.

Status: NEW → ASSIGNED
Flags: needinfo?(jmathies)
Priority: P2 → P1

After discussions with smaug we decided we should try and cater for async mode (using StartOperation and EndOperation) as well.

I worked up some patches, but as GetData is called many times (particularly when dragging) it means we are constantly taking references and submitting events for them to be released.
It also requires a fair bit of logic around releasing in EndOperation, GetData and Release (in case EndOperation is not called).

I think I've come up with a simpler plan that should still cover the scenarios, only take and release the internal reference once and simplify the logic.

Attachment #9254137 - Attachment description: Bug 1664149: Hold a reference in nsDataObj::GetData. r=smaug! → Bug 1664149: Hold a self reference in nsDataObj. r=smaug!

Comment on attachment 9254137 [details]
Bug 1664149: Hold a self reference in nsDataObj. r=smaug!

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: We don't have steps to reproduce and at the very least it seems you would need to persuade the user to Copy and Paste or Drag and Drop an image.

Over the comments question below, I have added comments, but I don't believe they add much information for an attacker as the fix is already obviously to do with reference counting.

  • Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Unknown
  • Which older supported branches are affected by this flaw?: All
  • If not all supported branches, which bug introduced the flaw?: None
  • Do you have backports for the affected branches?: Yes
  • If not, how different, hard to create, and risky will they be?:
  • How likely is this patch to cause regressions; how much testing does it need?: Fairly unlikely, it is relatively simple holding of extra references to keep object alive when released externally.
    Some general Copy/Paste and Drag/Drop testing on Windows would be good.
    If someone can reproduce obviously that would be ideal.
Attachment #9254137 - Flags: sec-approval?

Comment on attachment 9254137 [details]
Bug 1664149: Hold a self reference in nsDataObj. r=smaug!

approved to land and request uplift

Attachment #9254137 - Flags: sec-approval? → sec-approval+

Landed: https://hg.mozilla.org/integration/autoland/rev/08324a167e6bc3e42419d316a3d1fc0eef1f22f6

Backed out for causing mochitest failures with test_bug1123480.xhtml:

https://hg.mozilla.org/integration/autoland/rev/44dadccd67d33f0d5fbde0038277b3d0c11a8f32

Failure line: TEST-UNEXPECTED-FAIL | widget/tests/test_bug1123480.xhtml | should have cleared the clipboard data - got 1, expected +0

Flags: needinfo?(bobowencode)
Flags: needinfo?(bobowencode)
Group: dom-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 97 Branch

Comment on attachment 9254137 [details]
Bug 1664149: Hold a self reference in nsDataObj. r=smaug!

Beta/Release Uplift Approval Request

  • User impact if declined: Crashes still experienced when copying / dragging images (assuming this fix works).
  • Is this code covered by automated tests?: Unknown
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce: We don't have STR, but if QE can reproduce that would be great.
  • List of other uplifts needed: None
  • Risk to taking this patch: Medium
  • Why is the change risky/not risky? (and alternatives if risky): Only saying medium because while this involves fairly simple extra ref holding, its release is submitted to the event loop.
    One test needed amending for this, but it should be unlikely that other production code relies on the release happening straight away.
  • String changes made/needed: None
Attachment #9254137 - Flags: approval-mozilla-beta?
Attachment #9256180 - Flags: approval-mozilla-beta?

Comment on attachment 9254137 [details]
Bug 1664149: Hold a self reference in nsDataObj. r=smaug!

Approved for 96.0b8

Attachment #9254137 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9256180 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Flags: qe-verify+
QA Whiteboard: [qa-triaged]

As part of a security bug pattern analysis, we are requesting your help with a high level analysis of this bug. It is our hope to develop static analysis (or potentially runtime/dynamic analysis) in the future to identify classes of bugs.

Please visit this google form to reply.

Flags: needinfo?(bobowencode)
Whiteboard: [sec-survey]

Comment on attachment 9256125 [details]
*** ESR91 *** Bug 1664149: Hold a self reference in nsDataObj. r=smaug

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: sec-high
  • User impact if declined: Crashes still experienced when copying / dragging images. Currently looks like the fix works despite not having STR to prove.
  • Fix Landed on Version: 97
  • Risk to taking this patch: Medium
  • Why is the change risky/not risky? (and alternatives if risky): Only saying medium because while this involves fairly simple extra ref holding, its release is submitted to the event loop.
    One test needed amending for this, but it should be unlikely that other production code relies on the release happening straight away.
Flags: needinfo?(bobowencode)
Attachment #9256125 - Flags: approval-mozilla-esr91?
Attachment #9256180 - Flags: approval-mozilla-esr91?

I couldn't manage to reproduce this crash, I tried to find some accurate steps testing around copping and dragging images but I didn't succeed.
Simon, is it possible if you managed to reproduce this issue before to check if you still could reproduce the issue on the latest Firefox Nightly and on Firefox Beta?
https://www.mozilla.org/en-GB/firefox/channel/desktop/

Thanks.

Flags: needinfo?(simon.giesecke)

I don't have a way to reproduce this, unfortunately. I just filed the bug based on a number of crash reports with this signature.

Flags: needinfo?(simon.giesecke)

Based on the last two comments, I am removing the qe-verify+ flag, since we are not able to reproduce the issue.

Flags: qe-verify+
QA Whiteboard: [qa-triaged] → [qa-triaged][post-critsmash-triage]

Comment on attachment 9256125 [details]
*** ESR91 *** Bug 1664149: Hold a self reference in nsDataObj. r=smaug

Approved for 91.5esr.

Attachment #9256125 - Flags: approval-mozilla-esr91? → approval-mozilla-esr91+
Attachment #9256180 - Flags: approval-mozilla-esr91? → approval-mozilla-esr91+
Whiteboard: [sec-survey] → [sec-survey][adv-main96+r][adv-ESR91.5+r]

Marking this as verified since the latest crashes were on Firefox 97.0a1, Firefox 96.0b7 and Firefox 91.4.1esr.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-triaged][post-critsmash-triage] → [post-critsmash-triage]
Group: core-security-release
Duplicate of this bug: 1455817
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: