ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
17 stars 2 forks source link

out of bounds heap read in function REtest #36

Closed hannob closed 7 years ago

hannob commented 8 years ago

This input script https://crashes.fuzzing-project.org/mawk-oob-heap-read-REtest.awk will cause an out of bounds heap read access when passed to "mawk -f".

To see this one needs to compile mawk with address sanitizer(-fsanitize=address in CFLAGS) or use valgrind. This bug was found with the help of american fuzzy lop.

Address Sanitizer stack trace:

==6519==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000eff8 at pc 0x00000053e36f bp 0x7ffd424896b0 sp 0x7ffd424896a8
READ of size 4 at 0x60300000eff8 thread T0
    #0 0x53e36e in REtest /f/mawk/mawk-1.3.4-20150503/./rexp2.c:223:18
    #1 0x500a01 in execute /f/mawk/mawk-1.3.4-20150503/execute.c:1084:10
    #2 0x4f9d96 in main /f/mawk/mawk-1.3.4-20150503/main.c:99:5
    #3 0x7fe03f17bf9f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.20-r2/work/glibc-2.20/csu/libc-start.c:289
    #4 0x4187f5 in _start (/mnt/ram/gawk/mawk+0x4187f5)

0x60300000eff8 is located 0 bytes to the right of 24-byte region [0x60300000efe0,0x60300000eff8)
allocated by thread T0 here:
    #0 0x4b3be8 in __interceptor_malloc (/mnt/ram/gawk/mawk+0x4b3be8)
    #1 0x535eae in RE_malloc /f/mawk/mawk-1.3.4-20150503/./rexp1.c:243:9
    #2 0x535eae in REcompile /f/mawk/mawk-1.3.4-20150503/./rexp.c:139
    #3 0x532259 in re_compile /f/mawk/mawk-1.3.4-20150503/re_cmpl.c:99:28
    #4 0x4f9d96 in main /f/mawk/mawk-1.3.4-20150503/main.c:99:5

SUMMARY: AddressSanitizer: heap-buffer-overflow /f/mawk/mawk-1.3.4-20150503/./rexp2.c:223:18 in REtest
Shadow bytes around the buggy address:
  0x0c067fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9dd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff9df0: fa fa fa fa fa fa fa fa fa fa fa fa 00 00 00[fa]
  0x0c067fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9e40: 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
  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
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==6519==ABORTING
ThomasDickey commented 8 years ago

I have a fix for this :-)

ThomasDickey commented 7 years ago

http://invisible-island.net/mawk/CHANGES.html#t20160905