Bug 94292 - Buffer overflow in XSecurityGenerateAuthorization
Summary: Buffer overflow in XSecurityGenerateAuthorization
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: Security (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: X.Org Security
QA Contact: X.Org Security
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-25 17:30 UTC by Rob
Modified: 2016-03-04 02:29 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Patch: Allocate enough space in values buffer (737 bytes, patch)
2016-02-25 17:30 UTC, Rob
no flags Details | Splinter Review

Description Rob 2016-02-25 17:30:17 UTC
Created attachment 121965 [details] [review]
Patch: Allocate enough space in values buffer

There is a stack buffer overflow vulnerability in XSecurityGenerateAuthorization.

This vulnerability can easily be demonstrated as follows:

1. Create an ASAN build of libXext
   cd /tmp
   git clone git://anongit.freedesktop.org/xorg/lib/libXext
   cd libXext
   ./autogen.sh
   CFLAGS=-fsanitize=address LDFLAGS=-fsanitize=address ./configure
   make

2. Slightly modify xauth to generate a bad function call.
   cd /tmp
   git clone git://anongit.freedesktop.org/xorg/lib/xauth
   cd xauth
   ./autogen.sh
   sed 's/unsigned long attrmask = 0/unsigned long attrmask = XSecurityEventMask/' -i process.c
   make

3. Run the modified xauth program:
   $ xvfb-run -n 77 sh
   $$ touch /tmp/authfile
   $$ LD_LIBRARY_PATH=/tmp/libXext/src/.libs/ ./xauth -f /tmp/authfile generate $DISPLAY . untrusted timeout 1 group 1 data 12

Result:
=================================================================
==22792==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffde8d8d148 at pc 0x7feb14cd70c2 bp 0x7ffde8d8d0b0 sp 0x7ffde8d8d0a0
WRITE of size 8 at 0x7ffde8d8d148 thread T0
    #0 0x7feb14cd70c1 in XSecurityGenerateAuthorization (/tmp/libXext/src/.libs/libXext.so.6+0x160c1)
    #1 0x40d77f in do_generate (/tmp/xauth/xauth+0x40d77f)
    #2 0x40631f in dispatch_command (/tmp/xauth/xauth+0x40631f)
    #3 0x40763c in process_command (/tmp/xauth/xauth+0x40763c)
    #4 0x40e091 in main (/tmp/xauth/xauth+0x40e091)
    #5 0x7feb143fa70f in __libc_start_main (/usr/lib/libc.so.6+0x2070f)
    #6 0x402278 in _start (/tmp/xauth/xauth+0x402278)

Address 0x7ffde8d8d148 is located in stack of thread T0 at offset 56 in frame
    #0 0x7feb14cd6619 in XSecurityGenerateAuthorization (/tmp/libXext/src/.libs/libXext.so.6+0x15619)

  This frame has 2 object(s):
    [32, 56) 'values' <== Memory access at offset 56 overflows this variable
    [96, 128) 'rep'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow ??:0 XSecurityGenerateAuthorization
Shadow bytes around the buggy address:
  0x10003d1a99d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d1a99e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d1a99f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d1a9a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d1a9a10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10003d1a9a20: 00 00 f1 f1 f1 f1 00 00 00[f4]f2 f2 f2 f2 00 00
  0x10003d1a9a30: 00 00 f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00
  0x10003d1a9a40: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
  0x10003d1a9a50: 04 f4 f4 f4 f2 f2 f2 f2 04 f4 f4 f4 f2 f2 f2 f2
  0x10003d1a9a60: 00 f4 f4 f4 f2 f2 f2 f2 00 f4 f4 f4 f2 f2 f2 f2
  0x10003d1a9a70: 00 00 00 f4 f2 f2 f2 f2 00 00 00 00 f3 f3 f3 f3
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==22792==ABORTING
Comment 1 Alan Coopersmith 2016-03-04 02:27:50 UTC
Thanks - fix has been pushed to git master:
https://cgit.freedesktop.org/xorg/lib/libXext/commit/?id=0744837f525d8ba103e807af7c44ad2bf5cbd6ca
Comment 2 Alan Coopersmith 2016-03-04 02:29:11 UTC
Also, for the public record, from the X.Org Security list discussion:

The description and proposed patch seem correct, but I do not believe we need to
issue a security bulletin or request a CVE, as I don't see any existing calls to
this library from privileged code.

https://codesearch.debian.net/results/XSecurityGenerateAuthorization/page_0
only finds calls to it from xauth or xrx in the X code base.


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.