Bug 62677 (CVE-2004-0994) - VUL-0: CVE-2004-0994: xzgv: integer overflows that lead to buffer overflows
Summary: VUL-0: CVE-2004-0994: xzgv: integer overflows that lead to buffer overflows
Status: RESOLVED FIXED
Alias: CVE-2004-0994
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents (show other bugs)
Version: unspecified
Hardware: All Linux
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Thomas Biege
QA Contact: Security Team bot
URL:
Whiteboard: CVE-2004-0994: CVSS v2 Base Score: 10...
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-27 21:44 UTC by Thomas Biege
Modified: 2021-10-27 15:18 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
ximage_zgv.tar.gz (12.51 KB, application/x-tgz)
2004-10-27 21:45 UTC, Thomas Biege
Details
multiplication overflow check prototype (435 bytes, patch)
2004-10-29 19:49 UTC, Joerg Reuter
Details | Diff
Proposed fix for multiplication overflow (5.10 KB, patch)
2004-11-04 01:37 UTC, Joerg Reuter
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Biege 2004-10-27 21:44:08 UTC
Hi, 
here is a post for zgv from Bugtraq ML.
Comment 1 Thomas Biege 2004-10-27 21:44:08 UTC
<!-- SBZ_reproduce  -->
Von: 		infamous41md@hotpop.com 
An: 		bugtraq <bugtraq@securityfocus.com> 
Betreff: 	zgv image viewing heap overflows 
Datum: 		Mon, 25 Oct 2004 21:07:17 -0400	 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Subject: 
 
zgv multiple heap overflows 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Product: 
 
zgv is a picture viewer with a thumbnail-based file selector, for the Linux 
and 
FreeBSD console (it uses svgalib). It's pretty featureful, and is probably the 
best svgalib-based viewer. (It can also be built to use SDL if you prefer.) 
Lots 
of people have told me they like it, where "lots" = "oh, it must be at least 
two 
or three", and you can't ask for a more ringing endorsement than that. Well, 
you 
could, but I'm not sure you'd get it. :-) 
 
zgv supports most popular formats, and allows panning and fit-to-screen 
methods 
of viewing, slideshows, scaling, gamma adjustment, etc.  
 
http://www.svgalib.org/rus/zgv/ 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Vulnerable: 
 
I tested latest, zgv-5.5.orig. 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Summary: 
 
zgv uses malloc() frequently to allocate memory for storing image data.  When 
calculating how much to allocate, user supplied data from image headers is 
multiplied and/or added without any checks for arithmetic overflows.  We can 
overflow numerous calculations, and cause small buffers to be allocated.  Then 
we can overflow the buffer, and eventually execute code.  There are a total of 
11 overflows that are exploitable to execute arbitrary code. 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Details: 
 
01]readbmp.c:180:  if ((work_bmap = *bmap =  
                            calloc (w * (h + 2) * bytepp,1)) == NULL) 
 
02]readgif.c:498:  if((im->image=(byte *)malloc(width*height))==NULL) 
 
03]readgif.c:606:if((*theimageptr= 
                        (byte *)malloc(ginfo->width*ginfo->height))==NULL) 
 
04]readmrf.c:107:   (image=calloc(w64*h64*64*64,1))==NULL) 
 
05]readpcx.c:130:if((*bmap=malloc(w*(h+2)*bytepp))==NULL) 
 
06]readpng.c:225:theimage=(byte *)malloc(pixelsize*width*(height+2)); 
 
07]readpnm.c:147:if((*bmap=malloc(w*(h+2)*bytepp))==NULL) 
 
08]readprf.c:205:if((*bmap=work_bmap=malloc(width*(height+2)*planes))==NULL) 
 
09]readtiff.c:89:if((image=*bmap=work_bmap= 
                        malloc(numpix*sizeof(uint32)+width*3*2))==NULL) 
 
10]readxpm.c:183:if((colchars=malloc(ncols*sizeof(struct 
colchars_tag)))==NULL) 
 
11]readxpm.c:372:if((*bmap=malloc(w*(h+2)*bytepp))==NULL) 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Exploits: 
 
There is a C file for each hole above.  The exploit for the first xpm hole, 
#10, demonstrates code execution,  the rest just crash zgv.  The only one I 
couldn't get working is the second gif hole, #3 from above.  That is in the 
file ximage_other_gif.c.  However, all are suitable for code execution with 
some work.  I just didn't have the time. 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Note: 
 
