Closed Bug 1497246 (CVE-2022-34481) Opened 6 years ago Closed 2 years ago

integer overflow in nsTArray::ReplaceElementsAt

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
103 Branch
Tracking Status
firefox-esr91 102+ fixed
firefox101 --- wontfix
firefox102 + fixed
firefox103 + fixed

People

(Reporter: froydnj, Assigned: nika)

References

Details

(Keywords: csectype-intoverflow, sec-moderate, Whiteboard: [adv-main102+][adv-esr91.11+])

Attachments

(2 files)

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

Bug 1483699 handled a few cases of potential integer overflow in AppendElements/InsertElementsAt.  There's one case in ReplaceElementsAt that we didn't handle and can handle in this bug:

  // Adjust memory allocation up-front to catch errors.
  if (!ActualAlloc::Successful(this->template EnsureCapacity<ActualAlloc>(
        Length() + aArrayLen - aCount, sizeof(elem_type)))) {
    return nullptr;
  }

The addition of Length() + aArrayLen - aCount should be checked for overflow in some fashion.
(In reply to Nathan Froyd [:froydnj] from comment #0)
> +++ This bug was initially created as a clone of Bug #1483699 +++
> 
> Bug 1483699 handled a few cases of potential integer overflow in
> AppendElements/InsertElementsAt.  There's one case in ReplaceElementsAt that
> we didn't handle and can handle in this bug:
> 
>   // Adjust memory allocation up-front to catch errors.
>   if (!ActualAlloc::Successful(this->template EnsureCapacity<ActualAlloc>(
>         Length() + aArrayLen - aCount, sizeof(elem_type)))) {
>     return nullptr;
>   }
> 
> The addition of Length() + aArrayLen - aCount should be checked for overflow
> in some fashion.

Yes, please! I don't think the expression can overflow (because |aArrayLen| elements must exist in the array being added), but it can underflow because |aCount| appears to be unchecked on all nsTArray paths into ReplaceElementsAt ().

Nika, any ideas about who might be able to look at this bug? It seems like a shame to leave a fairly simple looking sec bug open for this long. Thanks.

Flags: needinfo?(nika)
Assignee: nobody → nika
Status: NEW → ASSIGNED
Flags: needinfo?(nika)
Group: dom-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 103 Branch

Please nominate this for Beta/ESR91 approval when you get a chance.

Flags: needinfo?(nika)

Comment on attachment 9279959 [details]
Bug 1497246 - Release-check aCount for underflow in ReplaceElementsAt, r=#xpcom-reviewers

Beta/Release Uplift Approval Request

  • User impact if declined: Slightly less validation in some nsTArray methods
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: Yes
  • 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): Minor change double-checking some math for underflow in nsTArray. The underflowing case should never be hit as it would require an index out-of-bounds error, but this adds some extra defense-in-depth.
  • String changes made/needed: None
  • Is Android affected?: Yes
Flags: needinfo?(nika)
Attachment #9279959 - Flags: approval-mozilla-beta?

Comment on attachment 9279959 [details]
Bug 1497246 - Release-check aCount for underflow in ReplaceElementsAt, r=#xpcom-reviewers

Approved for 102 beta 8, thanks.

Attachment #9279959 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9279959 - Flags: approval-mozilla-esr91?

Comment on attachment 9279959 [details]
Bug 1497246 - Release-check aCount for underflow in ReplaceElementsAt, r=#xpcom-reviewers

Approved for 91.11esr.

Attachment #9279959 - Flags: approval-mozilla-esr91? → approval-mozilla-esr91+
QA Whiteboard: [post-critsmash-triage]
Flags: qe-verify-
Whiteboard: [adv-main102+]
Alias: CVE-2022-34481
Whiteboard: [adv-main102+] → [adv-main102+][adv-esr91.11+]
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: