Closed Bug 1770137 (CVE-2022-1802) Opened 2 years ago Closed 2 years ago

Spot fix for pwn2own-2022 sandbox escape

Categories

(Toolkit Graveyard :: Notifications and Alerts, defect)

defect

Tracking

(firefox-esr91100+ verified, firefox100+ verified, firefox101+ verified, firefox102+ verified)

VERIFIED FIXED
102 Branch
Tracking Status
firefox-esr91 100+ verified
firefox100 + verified
firefox101 + verified
firefox102 + verified

People

(Reporter: peterv, Assigned: peterv)

References

Details

(Keywords: csectype-sandbox-escape, sec-critical)

Attachments

(2 files)

+++ This bug was initially created as a clone of Bug #1770057 +++

This bug is for the sandbox escape portion of the pwn2own-2022, described in section 2.2 of the PDF.

I think the basic, specific issue is that on this line of code we use an untrusted string from the content process to index into an Object:
this.notifications[origin][notification.id] = notification;

If origin is the string "__proto__", then we're now polluting the prototype of Object used by all JSMs, which can be taken advantage of later.

Assignee: nobody → peterv
Status: NEW → ASSIGNED

For posterity: We've decided that a spot fix is the saner approach given the reduced time we have and the amount of code it would have to touch otherwise. Fix for the underlying issue of prototype pollutions in JS IPC code will happen in through Bug #1770057, but not immediately.

Comment on attachment 9277284 [details]
Bug 1770137 - Make notification code use Object.create. r?gijs!,freddyb!

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: I think it shouldn't be too hard for people who know about prototype pollution to figure out how to exploit this.
  • 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
  • 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?: Patch should just apply.
  • How likely is this patch to cause regressions; how much testing does it need?: This shouldn't be very risky.

I'll note here that nightly uses a different implementation, so the patch would be a noop there :-/.

  • Is Android affected?: Yes
Attachment #9277284 - Flags: sec-approval?
See Also: → 1770154

This code is disabled in Nightly (see bug 1770154), so I'm marking 102 as disabled. We still want to land the patch there, but that should be kept in mind for testing and verification purposes.

Comment on attachment 9277284 [details]
Bug 1770137 - Make notification code use Object.create. r?gijs!,freddyb!

Approved to move forward

Attachment #9277284 - Flags: sec-approval? → sec-approval+
Group: firefox-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch

Comment on attachment 9277284 [details]
Bug 1770137 - Make notification code use Object.create. r?gijs!,freddyb!

Beta/Release Uplift Approval Request

  • User impact if declined: sandbox escape
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: IIRC we don't have a reliable QE test strategy for this change yet. :mccr8 is working on building a snippet which we'll be able to paste in the browser content toolbox to test this fix (though it will only work on Beta and Release)
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This shouldn't be very risky. Nightly uses a different version of the code.
  • String changes made/needed: None
  • Is Android affected?: Yes

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration:
  • User impact if declined: sandbox escape
  • Fix Landed on Version: 102
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This shouldn't be very risky. Nightly uses a different version of the code.
Attachment #9277284 - Flags: approval-mozilla-release?
Attachment #9277284 - Flags: approval-mozilla-esr91?
Attachment #9277284 - Flags: approval-mozilla-beta?
Flags: qe-verify+

Comment on attachment 9277284 [details]
Bug 1770137 - Make notification code use Object.create. r?gijs!,freddyb!

Approved for 100.0.2
Approved for 101.0b9
Approved for 91.9.1esr

Attachment #9277284 - Flags: approval-mozilla-release?
Attachment #9277284 - Flags: approval-mozilla-release+
Attachment #9277284 - Flags: approval-mozilla-esr91?
Attachment #9277284 - Flags: approval-mozilla-esr91+
Attachment #9277284 - Flags: approval-mozilla-beta?
Attachment #9277284 - Flags: approval-mozilla-beta+

Steps to reproduce:

You want to start with a fresh profile. (The important factor is that we need to make sure there are no existing saved notifications, which will show up as notificationstore.json in the profile directory. You can just delete that file to get back to the "fresh" state when the browser is not running.)

  1. First, you have to enable the browser toolbox.

a) Hamburger menu --> More tools --> Developer tools

b) Click on the ... next to the x on the developer tools bar, then click on settings. Under "Advanced settings" in the lower right, check "Enable browser chrome and addon-on debugging toolboxes" and "Enable remote debugging".

  1. Now, load the browser toolbox. Hamburger menu --> More tools --> Browser toolbox.

  2. In the window that pops up, at the bottom there is an area for console input starting with ">>". Click on that to get a cursor, then paste in the following string and hit enter:

Services.cpmm.sendAsyncMessage("Notification:Save", {origin:"__proto__", notification: { id: "someKey" }}); setTimeout(() => { alert("This should be undefined: " + Cu.getGlobalForObject(Services).Object.prototype.someKey); }, 100);

This will pop up an alert in main browser window. It will say "This should be undefined" followed by a JS value. If it says "undefined", then the exploit is fixed. If it says "[Object]", it is not.

  1. Now, exit the browser, start the browser again, then repeat steps 2 and 3. The pop up should again say undefined. (This tests a separate code path when we restore the notifications from disk, and was unfixed in the initial patch.)

Also note that in my experiments the browser would hang and crash on exit in the cases where the test failed, probably because the Object prototype got messed up, but there's no need to worry about that.

(Nika helped me put these steps together.)

Alias: CVE-2022-1802

Per the Slack channel, we need a follow-up patch for this bug.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attachment #9277369 - Attachment description: Bug 1770137 - Part , r=gijs → Bug 1770137 - Part 2, r=gijs
See Also: → 1770227

For the purposes of this bug, a "fresh state" in a profile seems to mean that notificationstore.json doesn't exist in the profile directory, so you can delete that file to get back to a fresh state. With only the initial patch, you get something like: delete notificationstore.json, start browser, run test. Test passes. (Test causes a new notificationstore.json to be created...) Restart browser, run test. Now the test fails.

Comment on attachment 9277369 [details]
Bug 1770137 - Part 2, r=gijs

Beta/Release Uplift Approval Request

  • User impact if declined: sandbox escape for existing profiles
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: see comment 10, try on both new and existing profiles.
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): quick fix to remaining hole from previous spot-fix.
  • String changes made/needed: None
  • Is Android affected?: Yes

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration:
  • User impact if declined: sandbox escape for existing profiles
  • Fix Landed on Version:
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): quick fix to remaining hole from previous spot-fix.
Attachment #9277369 - Flags: approval-mozilla-release?
Attachment #9277369 - Flags: approval-mozilla-esr91?
Attachment #9277369 - Flags: approval-mozilla-beta?

Comment on attachment 9277369 [details]
Bug 1770137 - Part 2, r=gijs

Approved for 100.0.2
Approved for 101.0b9
Approved for 91.9.1esr

Attachment #9277369 - Flags: approval-mozilla-release?
Attachment #9277369 - Flags: approval-mozilla-release+
Attachment #9277369 - Flags: approval-mozilla-esr91?
Attachment #9277369 - Flags: approval-mozilla-esr91+
Attachment #9277369 - Flags: approval-mozilla-beta?
Attachment #9277369 - Flags: approval-mozilla-beta+

Verified as fixed on macOS 11.6, Windows 10 x64 and on Ubuntu 20.04 x64.

Verified as fixed on Mobile Fenix/Focus RC 100.3.0 and Beta 101.0.0 Beta 6.

See Also: → 1770848
See Also: → 1771026
Group: core-security-release
Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: