Closed
Bug 1167888
(CVE-2015-2736)
Opened 10 years ago
Closed 9 years ago
nsZipArchive::BuildFileList has memory-safety bug
Categories
(Core :: Networking: JAR, defect)
Tracking
()
RESOLVED
FIXED
mozilla41
People
(Reporter: q1, Assigned: baku)
References
Details
(4 keywords, Whiteboard: [adv-main39+][adv-esr38.1+][adv-esr31.8+])
Attachments
(1 file)
934 bytes,
patch
|
smaug
:
review+
dveditz
:
approval-mozilla-aurora+
dveditz
:
approval-mozilla-beta+
dveditz
:
approval-mozilla-esr31+
dveditz
:
approval-mozilla-esr38+
dveditz
:
sec-approval+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows; rv:***) Gecko/20100101 Firefox/**.*
Build ID: 20150305021524
Steps to reproduce:
An attacker could force nsZipArchive::BuildFileList to read memory that it does not own, possibly leading to a crash, disclosure of sensitive information, or execution of code chosen by an attacker.
The problem is in the function's failure to validate the offsets of zip central directories.
Code beginning at line 624 extracts the first central directory offset from the zip-end record:
624: for (buf = endp - ZIPEND_SIZE; buf > startp; buf--)
625: {
626: if (xtolong(buf) == ENDSIG) {
627: centralOffset = xtolong(((ZipEnd *)buf)->offset_central_dir);
628: break;
629: }
630: }
631: }
Line 637 then sets the buffer pointer buf to "startp + centralOffset" without doing more than a cursory validation of centralOffset:
632:
633: if (!centralOffset)
634: return NS_ERROR_FILE_CORRUPTED;
635:
636: //-- Read the central directory headers
637: buf = startp + centralOffset;
The code then uses buf to find and read central directories:
638: uint32_t sig = 0;
639: while (buf + int32_t(sizeof(uint32_t)) <= endp &&
640: (sig = xtolong(buf)) == CENTRALSIG) {
641: // Make sure there is enough data available.
642: if (endp - buf < ZIPCENTRAL_SIZE)
643: return NS_ERROR_FILE_CORRUPTED;
644:
645: // Read the fixed-size data.
646: ZipCentral* central = (ZipCentral*)buf;
647:
648: uint16_t namelen = xtoint(central->filename_len);
649: ... // lots more where that came from
The problem occurs if the first-encountered zip-end record contains an offset_central_dir field that is very large, thus making centralOffset very large. In this case, the RHS of line 637 can overflow (especially on 32-bit platforms), setting buf to somewhere < startp. Since buf is then perforce < endp, this does not trip the check on line 639.
If *buf happens to contain CENTRALSIG, the code at line 638 et seq interprets it as a valid central directory, with unpredictable consequences further down the road when it's used. I guess that this defect could be used, for example, to inject Javascript from domain A into domain B.
This bug might explain https://bugzilla.mozilla.org/show_bug.cgi?id=596826 .
Assignee | ||
Comment 1•10 years ago
|
||
Attachment #8610176 -
Flags: review?(bugs)
Updated•10 years ago
|
Component: Untriaged → Networking: JAR
Product: Firefox → Core
Comment 2•10 years ago
|
||
Comment on attachment 8610176 [details] [diff] [review]
zip2.patch
This needs to land very late in a cycle :/
Attachment #8610176 -
Flags: review?(bugs) → review+
Assignee | ||
Comment 3•10 years ago
|
||
Comment on attachment 8610176 [details] [diff] [review]
zip2.patch
[Security approval request comment]
How easily could an exploit be constructed based on the patch?
A malformed zip file can cause this issue.
Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?
Yes.
Which older supported branches are affected by this flaw?
This code landed in 2009. All the branches are effected.
If not all supported branches, which bug introduced the flaw?
bug 511754
Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be?
It's easy to create a backport patch. And it's not risky at all.
How likely is this patch to cause regressions; how much testing does it need?
No regressions.
Attachment #8610176 -
Flags: sec-approval?
Assignee | ||
Updated•10 years ago
|
Assignee: nobody → amarchesini
Updated•10 years ago
|
Blocks: 511754
Status: UNCONFIRMED → NEW
status-b2g-v2.0:
--- → affected
status-b2g-v2.0M:
--- → affected
status-b2g-v2.1:
--- → affected
status-b2g-v2.1S:
--- → affected
status-b2g-v2.2:
--- → affected
status-b2g-master:
--- → affected
status-firefox38:
--- → wontfix
status-firefox39:
--- → affected
status-firefox40:
--- → affected
status-firefox41:
--- → affected
status-firefox-esr31:
--- → affected
status-firefox-esr38:
--- → affected
Ever confirmed: true
Keywords: regression
Comment 4•10 years ago
|
||
Comment on attachment 8610176 [details] [diff] [review]
zip2.patch
This patch (especially combined with the other similar one) draws attention to overflow math in this file so we need to fix the similar problems a few lines down while we're here. (namelen is sanity checked, but extralen and commentlen aren't, and addition of small values could overflow anyway under the right circumstances). One possible check would be to compare (endp - buf) to the sizes.
Attachment #8610176 -
Flags: sec-approval?
Attachment #8610176 -
Flags: sec-approval-
Attachment #8610176 -
Flags: review-
Assignee | ||
Comment 5•10 years ago
|
||
I guess we can combine this patch with the other one. I asked a review for the other patch and in that patch I fix what you suggest here.
Flags: needinfo?(dveditz)
Comment 6•10 years ago
|
||
sounds good.
Flags: needinfo?(dveditz)
Keywords: csectype-intoverflow,
sec-high
Assignee | ||
Comment 7•10 years ago
|
||
dveditz, when can we land these 2 patches?
Flags: needinfo?(dveditz)
Updated•10 years ago
|
status-firefox38.0.5:
--- → wontfix
tracking-firefox39:
--- → +
tracking-firefox40:
--- → +
tracking-firefox41:
--- → +
tracking-firefox-esr31:
--- → 39+
tracking-firefox-esr38:
--- → 39+
Flags: needinfo?(dveditz)
Whiteboard: [wait until June 4 to land]
Comment 8•10 years ago
|
||
Comment on attachment 8610176 [details] [diff] [review]
zip2.patch
a=dveditz and sec-approval for all the branches, to land on June 4
Attachment #8610176 -
Flags: sec-approval-
Attachment #8610176 -
Flags: sec-approval+
Attachment #8610176 -
Flags: review-
Attachment #8610176 -
Flags: approval-mozilla-esr38+
Attachment #8610176 -
Flags: approval-mozilla-esr31+
Attachment #8610176 -
Flags: approval-mozilla-beta+
Attachment #8610176 -
Flags: approval-mozilla-aurora+
Updated•10 years ago
|
Whiteboard: [wait until June 4 to land] → [checkin on 6/4]
Assignee | ||
Comment 9•10 years ago
|
||
checkin-needed but read comment 8 before landing.
Keywords: checkin-needed
Updated•10 years ago
|
Keywords: checkin-needed
Updated•10 years ago
|
Flags: sec-bounty?
Assignee | ||
Comment 10•10 years ago
|
||
Comment 11•10 years ago
|
||
Flags: in-testsuite?
Whiteboard: [checkin on 6/4]
Target Milestone: --- → mozilla41
Comment 12•10 years ago
|
||
Comment 13•10 years ago
|
||
https://hg.mozilla.org/releases/mozilla-esr38/rev/fcb018657fb6
https://hg.mozilla.org/releases/mozilla-b2g37_v2_2/rev/f2157a04d75b
https://hg.mozilla.org/releases/mozilla-b2g34_v2_1/rev/25ae62aef2c1
https://hg.mozilla.org/releases/mozilla-b2g34_v2_1s/rev/25ae62aef2c1
https://hg.mozilla.org/releases/mozilla-b2g32_v2_0/rev/5e363e84b661
https://hg.mozilla.org/releases/mozilla-b2g32_v2_0m/rev/5e363e84b661
https://hg.mozilla.org/releases/mozilla-esr31/rev/917d8e07d42b
Comment 15•9 years ago
|
||
Andrea, is manual verification needed for this fix? If yes, could you provide us with some testing details?
Flags: needinfo?(amarchesini)
Assignee | ||
Comment 16•9 years ago
|
||
I don't think this can be test manually.
Flags: needinfo?(amarchesini)
Comment 17•9 years ago
|
||
(In reply to Andrea Marchesini (:baku) from comment #16)
> I don't think this can be test manually.
Thank you Andrea! Setting as qe-verify- then.
Flags: qe-verify-
Updated•9 years ago
|
Flags: sec-bounty? → sec-bounty+
Updated•9 years ago
|
Whiteboard: [adv-main39+][adv-esr38.1+][adv-esr31.8+]
Updated•9 years ago
|
Alias: CVE-2015-2736
Updated•9 years ago
|
Group: core-security → core-security-release
Updated•8 years ago
|
Group: core-security-release
Updated•6 months ago
|
Keywords: reporter-external
You need to log in
before you can comment on or make changes to this bug.
Description
•