Bug 13520 - MIT-SHM Extension Integer Overflow Vulnerability
Summary: MIT-SHM Extension Integer Overflow Vulnerability
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: Security (show other bugs)
Version: 7.3 (2007.09)
Hardware: Other All
: medium normal
Assignee: X.Org Security
QA Contact: X.Org Security
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-04 12:56 UTC by Matthieu Herrb
Modified: 2008-01-21 15:04 UTC (History)
5 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Draft advisory (4.66 KB, text/plain)
2007-12-04 12:57 UTC, Matthieu Herrb
no flags Details
Proposed fix (2.03 KB, patch)
2007-12-11 11:51 UTC, Adam Jackson
no flags Details | Splinter Review
proposed fix - for both functions.. (2.98 KB, patch)
2007-12-13 19:13 UTC, Dave Airlie
no flags Details | Splinter Review
Testcase (2.09 KB, text/plain)
2007-12-17 18:59 UTC, Alan Coopersmith
no flags Details
mitshm-testcase.c (2.24 KB, text/x-csrc)
2008-01-18 12:23 UTC, Adam Jackson
no flags Details

Description Matthieu Herrb 2007-12-04 12:56:48 UTC
iDefense has sent us the attached draft advisory
Comment 1 Matthieu Herrb 2007-12-04 12:57:24 UTC
Created attachment 12941 [details]
Draft advisory
Comment 2 Adam Jackson 2007-12-11 11:51:34 UTC
Created attachment 13034 [details] [review]
Proposed fix
Comment 3 Dave Airlie 2007-12-13 18:11:06 UTC
okay please drop the first hunk of ajax's patch, its buggy as size is replaced in the derference..

further down 
ProcPanoramiXShmCreatePixmap
contains the same code does this also require a fix?
Comment 4 Dave Airlie 2007-12-13 19:13:54 UTC
Created attachment 13099 [details] [review]
proposed fix - for both functions..

Okay this fixes both functions non-panoramix and panoramix..
Comment 5 Alan Coopersmith 2007-12-17 18:59:38 UTC
Created attachment 13178 [details]
Testcase

This is a test for the simplest case (width & height of 32768, depth of 32 bit =
32768 * 32768 * 4 = INT_MAX+1), which is allowed to pass before the fix, and 
now caught by the simple width > 32767 & depth > 32767 checks - better tests for 
the cases in the more complex code paths would be good to have too.
Comment 6 Matthieu Herrb 2008-01-17 08:25:49 UTC
This is public now
Comment 7 Matthieu Herrb 2008-01-17 08:27:34 UTC
Patch has beem committed: 6de61f82728df22ea01f9659df6581b87f33f11d
Comment 8 Adam Jackson 2008-01-18 12:23:20 UTC
Created attachment 13779 [details]
mitshm-testcase.c

Enhanced testcase that also verifies that 1bpp pixmaps continue to work, ie, that:

http://cgit.freedesktop.org/xorg/xserver/commit/?id=e9fa7c1c88a8130a48f772c92b186b8b777986b5

does the right thing.
Comment 9 Matthias Hopf 2008-01-21 03:56:12 UTC
+    size = PixmapBytePad(width, depth) * height;
+    if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
                                                 ^^^
IMHO this should read >=
Currently this *doesn't* test 8bpp pixmaps.

+        if (size < width * height)
+            return BadAlloc;

I *really* don't understand this test. When can this ever hit true (with depth >=8, that is)? size, width, and height are unsigned 32bit, and 32767*32767 perfectly fits 32bit.

+        /* thankfully, offset is unsigned */
+        if (stuff->offset + size < size)
+            return BadAlloc;

This overwrap test (which I assume was the original fix) can (and should) always be done, independently of the machine size and pixel depth.

Agreed?
Comment 10 Adam Jackson 2008-01-21 06:45:08 UTC
(In reply to comment #9)
> +    size = PixmapBytePad(width, depth) * height;
> +    if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
>                                                  ^^^
> IMHO this should read >=
> Currently this *doesn't* test 8bpp pixmaps.

Sure, but everybody stores depth 8 pixmaps as 8bpp, and as you note below, 32767*32767 < 2^32-1.  It'd be harmless to test 8bpp too, I suppose.

> +        if (size < width * height)
> +            return BadAlloc;
> 
> I *really* don't understand this test. When can this ever hit true (with depth
> >=8, that is)? size, width, and height are unsigned 32bit, and 32767*32767
> perfectly fits 32bit.

Yeah, for <=32bpp it's fine.  I suppose it's just paranoia in case anyone starts doing >32bpp, but that day is soon.

> +        /* thankfully, offset is unsigned */
> +        if (stuff->offset + size < size)
> +            return BadAlloc;
> 
> This overwrap test (which I assume was the original fix) can (and should)
> always be done, independently of the machine size and pixel depth.
> 
> Agreed?

Agreed.
Comment 11 Matthias Hopf 2008-01-21 07:14:13 UTC
> > +        if (size < width * height)
> > +            return BadAlloc;
> > 
> > I *really* don't understand this test. When can this ever hit true (with depth
> > >=8, that is)? size, width, and height are unsigned 32bit, and 32767*32767
> > perfectly fits 32bit.
> 
> Yeah, for <=32bpp it's fine.  I suppose it's just paranoia in case anyone
> starts doing >32bpp, but that day is soon.

Hm. Yes, sounds true. But wouldn't be the proper fix to just change size to CARD64? AFAICS the structure is used in this file only...

Pushed the offset wrapping in be6c17fcf9e.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.