Unix Technical Forum

Re: buffer overflow in libXfont

This is a discussion on Re: buffer overflow in libXfont within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Thorsten Glaser wrote: > Hello, > > I first detected this on MirOS but after a phone call with ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 08:44 AM
Matthieu Herrb
 
Posts: n/a
Default Re: buffer overflow in libXfont

Thorsten Glaser wrote:
> Hello,
>
> I first detected this on MirOS but after a phone call with a friend
> running OpenBSD on his laptop, he could verify this works for him too.
>
> Download http://switch.dl.sourceforge.net/sou...en-1.1.ttf.zip
> (a free "as in GNU" decorative font)
>
> For reference, here's the checksum:
> RMD160 (DarkGardenMK.ttf) = 8058fae7a1d284274bc0b3d0ddb0af879696d971
>
> Put that into a separate directory, for example like this:
>
> $ mkdir /tmp/x
> $ cd /tmp/x
> $ ftp http://switch.dl.sourceforge.net/sou...en-1.1.ttf.zip
> $ unzip -j darkgarden-1.1.ttf.zip darkgarden-1.1/DarkGardenMK.ttf
> $ mkfontscale
> $ mkfontdir
>
> After this, the command 'cat fonts.dir' should output the following:
> 1
> DarkGardenMK.ttf -misc-dark garden-medium-r-normal--0-0-0-0-p-0-iso10646-1
>
> $ xset +fp /tmp/x
> $ xset fp rehash
> $ xlsfonts | fgrep dark
>
> Check if it's there.
>
> $ xterm -fn '-misc-dark garden-medium-r-normal--0-0-0-0-p-0-iso10646-1
>
> Voil`, X just crashed. Find one of the following in /var/log/messages:
>
> Jul 1 21:18:26 odem X: stack overflow in function FreeTypeLoadXFont
> Jul 1 21:18:26 odem /bsd: signal 6 received by (XFree86:11539) UID(2999) EUID(2999), parent (xinit:28405) UID(2999) EUID(2999)
>
> Jul 2 00:48:08 hydrogenium X: stack overflow in function FreeTypeAddProp
>
> Sorry, the last line is cropped, thanks to a crashed X, unwilling
> mouse after restart, and IRC...
>
> Now, if you install the font via fontconfig, the command
> $ xterm -fa Dark\ Garden
> works, displays a nice xterm with a not so nice width and an
> interesting illegible font, but doesn't crash a thing. Thus,
> libfreetype is working fine, but libXfont isn't.
>
> The stuff is in XF4/xc/lib/font/FreeType/module/ (I haven't
> tested whether libXfont.so.*, built from xc/lib/font/FreeType,
> is affected too, because I don't know how to use xfs, and other
> than that, nothing appears to use it.) and I haven't got a
> clue what's going on. (Especially since in that ancient XF86
> code I'm using, the FreeTypeLoadXFont function doesn't have
> any char array, and no function beginning with FreeTypeAddProp
> exists.)
>
> On my box, this is true for freetype 2.1.8 and 2.2.1, with
> either mmap malloc or brk malloc; on 'hydrogenium', there's
> an OpenBSD/i386 3.9-current of two weeks or so ago running.
> That's a Thinkpad.
>
> Maybe there's indeed something exploitable for "the rest of
> the world" where propolice saved us again?
>
> bye,
> //mirabile


It appears that the Freetype interface code in libXfont fails to
nul-terminate strings when they get truncated in FTu2a() (and also in
FtGetEnglishName()). The attached patch fixes that.
The Dark Garden font still fails to load as a server-side font, but now
it properly returns an error to the client

Index: fttools.c
================================================== =================
RCS file: /cvs/OpenBSD/XF4/xc/lib/font/FreeType/fttools.c,v
retrieving revision 1.5
diff -u -r1.5 fttools.c
--- fttools.c 1 Jan 2006 15:32:11 -0000 1.5
+++ fttools.c 2 Jul 2006 16:53:17 -0000
@@ -77,7 +77,7 @@

n = 0;
for (i = 0; i < slen; i += 2) {
- if(n >= max)
+ if(n >= max - 1)
break;
if(HIBYTE(from+i, byte)!=0)
*to++='?';
@@ -143,9 +143,10 @@
/* Pretend that Apple Roman is ISO 8859-1. */
if(FTGetName(face, nid, TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN,
&name)) {
len = name.string_len;
- if(len > name_len)
- len = name_len;
+ if(len > name_len - 1)
+ len = name_len - 1;
memcpy(name_return, name.string, len);
+ name_return[len] = '\0'; /* ensure nul terminaison */
return len;
}

I'm reporting this back to X.Org.
--
Matthieu Herrb

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com