Yeraze / ytnef

Yeraze's TNEF Stream Reader - for winmail.dat files
GNU General Public License v2.0
32 stars 22 forks source link

heap-based-buffer overflow in SwapWord (ytnef.c) #39

Closed asarubbo closed 6 years ago

asarubbo commented 7 years ago

On 1.9.2:

# ytnefprint $FILE
==22220==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000038 at pc 0x7ff75139d8eb bp 0x7ffeed684ad0 sp 0x7ffeed684ac8
READ of size 1 at 0x602000000038 thread T0
    #0 0x7ff75139d8ea in SwapWord /tmp/ytnef-1.9.2/lib/ytnef.c:153:28
    #1 0x7ff75139d8ea in TNEFDateHandler /tmp/ytnef-1.9.2/lib/ytnef.c:682
    #2 0x7ff7513b4b47 in TNEFParse /tmp/ytnef-1.9.2/lib/ytnef.c:1184:15
    #3 0x7ff7513b39d3 in TNEFParseFile /tmp/ytnef-1.9.2/lib/ytnef.c:1042:10
    #4 0x508814 in main /tmp/ytnef-1.9.2/ytnefprint/main.c:80:9
    #5 0x7ff7504c978f in __libc_start_main /tmp/portage/sys-libs/glibc-2.23-r3/work/glibc-2.23/csu/../csu/libc-start.c:289
    #6 0x419c38 in _start (/usr/bin/ytnefprint+0x419c38)

0x602000000038 is located 0 bytes to the right of 8-byte region [0x602000000030,0x602000000038)
allocated by thread T0 here:
    #0 0x4cf7e0 in calloc /tmp/portage/sys-libs/compiler-rt-sanitizers-4.0.0/work/compiler-rt-4.0.0.src/lib/asan/asan_malloc_linux.cc:74
    #1 0x7ff7513b472a in TNEFParse /tmp/ytnef-1.9.2/lib/ytnef.c:1154:12
    #2 0x7ff7513b39d3 in TNEFParseFile /tmp/ytnef-1.9.2/lib/ytnef.c:1042:10
    #3 0x508814 in main /tmp/ytnef-1.9.2/ytnefprint/main.c:80:9
    #4 0x7ff7504c978f in __libc_start_main /tmp/portage/sys-libs/glibc-2.23-r3/work/glibc-2.23/csu/../csu/libc-start.c:289

SUMMARY: AddressSanitizer: heap-buffer-overflow /tmp/ytnef-1.9.2/lib/ytnef.c:153:28 in SwapWord
Shadow bytes around the buggy address:
  0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c047fff8000: fa fa fd fa fa fa 00[fa]fa fa fa fa fa fa fa fa
  0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
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
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  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
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==22220==ABORTING

Testcase: https://github.com/asarubbo/poc/blob/master/00243-ytnef-heapoverflow-SwapWord

carnil commented 7 years ago

This is CVE-2017-9471

ohwgiles commented 6 years ago

Solved in PR #56

Yeraze commented 6 years ago

Released in https://github.com/Yeraze/ytnef/releases/tag/v1.9.3