Closed Bug 1842658 (CVE-2023-4049) Opened 2 years ago Closed 2 years ago

Clean up some manual AddRef/Release implementations

Categories

(Core :: XPCOM, defect)

defect

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox-esr102 116+ fixed
firefox-esr115 116+ fixed
firefox115 --- wontfix
firefox116 + fixed
firefox117 + fixed

People

(Reporter: nika, Assigned: nika)

Details

(Keywords: csectype-race, sec-high, Whiteboard: [adv-main116+] [adv-ESR115.1+] [adv-ESR102.14+])

Attachments

(3 files)

While reading over the refcnt implementations in https://phabricator.services.mozilla.com/D182992, I noticed some of the implementations were manual and in some cases a bit sketchy when they didn't need to be.

This patch is to track cleaning them up, and potentially fixing race issues in atomic refcounts which were not being handled correctly.

Group: core-security → dom-core-security
Keywords: csectype-race

It appears that when this was originally added in bug 430061, the inline
refcounting macros didn't exist yet.

When the code was originally added in bug 1842658, it was to use non-atomic
refcounting across multiple threads due to some invariants preventing
concurrent access. That was changed in bug 1607762 to fix a race issue.

We should be able to switch to using the macros now, which will simplify the
code here a bit.

Depends on D183203

Nika pointed out that this can lead to double frees (which could lead to UAFs), if the refcount is at 2, then 2 threads decrement, then they both read the refcount as zero, so I'm going to mark this sec-high. I don't know how easily exploitable that is for these particular classes. These don't look directly exposed to web content, but they can certainly be created and destroyed by it.

Keywords: sec-high

Specifically the sec-high part is only part 2, part 1 should have no changes due to it never being a threadsafe refcnt.

Comment on attachment 9343147 [details]
Bug 1842658 - Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8!

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: It would be quite difficult to. The issue is due to multiple atomic loads during a Release function of a platform object.
  • 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?: Bug 1607762
  • Do you have backports for the affected branches?: No
  • If not, how different, hard to create, and risky will they be?: I expect that the patch will apply cleanly on all impacted branches.
  • How likely is this patch to cause regressions; how much testing does it need?: Unlikely to cause regressions
  • Is Android affected?: Yes
Attachment #9343147 - Flags: sec-approval?
Attachment #9343146 - Flags: sec-approval?

Comment on attachment 9343147 [details]
Bug 1842658 - Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8!

Approved to land and uplift if desired.

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

Comment on attachment 9343146 [details]
Bug 1842658 - Part 1: Use a refcounting macro for imgCacheEntry, r=emilio!

Approved to land and uplift if desired.

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

Comment on attachment 9343147 [details]
Bug 1842658 - Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8!

Beta/Release Uplift Approval Request

  • User impact if declined: Potential race condition leading to UAF.

Only part 2 could actually lead to a security issue, so part 1 could be not uplifted if desired, but they uplift well as a package.

  • 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): Change to use battle-tested reference counting macros rather than manually implemented reference counting on some objects.
  • 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: Potential race condition leading to UAF.

Only part 2 could actually lead to a security issue, so part 1 could be not uplifted if desired, but they uplift well as a package.

  • Fix Landed on Version:
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Change to use battle-tested reference counting macros rather than manually implemented reference counting on some objects.
Attachment #9343147 - Flags: approval-mozilla-esr115?
Attachment #9343147 - Flags: approval-mozilla-beta?
Attachment #9343146 - Flags: approval-mozilla-beta?
Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/642d09cfa740 Part 1: Use a refcounting macro for imgCacheEntry, r=tnikkel https://hg.mozilla.org/integration/autoland/rev/509bf5b39d3f Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8
Group: dom-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch

Comment on attachment 9343146 [details]
Bug 1842658 - Part 1: Use a refcounting macro for imgCacheEntry, r=emilio!

Approved for 116.0b6

Attachment #9343146 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9343147 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Comment on attachment 9343147 [details]
Bug 1842658 - Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8!

Approved for 115.1esr

Attachment #9343147 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+
Attachment #9343147 - Flags: approval-mozilla-esr102?
QA Whiteboard: [post-critsmash-triage]

Comment on attachment 9343147 [details]
Bug 1842658 - Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8!

Approved for 102.14esr

Attachment #9343147 - Flags: approval-mozilla-esr102? → approval-mozilla-esr102+
Whiteboard: [adv-main116+] [adv-ESR115.1+] [adv-ESR102.14+]
Group: core-security-release
Alias: CVE-2023-4049
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: