Closed
Bug 1117406
Opened 10 years ago
Closed 10 years ago
PNG: heap-overflow crash [@qcms_transform_data_rgba_out_lut_sse2]
Categories
(Core :: Graphics: ImageLib, defect)
Tracking
()
VERIFIED
FIXED
mozilla38
People
(Reporter: posidron, Assigned: glennrp+bmo)
Details
(4 keywords, Whiteboard: [adv-main36+][adv-esr31.5+])
Attachments
(8 files, 6 obsolete files)
61.71 KB,
application/octet-stream
|
Details | |
14.37 KB,
text/plain
|
Details | |
922 bytes,
text/html
|
Details | |
3.44 KB,
text/html
|
Details | |
2.14 KB,
patch
|
jrmuizel
:
review+
abillings
:
sec-approval+
|
Details | Diff | Splinter Review |
2.19 KB,
patch
|
abillings
:
approval-mozilla-beta+
|
Details | Diff | Splinter Review |
2.14 KB,
patch
|
abillings
:
approval-mozilla-aurora+
|
Details | Diff | Splinter Review |
2.16 KB,
patch
|
abillings
:
approval-mozilla-esr31+
|
Details | Diff | Splinter Review |
No description provided.
Reporter | ||
Comment 1•10 years ago
|
||
Reporter | ||
Comment 2•10 years ago
|
||
Comment 3•10 years ago
|
||
The png file is data_1_output_Output.txt
Assignee | ||
Comment 4•10 years ago
|
||
pngcheck and ImageMagick reports about the test image:
glenn.rp> pngcheck -v data_1_output_Output.txt
File: data_1_output_Output.txt (46657 bytes)
chunk IHDR at offset 0x0000c, length 13
200 x 171 image, 24-bit RGB, interlaced
chunk tEXt at offset 0x00025, length 43, keyword: Creation Time
chunk tIME at offset 0x0005c, length 7: 5 Apr 2006 13:09:43 UTC
chunk pHYs at offset 0x0006f, length 9: 2834x2834 pixels/meter (72 dpi)
chunk gAMA at offset 0x00084, length 4: 0.45455
chunk tRNS at offset 0x00094, length 6
red = 0x04be, green = 0xf9c7, blue = 0x4165
chunk IDAT at offset 0x000a6, length 46471
zlib: deflated, 32K window, maximum compression
CRC error in chunk IDAT (computed b5f11d99, expected 6275f80e)
ERRORS DETECTED in data_1_output_Output.txt
glenn.rp> cp data_1_output_Output.txt crash.png
glenn.rp> identify -verbose crash.png # (ImageMagick, built with libpng-1.6.16)
identify: tRNS chunk has out-of-range samples for bit_depth `crash.png' @ warning/png.c/MagickPNGWarningHandler/1656.
identify: IDAT: invalid distance too far back `crash.png' @ error/png.c/MagickPNGErrorHandler/1630.
identify: corrupt image `crash.png' @ error/png.c/ReadPNGImage/3957.
Assignee | ||
Comment 5•10 years ago
|
||
Can you verify that you were using gfx.color_management.mode=1? I think that with mode=0 or mode=2, while
reading a PNG with a gAMA chunk but no cHRM chunk, we wouldn't reach the bug.
Flags: needinfo?(cdiehl)
Assignee | ||
Updated•10 years ago
|
Assignee: nobody → glennrp+bmo
Status: NEW → ASSIGNED
Reporter | ||
Comment 6•10 years ago
|
||
(In reply to Glenn Randers-Pehrson from comment #5)
> Can you verify that you were using gfx.color_management.mode=1? I think
> that with mode=0 or mode=2, while
> reading a PNG with a gAMA chunk but no cHRM chunk, we wouldn't reach the bug.
user_pref("gfx.color_management.mode", 1);
Confirmed.
Flags: needinfo?(cdiehl)
Assignee | ||
Comment 7•10 years ago
|
||
Thanks. The default configuration (with gfx.color_management.mode=2)
would be vulnerable as well, if the test case had included a valid cHRM chunk or
sRGB chunk. I'm now setting up to test whether the invalid tRNS chunk is
causing the crash due to some mixup of whether channels is 3 or 4 in the
PNG decoder and/or in libpng.
Assignee | ||
Comment 8•10 years ago
|
||
Here's a simpler test case. It's a valid PNG except that the tRNS chunk values are out of range. I verified that when decoding this and the original test case, the PNG decoder calls GetCMSRGBATransform() when it should be calling GetCMSRGBTransform(), which leads to an overwrite beyond the last row of interlacebuf. I expect to have a patch ready tomorrow. I wasn't able to get an ASAN build working on my machine, so it would be good to verify that the simple test case also triggers the ASAN crash.
Flags: needinfo?(cdiehl)
Assignee | ||
Comment 9•10 years ago
|
||
Please try this patch. It removes the special handling of out-of-range tRNS values from nsPNGDecoder.cpp; it was getting it wrong anyway.
Flags: needinfo?(ryanvm)
Reporter | ||
Comment 10•10 years ago
|
||
(In reply to Glenn Randers-Pehrson from comment #8)
> Created attachment 8544359 [details]
> Simpler test case, bug1117406.html
> I wasn't able to get an ASAN build working on my machine, so it would be good
> to verify that the simple test case also triggers the ASAN crash.
We have ASan builds here: https://ftp.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/mozilla-central-linux64-asan/latest/
Flags: needinfo?(cdiehl)
Assignee | ||
Comment 11•10 years ago
|
||
Verified that the simpler test case also crashes ("Tab crashed" + asan report), tested with downloaded ASAN build of 6 Jan 2015.
Assignee | ||
Comment 12•10 years ago
|
||
Comment on attachment 8544530 [details] [diff] [review]
v00-1117406-let-libpng-handle-out-of-range-tRNS
The v00 patch does stop the crash but it also regresses bug #428045
Attachment #8544530 -
Attachment is obsolete: true
Flags: needinfo?(ryanvm)
Comment 13•10 years ago
|
||
I assume this affects pretty much any supported Gecko revision?
Flags: needinfo?(glennrp+bmo)
Assignee | ||
Comment 14•10 years ago
|
||
(In reply to Ryan VanderMeulen [:RyanVM UTC-5] from comment #13)
> I assume this affects pretty much any supported Gecko revision?
Yeah, back to Firefox 1.9.1 or so. I'll upload a v01 patch shortly.
Flags: needinfo?(glennrp+bmo)
Comment 15•10 years ago
|
||
FYI, this missed Firefox 35 already (the release candidate was built yesterday), so it'll probably need to wait to land until sometime in the middle of the next cycle. The sec team will say for sure when they respond to the sec-approval request on the patch.
status-b2g-v1.4:
--- → affected
status-b2g-v2.0:
--- → affected
status-b2g-v2.0M:
--- → affected
status-b2g-v2.1:
--- → affected
status-b2g-v2.2:
--- → affected
status-firefox34:
--- → wontfix
status-firefox35:
--- → wontfix
status-firefox36:
--- → affected
status-firefox37:
--- → affected
status-firefox-esr31:
--- → affected
tracking-firefox36:
--- → ?
tracking-firefox37:
--- → ?
tracking-firefox-esr31:
--- → ?
Assignee | ||
Comment 17•10 years ago
|
||
(In reply to Glenn Randers-Pehrson from comment #14)
> (In reply to Ryan VanderMeulen [:RyanVM UTC-5] from comment #13)
> > I assume this affects pretty much any supported Gecko revision?
>
> Yeah, back to Firefox 1.9.1 or so. I'll upload a v01 patch shortly.
Actually anything since August 19, 2008, when I introduced the bug, which
is a missing "num_trans = 0;" in nsPNGDecoder.cpp.
Comment 18•10 years ago
|
||
Flags: needinfo?(ryanvm)
Assignee | ||
Comment 19•10 years ago
|
||
Comment on attachment 8544801 [details] [diff] [review]
v01-1117406-fix-handling-out-of-range-tRNS
The try run looks good. I downloaded the asan build and it shows the simple test case without a crash, and does not regress bug #42805 (see http://www.simplesystems.org/users/glennrp/tRNS/). R?
Attachment #8544801 -
Flags: review?(jmuizelaar)
Comment 20•10 years ago
|
||
Comment on attachment 8544801 [details] [diff] [review]
v01-1117406-fix-handling-out-of-range-tRNS
Review of attachment 8544801 [details] [diff] [review]:
-----------------------------------------------------------------
::: image/decoders/nsPNGDecoder.cpp
@@ +560,5 @@
>
> if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
> int sample_max = (1 << bit_depth);
> png_color_16p trans_values;
> png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values);
Is it possible for this call to fail?
Assignee | ||
Comment 21•10 years ago
|
||
png_get_valid returns 0 or nonzero
sample_max can overflow if sizeof(int) is 16 bits or less but that's harmless;
it would just roll around to zero. That was fixed a while ago in libpng17
but hasn't been backported to libpng16 yet.
png_get_tRNS returns 0 or nonzero, and fills
in trans (a byte array), num_trans (a png_uint_32 integer),
and trans_values (a png_uint_16 struct), after checking
each of those arguments for NULL first.
But it can provide a wrong answer, if bit_depth is 8 or less but
any of trans_values is greater than 255. Libpng produces a warning
in that situation, but we ignore all libpng warnings in non-debug
builds.
Assignee | ||
Comment 22•10 years ago
|
||
Rebased against last night's update to nsPNGDecoder.cpp
Attachment #8544801 -
Attachment is obsolete: true
Attachment #8544801 -
Flags: review?(jmuizelaar)
Attachment #8546641 -
Flags: review?(jmuizelaar)
Comment 23•10 years ago
|
||
Comment on attachment 8546641 [details] [diff] [review]
v02-1117406-fix-handling-out-of-range-tRNS
Review of attachment 8546641 [details] [diff] [review]:
-----------------------------------------------------------------
::: image/decoders/nsPNGDecoder.cpp
@@ +564,5 @@
> (int)trans_values->green > sample_max ||
> (int)trans_values->blue > sample_max))) {
> // clear the tRNS valid flag and release tRNS memory
> png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
> + num_trans=0; // this line added at bug #1117406
Drop this comment and add spaces around '='.
You could also add a comment like:
// reset num_trans so that we don't try to use them.
Attachment #8546641 -
Flags: review?(jmuizelaar) → review+
Assignee | ||
Comment 24•10 years ago
|
||
Revised as requested.
Attachment #8546909 -
Flags: review?(jmuizelaar)
Assignee | ||
Comment 25•10 years ago
|
||
The v03 patch omitted the checkin info. Please transfer "r+" from v02 to v04.
Attachment #8546909 -
Attachment is obsolete: true
Attachment #8546909 -
Flags: review?(jmuizelaar)
Attachment #8547111 -
Flags: review?(jmuizelaar)
Updated•10 years ago
|
Attachment #8546641 -
Attachment is obsolete: true
Updated•10 years ago
|
Attachment #8547111 -
Flags: review?(jmuizelaar) → review+
Assignee | ||
Updated•10 years ago
|
Keywords: checkin-needed
Comment 26•10 years ago
|
||
Per comment 15, this needs to get sec-approval since it's a sec-crit affecting multiple branches.
https://wiki.mozilla.org/Security/Bug_Approval_Process
Keywords: checkin-needed
Assignee | ||
Comment 27•10 years ago
|
||
Demonstrates that bug #428045 was not completely fixed. It still accepts invalid trans values that are exactly 2^bit_depth and masks the top byte.
This happens even when the v03 patch is applied. Different bug, same piece of code.
Assignee | ||
Comment 28•10 years ago
|
||
Fix for the off-by-one error mentioned in the previous comment; also fixes the ASAN crash without drawing attention to that.
Assignee | ||
Comment 29•10 years ago
|
||
The v05 patch is essentially what's already in libpng-1.7.0beta47. The equivalent for the "num_trans = 0" fix has been in libpng17 since version 1.7.0alpha01, which was released December 15, 2012.
Updated•10 years ago
|
status-firefox38:
--- → affected
tracking-firefox38:
--- → +
Updated•10 years ago
|
Attachment #8547111 -
Attachment is obsolete: true
Flags: needinfo?(ryanvm)
Assignee | ||
Updated•10 years ago
|
Attachment #8547126 -
Flags: review?(jmuizelaar)
Comment 31•10 years ago
|
||
status-b2g-master:
--- → affected
Assignee | ||
Comment 32•10 years ago
|
||
patch for mozilla-release, tested locally on Ubuntu.
Assignee | ||
Comment 33•10 years ago
|
||
patch for mozilla-beta, tested locally on Ubuntu.
Assignee | ||
Comment 34•10 years ago
|
||
The v05-1117406-* patch can also be applied to aurora, without any modification. Tested locally with Ubuntu 14:04.
Assignee | ||
Comment 35•10 years ago
|
||
I verified that a trivial variation of the "simpler test case" will crash recent regular (non-asan) nightlies with "Tab crashed".
Assignee | ||
Comment 36•10 years ago
|
||
(In reply to Ryan VanderMeulen [:RyanVM UTC-5] from comment #26)
> Per comment 15, this needs to get sec-approval since it's a sec-crit
> affecting multiple branches.
I've got a security-request comment ready for the v05 patch, once v05 gets r+.
Flags: needinfo?(ryanvm)
Flags: needinfo?(jmuizelaar)
Updated•10 years ago
|
Flags: needinfo?(ryanvm)
Updated•10 years ago
|
Attachment #8547126 -
Flags: review?(jmuizelaar) → review+
Assignee | ||
Comment 37•10 years ago
|
||
Comment on attachment 8547126 [details] [diff] [review]
v05-1117406-fix-handling-out-of-range-tRNS
[Security approval request comment]
How easily could an exploit be constructed based on the patch?
Easily, if an attacker notices the addition of "num_trans = 0" and investigates why. Hopefully the patch draws attention away from that by fixing a closely related but harmless bug at the same time. The attacker would need to convince the target user to run with the non-default gfx.color_management.mode==1.
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 #428025
Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be?
Yes, patches for release and beta are attached to this bug. For aurura, use the same patch as for mozilla-central.
How likely is this patch to cause regressions; how much testing does it need?
Very unlikely. A patch equivalent to this one has been included in libpng17 since version 1.7.0alpha01, about 2 years ago. There may be a different appearance (not a regression) of images that have a tRNS chunk containing values that are exactly 2^bit_depth (e.g., 256 in a PNG with 8-bit samples); in such images the transparency handling will be done correctly instead of incorrectly.
Attachment #8547126 -
Flags: sec-approval?
Updated•10 years ago
|
Whiteboard: [checkin on 1/26]
Comment 38•10 years ago
|
||
Comment on attachment 8547126 [details] [diff] [review]
v05-1117406-fix-handling-out-of-range-tRNS
sec-approval+ for checkin on January 26. Please nominate Aurora, Beta, and ESR31 patches so we can check them in after everything is green on Trunk.
Attachment #8547126 -
Flags: sec-approval? → sec-approval+
Assignee | ||
Comment 39•10 years ago
|
||
Approval Request Comment
[Feature/regressing bug #]: 428025
[User impact if declined]: crash via malformed PNG
[Describe test coverage new/current, TBPL]: local tests with malformed PNG only due to security; tested on trunk with usual test set via tryserver
[Risks and why]: Low, patch is simple and this code has been used in libpng17 for 2 years
[String/UUID change made/needed]: none
This patch is identical to the v05-* patch for Trunk.
Flags: needinfo?(jmuizelaar)
Attachment #8551434 -
Flags: approval-mozilla-aurora?
Assignee | ||
Comment 40•10 years ago
|
||
Comment on attachment 8549294 [details] [diff] [review]
v05 (beta) -1117406-fix-handling-out-of-range-tRNS
Approval Request Comment
[Feature/regressing bug #]: 428025
[User impact if declined]: crash via malformed PNG
[Describe test coverage new/current, TBPL]: local tests with malformed PNG only due to security; tested on trunk with usual test set via tryserver
[Risks and why]: Low, patch is simple and this code has been used in libpng17 for 2 years
[String/UUID change made/needed]: none
This patch differs from the v05-* patch for trunk only in the offset of the changed code.
Attachment #8549294 -
Flags: approval-mozilla-beta?
Assignee | ||
Comment 41•10 years ago
|
||
Attachment #8551510 -
Flags: approval-mozilla-esr31?
Assignee | ||
Updated•10 years ago
|
Attachment #8549292 -
Attachment is obsolete: true
Updated•10 years ago
|
Attachment #8551434 -
Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Updated•10 years ago
|
Attachment #8549294 -
Flags: approval-mozilla-beta? → approval-mozilla-beta+
Updated•10 years ago
|
Attachment #8551510 -
Flags: approval-mozilla-esr31? → approval-mozilla-esr31+
Comment 42•10 years ago
|
||
Flags: in-testsuite?
Whiteboard: [checkin on 1/26]
Assignee | ||
Comment 43•10 years ago
|
||
Are you asking for a test case that would "paint a bullseye on the security problem"? If so, that would change the answer to that question in comment #37. I can provide one if that's what's required.
Flags: needinfo?(ryanvm)
Comment 44•10 years ago
|
||
We should land an automated test for this once Fx36 ships. I'm just setting the flag as a reminder.
Flags: needinfo?(ryanvm)
Comment 45•10 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
status-b2g-v2.1S:
--- → affected
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
Comment 46•10 years ago
|
||
Comment 47•10 years ago
|
||
Comment 48•10 years ago
|
||
Comment 49•10 years ago
|
||
Updated•10 years ago
|
Whiteboard: [adv-main36+][adv-esr31.5+]
Comment 50•10 years ago
|
||
Reproduced the original issue using the following build:
* http://inbound-archive.pub.build.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/mozilla-central-linux64-asan/1420110134/
** user_pref("gfx.color_management.mode", 1);
** data_1_output_Output.txt --> crash.png [Crashed]
** simpler test case bug1117406.html from comment #8 [Crashed]
Went through verification using the following builds:
* fx38: http://inbound-archive.pub.build.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/mozilla-central-linux64-asan/1424187631/
* fx37: http://inbound-archive.pub.build.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/mozilla-aurora-linux64-asan/1424185888/
* fx36: http://inbound-archive.pub.build.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/mozilla-beta-linux64-asan/1424184332/
* fx31.5.0esr: http://ftp.mozilla.org/pub/mozilla.org/firefox/candidates/31.5.0esr-candidates/build2/
Test Cases Used:
* Opened both POC mentioned above several times in regular windows/tabs
* Opened both POC mentioned above several times in private windows/tabs
* Opened both POC mentioned above several times in e10s windows/tabs (only applies to m-c)
* Ensured that fx didn't crash using both ("gfx.color_management.mode", 1); & ("gfx.color_management.mode", 2);
Status: RESOLVED → VERIFIED
Comment 51•10 years ago
|
||
Updated•9 years ago
|
Group: core-security → core-security-release
Updated•8 years ago
|
Group: core-security-release
You need to log in
before you can comment on or make changes to this bug.
Description
•