There was also a hole in: 
 
01]readpcd.c:42:if((*bmap=malloc(w*(h+3-*output_type)*(*output_type)))==NULL) 
 
I couldn't find the PCD file format anywhere for free on the web, and didn't 
pursue this further.  I didn't see anything that would make it not exploitable 
though, so it looks valid to me. 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
Vendor: 
 
Was not contacted. 
 
++++++++++++++++++++++++++++++++++++++++++++ 
 
--  
-sean
Comment 2 Thomas Biege 2004-10-27 21:45:01 UTC
Created attachment 25476 [details]
ximage_zgv.tar.gz

do not trust this exploit!
Comment 3 Thomas Biege 2004-10-27 21:45:57 UTC
Looks like we do not ship this nice little tool anymore. 
Comment 4 Thomas Biege 2004-10-27 21:48:48 UTC
dead! 
Comment 5 Thomas Biege 2004-10-29 14:37:45 UTC
<!-- SBZ_reopen -->Reopened by thomas@suse.de at Fri Oct 29 08:37:45 2004
Comment 6 Thomas Biege 2004-10-29 14:37:45 UTC
These bugs seem to affect xzgv too. 
Comment 7 Joerg Reuter 2004-10-29 16:51:49 UTC
Ouch, I'll take a look...
Comment 8 Joerg Reuter 2004-10-29 16:52:34 UTC
(should have clicked "Accept bug" also...)
Comment 9 Joerg Reuter 2004-10-29 19:49:09 UTC
Created attachment 25619 [details]
multiplication overflow check prototype

Okay, same problems exists in xzgv, indeed.

Hmm, would a check like this work? Checking every write access to the buffer
would be a PITA (especially for the implementation of the other image
formats...), but I'd like to have someone more familiar with ANSI C types and
bit operators to check whether this actually works on all of our platforms and
equally important, will continue to work with later GCC versions...
Comment 10 Thomas Biege 2004-10-29 20:52:33 UTC
What does (size_t ~0) do? :) 
 
Assuming that all variables used are unsigned you can try the following check: 
#include <limits.h> 
... 
 
if(width > UINT_MAX / height) 
	EXIT 
if( (width * height) > UINT_MAX / 3) 
	EXIT 
 
malloc() 
 
 
 
 
Comment 11 Thomas Biege 2004-10-29 20:53:41 UTC
And yes. width and height should be > 0 :) 
Comment 12 Joerg Reuter 2004-10-29 22:48:56 UTC
(size_t) ~0 does a bitwise inversion of a '0' of type size_t -- at least I hope
so... Thinking about it, it should rather be ~((size_t) 0). Since size_t is
unsigned by definition, you'll get the largest number available for size_t, as
size_t isn't necessarily "unsigned int" (size_t is defined as the largest
unsigned integer type available on the platform, if I'm not mistaken) and I
haven't found any SIZE_T_MAX #define... Is there anything wrong with this?
Comment 13 Joerg Reuter 2004-11-04 01:37:07 UTC
Created attachment 25749 [details]
Proposed fix for multiplication overflow

Okay, I think this patch should fix it. Can someone take a close look please
whether I've missed something? Would be embarrassing if we would issue an
update that does not fix the vulnerability...
Comment 14 Thomas Biege 2004-11-05 03:26:32 UTC
 
looks good. thank you! :) 
Comment 15 Joerg Reuter 2004-11-10 01:58:39 UTC
Okay, submitted packages for 8.[12]-i386, 9.[012]-{i386,x86_64} and STABLE as
well as a patchinfo.
Comment 16 Thomas Biege 2004-11-15 16:56:39 UTC
<!-- SBZ_reopen -->Reopened by thomas@suse.de at Mon Nov 15 09:56:39 2004
Comment 17 Thomas Biege 2004-11-15 16:56:39 UTC
reopened for tracking by sec-team 
Comment 18 Marcus Meissner 2004-11-15 17:27:44 UTC
released updated packages on thursday...  
Comment 19 Ludwig Nussel 2004-12-14 18:52:43 UTC
CAN-2004-0994 
Comment 20 Thomas Biege 2009-10-13 19:55:20 UTC
CVE-2004-0994: CVSS v2 Base Score: 10.0 (AV:N/AC:L/Au:N/C:C/I:C/A:C)