Closed Bug 1182723 (CVE-2015-4489) Opened 9 years ago Closed 9 years ago

Self-assignment in nsTArray_Impl causes memory-safety bug

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla42
Tracking Status
firefox39 --- wontfix
firefox40 + fixed
firefox41 + fixed
firefox42 + fixed
firefox-esr31 --- wontfix
firefox-esr38 40+ fixed
b2g-v2.0 --- fixed
b2g-v2.0M --- fixed
b2g-v2.1 --- fixed
b2g-v2.1S --- fixed
b2g-v2.2 --- fixed
b2g-v2.2r --- fixed
b2g-master --- fixed

People

(Reporter: q1, Assigned: poiru)

References

Details

(Keywords: csectype-uaf, sec-high, Whiteboard: [post-critsmash-triage][adv-main40+][adv-esr38.2+])

Attachments

(2 files)

Assigning an array object based upon nsTArray_Impl to itself causes the destruction of the array's elements, followed by the construction of new elements from the memory that contained the destroyed elements. If the element type has a nontrivial destructor, this almost certainly results in the construction of invalid new elements, such as those containing pointers to unowned memory.

The bug is that the copy-assignment operator does not check for self-assignment.

I do not know whether any code actually does such a self-assignment.

There is also a similar bug in the move-assignment operator, which is less serious because it clears the object, then assigns it to itself.
Flags: needinfo?(nfroyd)
Flags: sec-bounty?
Attachment #8633045 - Flags: review?(continuation)
Assignee: nobody → birunthan
Status: NEW → ASSIGNED
Comment on attachment 8633045 [details] [diff] [review]
Properly handle self-assignment in nsTArray::operator=

Review of attachment 8633045 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks for fixing this.  Sorry for the delay in my review.

Do you think it is likely that we're hitting this issue in the codebase? That will affect whether we need to backport this and (maybe) the security rating. I guess you could do a try push that just crashes on self-assignment as a basic smoke test.
Attachment #8633045 - Flags: review?(continuation) → review+
Flags: needinfo?(nfroyd)
(In reply to Andrew McCreight [:mccr8] from comment #2)
> Do you think it is likely that we're hitting this issue in the codebase?
> That will affect whether we need to backport this and (maybe) the security
> rating. I guess you could do a try push that just crashes on self-assignment
> as a basic smoke test.

We seem to be: https://treeherder.mozilla.org/#/jobs?repo=try&revision=6190cff0f3e2 (please ignore the build oranges, I forgot to remove the test)
Depends on: 1185589
Comment on attachment 8633045 [details] [diff] [review]
Properly handle self-assignment in nsTArray::operator=

[Security approval request comment]
How easily could an exploit be constructed based on the patch?

Not sure.

Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?

The patch is obvious so an empty commit message is probably as much of a bulls-eye as a clear commit message.

Which older supported branches are affected by this flaw?

All (release, esr, etc.).

Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be?

Easy, no risk.

How likely is this patch to cause regressions; how much testing does it need?

Very unlikely.
Attachment #8633045 - Flags: sec-approval?
(In reply to Birunthan Mohanathas [:poiru] from comment #3)
> We seem to be:

Thanks for checking. Seems like there's enough that I'll just mark this as sec-high, though some of those cases might be benign arrays with elements with boring data types.
sec-approval+. We should also get patches made and nominated for Aurora, Beta, and ESR38.
Attachment #8633045 - Flags: sec-approval? → sec-approval+
This is a version of the patch without tests because the older branches don't have TestTArray.cpp. The patch is trivial and the test is green on 42 so we don't need a test on the older branches.

[Approval Request Comment]
Fix Landed on Version: 42
Risk to taking this patch (and alternatives if risky): Minimal
String or UUID changes made by this patch: None

This should land along with bug 1185589. Order does not matter.
Attachment #8636665 - Flags: approval-mozilla-esr38?
Attachment #8636665 - Flags: approval-mozilla-beta?
Attachment #8636665 - Flags: approval-mozilla-aurora?
Comment on attachment 8636665 [details] [diff] [review]
esr38/40/41 patch without tests

Branch patches approved.

We probably should have landed the trunk one without a test. I missed that you included one. Too late now though.
Attachment #8636665 - Flags: approval-mozilla-esr38?
Attachment #8636665 - Flags: approval-mozilla-esr38+
Attachment #8636665 - Flags: approval-mozilla-beta?
Attachment #8636665 - Flags: approval-mozilla-beta+
Attachment #8636665 - Flags: approval-mozilla-aurora?
Attachment #8636665 - Flags: approval-mozilla-aurora+
The C++ doesn't make it any more obvious or easier to exploit than the code change itself.
(In reply to Andrew McCreight [:mccr8] from comment #10)
> The C++ doesn't make it any more obvious or easier to exploit than the code
> change itself.

Err... the C++ test, I meant.
(In reply to Birunthan Mohanathas [:poiru] from comment #7)
> https://hg.mozilla.org/integration/mozilla-inbound/rev/bcf65c04b69c

This landed with the wrong bug # in the commit message.

https://hg.mozilla.org/mozilla-central/rev/bcf65c04b69c
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Whiteboard: [post-critsmash-triage]
Flags: sec-bounty? → sec-bounty+
Whiteboard: [post-critsmash-triage] → [post-critsmash-triage][adv-main40+][adv-esr38.2+]
Alias: CVE-2015-4489
Group: core-security
You need to log in before you can comment on or make changes to this bug.