Closed
Bug 1045977
(CVE-2014-1564)
Opened 11 years ago
Closed 11 years ago
Apparent info leak caused by uninitialized memory with malformed GIFs
Categories
(Core :: Graphics: ImageLib, defect)
Tracking
()
VERIFIED
FIXED
mozilla34
People
(Reporter: lcamtuf, Assigned: mwu)
References
Details
(Keywords: csectype-uninitialized, reporter-external, sec-high, Whiteboard: [reporter-external][adv-main32+][adv-esr31.1+])
Attachments
(4 files, 1 obsolete file)
518.45 KB,
image/png
|
Details | |
64.29 KB,
text/plain
|
Details | |
1.81 KB,
patch
|
Sylvestre
:
approval-mozilla-aurora+
Sylvestre
:
approval-mozilla-beta+
abillings
:
sec-approval+
|
Details | Diff | Splinter Review |
1.86 KB,
patch
|
Sylvestre
:
approval-mozilla-esr31+
|
Details | Diff | Splinter Review |
Check this out:
http://lcamtuf.coredump.cx/ffgif/
The code repeatedly loads the same image via <img> and then puts it on <canvas>, comparing results. At least on my system, this generates somewhere between 4 and 8 distinct bitmaps. The differences are also apparent visually.
This feels awfully like the use of uninitialized memory; if that's the case, it sounds like a potential security-relevant info leak.
The image in question is:
http://lcamtuf.coredump.cx/ffgif/id:000110,src:000023.gif
Updated•11 years ago
|
Component: Security → ImageLib
Product: Firefox → Core
![]() |
||
Updated•11 years ago
|
Flags: sec-bounty?
Whiteboard: [reporter-external]
Comment 1•11 years ago
|
||
johns is going to check if this test case does anything interesting with ASan.
Comment 2•11 years ago
|
||
This doesn't seem to reproduce in asan builds, with or without optimize/debug. In a non-asan build one interesting thing I saw was this variant of the image:
> data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAR0lEQVRYhe3OoREAIAxD0WzAMGzTHZmtAlEZLArBVf7cfZt7kiTbsecqXfNjmTlsR0fqOgIAAAAAAAAAAAAAAAAAAAAA/HYA0VZS42M4bB0AAAAASUVORK5CYII=
Which has some random pixels in addition to the odd shade of grey, which definitely looks worrying
Comment 3•11 years ago
|
||
This also doesn't seem to reproduce in a debug/no-opt build without asan
Comment 4•11 years ago
|
||
johns was running on Linux and it seemed to happen fairly frequently. For me on OSX, I was only able to reproduce it once in a half dozen times, and there it only seemed to be a small difference.
OS: Windows 7 → All
Comment 5•11 years ago
|
||
So, this is the result of --disable-jemalloc, which also disables poisoning. ASAN does its own more thorough poisoning, so that could explain why the images were uniform in those builds.
Comment 6•11 years ago
|
||
Nick, if you wouldn't mind, could you see what this test case does in Valgrind? Thanks.
Flags: needinfo?(n.nethercote)
![]() |
||
Comment 7•11 years ago
|
||
Are we only supposed to see one variant?
Flags: needinfo?(n.nethercote)
Summary: Apparent uninitialized memory leak with malformed GIFs → Apparent info leak caused by uninitialized memory with malformed GIFs
![]() |
||
Comment 8•11 years ago
|
||
I got 163 variants(!) and heaps of undefined value error reports when running under Valgrind. They all seem to involve VolatileBuffers. See the attachment.
Note that each error has two parts:
- the "Conditional jump or move depends on uninitialised value(s)" part, which indicates where the undefined value was used in a dangerous way, and
- the "Uninitialised value was created by a heap allocation" part, which indicates where the undefined value came from.
For posterity, here are the Valgrind flags I used:
> valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access --num-callers=36 --leak-check=no --track-o
rigins=yes
Finally, ASan won't be able to detect these errors. Undefined value errors are the main class of errors that Valgrind can detect but ASan cannot. (MSan is supposed to detect them, but I think it's still experimental.)
Comment 9•11 years ago
|
||
Thanks, Nick!
Comment 10•11 years ago
|
||
Could you find somebody to look into this, Milan? Thanks.
Flags: needinfo?(milan)
Keywords: csectype-uninitialized,
sec-high
Comment 11•11 years ago
|
||
I started looking at this a bit.
The image is truncated after the GIF_IMAGE_SEPARATOR. I suspect we are getting a little confused about whether we have a frame of the image or not.
Assignee: nobody → jmuizelaar
Comment 12•11 years ago
|
||
(In reply to Jeff Muizelaar [:jrmuizel] from comment #11)
> I started looking at this a bit.
>
> The image is truncated after the GIF_IMAGE_SEPARATOR. I suspect we are
> getting a little confused about whether we have a frame of the image or not.
It looks like the problem shown by valgrind is that VolatileBufferFallback::Init does not initialize it's buffer to 0
Assignee: jmuizelaar → mwu
Assignee | ||
Comment 13•11 years ago
|
||
Not initializing the buffer to zero is fine - malloc does the same thing, but imgFrame isn't clearing the buffer when it needs to. This code used to have gfxImageSurface allocate the buffer, which would memset the data to zero. I missed this when switching the code to managing its own buffers.
Buffers do not need to be cleared when not heap allocated, since the memory comes directly from the kernel which zeros it for us.
Assignee | ||
Comment 14•11 years ago
|
||
Comment on attachment 8471069 [details] [diff] [review]
Clear heap allocated buffers
Review of attachment 8471069 [details] [diff] [review]:
-----------------------------------------------------------------
I was looking into making the VolatileBuffer api provide a InitZeroed function, but that makes the fix a bit more complicated. I'll look into doing that after fixing this since I don't think exposing OnHeap() is good.
Attachment #8471069 -
Flags: review?(seth)
Attachment #8471069 -
Flags: review?(n.nethercote)
Comment 15•11 years ago
|
||
(In reply to Michael Wu [:mwu] from comment #14)
> Comment on attachment 8471069 [details] [diff] [review]
> Clear heap allocated buffers
Is it possible for such buffers to be allocated on the stack instead?
If so, won't we need to clear those too?
Assignee | ||
Comment 16•11 years ago
|
||
(In reply to Julian Seward [:jseward] from comment #15)
> Is it possible for such buffers to be allocated on the stack instead?
> If so, won't we need to clear those too?
VolatileBuffers are always allocated using system calls or a heap allocator.
![]() |
||
Comment 17•11 years ago
|
||
Comment on attachment 8471069 [details] [diff] [review]
Clear heap allocated buffers
Review of attachment 8471069 [details] [diff] [review]:
-----------------------------------------------------------------
r=me for fixing the problem, but yes, a nicer follow-up is needed.
::: image/src/imgFrame.cpp
@@ +185,5 @@
> + if (mVBuf->OnHeap()) {
> + int32_t stride = VolatileSurfaceStride(mSize, mFormat);
> + VolatileBufferPtr<uint8_t> ptr(mVBuf);
> + memset(ptr, 0, stride * mSize.height);
> + }
Move this new code before the CreateLockedSurface() call? Seems better to allocate the buffer and then immediately zero it.
Attachment #8471069 -
Flags: review?(n.nethercote) → review+
Updated•11 years ago
|
Flags: needinfo?(milan)
Comment 18•11 years ago
|
||
Comment on attachment 8471069 [details] [diff] [review]
Clear heap allocated buffers
Review of attachment 8471069 [details] [diff] [review]:
-----------------------------------------------------------------
I agree with njn's comment, but otherwise looks good to me.
I am pretty sure I just hit this in another patch, bug 1054079, which makes us rasterize SVG images into imgFrame's instead of using SourceSurface's directly. The oranges are the result of uninitialized memory causing random noise in parts of the image where the SVG was totally transparent (and thus didn't draw anything).
Attachment #8471069 -
Flags: review?(seth) → review+
Assignee | ||
Comment 19•11 years ago
|
||
Is there any specific way I should land this, given that it's a security bug?
Comment 20•11 years ago
|
||
(In reply to Michael Wu [:mwu] from comment #19)
> Is there any specific way I should land this, given that it's a security bug?
Yes, follow the directions outlined at https://wiki.mozilla.org/Security/Bug_Approval_Process
Assignee | ||
Comment 21•11 years ago
|
||
Review comment addressed.
Attachment #8471069 -
Attachment is obsolete: true
Assignee | ||
Comment 22•11 years ago
|
||
Assignee | ||
Comment 23•11 years ago
|
||
Comment on attachment 8474064 [details] [diff] [review]
Clear heap allocated buffers, v2
[Security approval request comment]
How easily could an exploit be constructed based on the patch?
It's relatively easy to get access to the uninitialized data through canvas, and canvas is the most obvious way to grab raw image data. The only non-obvious part is using a corrupt image to prevent the buffer from being overridden with decoded image data.
Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?
The check-in comment could be rephrased a bit if needed.
Which older supported branches are affected by this flaw?
ESR31, B2G30
If not all supported branches, which bug introduced the flaw?
Bug 962670
Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be?
A different patch is required for Gecko 31/30. It's attached in the bug, and should work as long as it compiles.
How likely is this patch to cause regressions; how much testing does it need?
Regressions unlikely, though it may affect performance in certain cases.
Attachment #8474064 -
Flags: sec-approval?
Updated•11 years ago
|
status-firefox31:
--- → wontfix
status-firefox32:
--- → affected
status-firefox33:
--- → affected
status-firefox34:
--- → affected
status-firefox-esr24:
--- → unaffected
status-firefox-esr31:
--- → affected
Comment 24•11 years ago
|
||
Comment on attachment 8474064 [details] [diff] [review]
Clear heap allocated buffers, v2
sec-approval+ for trunk.
Please nominate this for Aurora, Beta, and ESR31.
Attachment #8474064 -
Flags: sec-approval? → sec-approval+
Assignee | ||
Comment 25•11 years ago
|
||
[Blocking Requested - why for this release]: Security bug.
blocking-b2g: --- → 2.0?
Assignee | ||
Comment 26•11 years ago
|
||
Comment on attachment 8474064 [details] [diff] [review]
Clear heap allocated buffers, v2
[Approval Request Comment]
This is a sec-high bug. See comment 23 for details.
Attachment #8474064 -
Flags: approval-mozilla-beta?
Attachment #8474064 -
Flags: approval-mozilla-aurora?
Assignee | ||
Comment 27•11 years ago
|
||
Clearing blocking request - going to use the approval flag on the patch instead.
blocking-b2g: 2.0? → ---
Assignee | ||
Comment 28•11 years ago
|
||
Comment on attachment 8474724 [details] [diff] [review]
Clear heap allocated buffers (For esr31/b2g30)
Apparently imgFrame.cpp diverged a bit between 30 and 31, so I'm going to have a separate patch for b2g30.
Attachment #8474724 -
Attachment description: Clear heap allocated buffers (For esr31/b2g30) → Clear heap allocated buffers (For esr31)
Assignee | ||
Comment 29•11 years ago
|
||
Comment on attachment 8474724 [details] [diff] [review]
Clear heap allocated buffers (For esr31/b2g30)
Nevermind - I mixed up the release branches. This does apply to b2g30.
Attachment #8474724 -
Attachment description: Clear heap allocated buffers (For esr31) → Clear heap allocated buffers (For esr31/b2g30)
Assignee | ||
Comment 30•11 years ago
|
||
Comment on attachment 8474724 [details] [diff] [review]
Clear heap allocated buffers (For esr31/b2g30)
[Approval Request Comment]
If this is not a sec:{high,crit} bug, please state case for ESR consideration:
This is a sec-high bug. See comment 23 for details.
Attachment #8474724 -
Flags: approval-mozilla-esr31?
Attachment #8474724 -
Flags: approval-mozilla-b2g30?
Comment 31•11 years ago
|
||
We're late in beta. If this should land concurrently on all branches, we can try to land today in time for beta8. If not, this should get in beta9, which goes to build on Thu.
Updated•11 years ago
|
Assignee | ||
Comment 32•11 years ago
|
||
Landing in beta 9 sounds good to me.
Comment 33•11 years ago
|
||
Does this need to land concurrently or can this land on m-c Tue and bake for a day or two before uplift?
Comment 34•11 years ago
|
||
It should be fine to land on trunk first. That's what we usually do.
Assignee | ||
Comment 35•11 years ago
|
||
Comment 36•11 years ago
|
||
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
Updated•11 years ago
|
Attachment #8474724 -
Flags: approval-mozilla-esr31? → approval-mozilla-esr31+
Updated•11 years ago
|
Attachment #8474064 -
Flags: approval-mozilla-beta?
Attachment #8474064 -
Flags: approval-mozilla-beta+
Attachment #8474064 -
Flags: approval-mozilla-aurora?
Attachment #8474064 -
Flags: approval-mozilla-aurora+
Updated•11 years ago
|
Attachment #8474724 -
Flags: approval-mozilla-b2g30?
Comment 37•11 years ago
|
||
https://hg.mozilla.org/releases/mozilla-aurora/rev/ab8b62a75e77
https://hg.mozilla.org/releases/mozilla-beta/rev/bff13e7445c5
https://hg.mozilla.org/releases/mozilla-esr31/rev/2437605df381
https://hg.mozilla.org/releases/mozilla-b2g30_v1_4/rev/64ed70a322c9
status-b2g-v1.3:
--- → unaffected
status-b2g-v1.3T:
--- → unaffected
status-b2g-v1.4:
--- → fixed
status-b2g-v2.0:
--- → affected
status-b2g-v2.1:
--- → fixed
Comment 38•11 years ago
|
||
Assignee | ||
Comment 39•11 years ago
|
||
This actually affect 1.3t, since volatile buffer images were backported there.
Assignee | ||
Comment 40•11 years ago
|
||
Comment on attachment 8474724 [details] [diff] [review]
Clear heap allocated buffers (For esr31/b2g30)
[Approval Request Comment]
This is a sec-high bug that also affects 1.3t (but *not* 1.3). See comment 23 for details.
Attachment #8474724 -
Flags: approval-mozilla-b2g28?
Updated•11 years ago
|
Flags: sec-bounty? → sec-bounty+
Comment 42•11 years ago
|
||
On builds from around the time this was reported, I get between 2-4 variants. However, using builds post-fix from 2014-08-20, I consistently get 1 variant.
While it's an improvement, does this mean we've successfully mitigated this? FWIW the image itself does not appear visually different to my eye.
Flags: needinfo?(mwu)
Assignee | ||
Comment 43•11 years ago
|
||
I'm pretty sure this is fixed for the test case posted here if you're only getting one variant. If you want to be more thorough, test on Windows(8.1 and pre-8.1)/Linux/OSX/Android, because there are slightly different volatile buffer code paths in each one. Getting one variant consistently is the important part.
Flags: needinfo?(mwu)
Updated•11 years ago
|
Whiteboard: [reporter-external] → [reporter-external][adv-main32+][adv-esr31.1+]
Comment 44•11 years ago
|
||
As mentioned in comment #43, only a single variant should always appear when loading the POC from comment #0, went through the following verification:
Reproduced the original issue using the following build:
- http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2014-07-29-03-02-02-mozilla-central/
- Received anywhere between 2-6 variants until it finally reach 1 varriant
- Uninstalled/Installed several times and kept receiving different variaent sizes
Win 8.1 x64 (VM): PASSED
Win 7 Pro SP2 x64 (VM): PASSED
Ubuntu 13.10 x64 (VM): PASSED
OSX 10.9.4 x64: PASSED
For each of the above OS's, I went through the following test cases:
fx 34.0a1:
- http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2014-08-26-03-02-03-mozilla-central/
- loaded the poc 20x (uninstalling/re-installing fx once I reached 10x) and always received 1 variant
fx 33.0a2:
- http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2014-08-26-00-40-03-mozilla-aurora/
- loaded the poc 20x (uninstalling/re-installing fx once I reached 10x) and always received 1 variant
fx 32:
- http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest-beta/
- loaded the poc 20x (uninstalling/re-installing fx once I reached 10x) and always received 1 variant
fx 31.0esrpre:
- http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2014-08-26-00-05-03-mozilla-esr31/
- loaded the poc 20x (uninstalling/re-installing fx once I reached 10x) and always received 1 variant
Status: RESOLVED → VERIFIED
Flags: qe-verify+
Updated•11 years ago
|
Alias: CVE-2014-1564
Updated•11 years ago
|
tracking-firefox-esr31:
--- → 32+
Updated•10 years ago
|
See Also: → CVE-2014-1580
Assignee | ||
Comment 45•10 years ago
|
||
Comment on attachment 8474724 [details] [diff] [review]
Clear heap allocated buffers (For esr31/b2g30)
Clearing request since it seems too late for b2g28.
Attachment #8474724 -
Flags: approval-mozilla-b2g28?
Updated•9 years ago
|
Group: core-security → core-security-release
Updated•9 years ago
|
Group: core-security-release
Updated•9 months ago
|
Keywords: reporter-external
You need to log in
before you can comment on or make changes to this bug.
Description
•