libXfont contains a compress / LZW decompressor implementation. This implementation does not correctly handle compressed streams that contain code words that were not yet added to the decompression table. LZW decompression has a special case (a KwKwK string) when code word matches the first free entry in the decompression table. The implementation used in libXfont allow code words not only matching, but also exceeding the first free entry. Relevant code appears in BufCompressedFill() in src/fontfile/decompress.c: /* * Special case for KwKwK string. */ if ( code >= file->free_ent ) { *stackp++ = finchar; code = oldcode; } http://cgit.freedesktop.org/xorg/lib/libXfont/tree/src/fontfile/decompress.c?id=f29f1d68d7eca96e45ba3758686be07993d82e03#n249 This allows creating a loop in the decompression table, which leads to an "infinite" loop: /* * Generate output characters in reverse order */ while ( code >= 256 ) { *stackp++ = file->tab_suffix[code]; code = file->tab_prefix[code]; } http://cgit.freedesktop.org/xorg/lib/libXfont/tree/src/fontfile/decompress.c?id=f29f1d68d7eca96e45ba3758686be07993d82e03#n257 and heap-based buffer overflow (CompressedFile's de_stack[]): char_type de_stack[STACK_SIZE]; char_type *tab_suffix; unsigned short *tab_prefix; } CompressedFile; http://cgit.freedesktop.org/xorg/lib/libXfont/tree/src/fontfile/decompress.c?id=f29f1d68d7eca96e45ba3758686be07993d82e03#n121 Once stackp is incremented to point to after de_stack[] buffer end, tab_suffix and tab_prefix pointers are corrupted, which may lead to arbitrary memory corruption. libXfont is used by X server and can parse arbitrary user-supplied font file. Successful exploitation may possibly lead to a local privilege escalation.
(In reply to comment #0) > libXfont contains a compress / LZW decompressor implementation. LZW decompression implementations in libXfont, ncompress and gzip all seem to be based on the same implementation. ncompress and gzip already contain a check for code > free_ent and abort decompression in such case. Other code bases derived from the same source (such as GIF parsers in mozilla/libpr0n and gd) check for stack[] overflow in the while loop.
Created attachment 516719 [details] My proposed patch - variant 1 Checks code values, similar to ncompress/gzip.
Created attachment 516721 [details] My proposed patch - variant 2 de_stack overflow check in the while loop, similar to what OpenBSD compress does.
Created attachment 516759 [details] Updated proposed patch
Making this public.
libXfont fixed upstream in version 1.4.4: http://lists.freedesktop.org/archives/xorg-announce/2011-August/001721.html http://lists.freedesktop.org/archives/xorg-announce/2011-August/001722.html http://cgit.freedesktop.org/xorg/lib/libXfont/commit/?id=d11ee5886e9d9ec610051a206b135a4cdc1e09a0
Created libXfont tracking bugs for this issue Affects: fedora-all [bug 729870]
This issue has been addressed in following products: Red Hat Enterprise Linux 5 Red Hat Enterprise Linux 6 Via RHSA-2011:1154 https://rhn.redhat.com/errata/RHSA-2011-1154.html
This issue has been addressed in following products: Red Hat Enterprise Linux 4 Via RHSA-2011:1155 https://rhn.redhat.com/errata/RHSA-2011-1155.html
An improved fix was committed to upstream git repository. It improves input checks to avoid decompression table loops and increases decompression stack size, instead of performing stack boundary checks: http://cgit.freedesktop.org/xorg/lib/libXfont/commit/src/fontfile/decompress.c?id=bd48ad11fd11412c62c3ac8ed5d52c4f10a985aa
This issue has been addressed in following products: Red Hat Enterprise Linux 5.6.Z - Server Only Via RHSA-2011:1834 https://rhn.redhat.com/errata/RHSA-2011-1834.html