Skip to content

Heap buffer overflow occurs in particular inputs #2

@ppodds

Description

@ppodds

In some inputs, I could find heap BOF in this program.

For testing purposes, we can generate inputs like this:

echo -ne "\xf6" > input1
echo -ne "\xe2" > input2
echo -ne "\xff" > input3

Generate binary that can detect BOF:

gcc libx.c x.c -fsanitize=address -o x

Execute it with the above input:

./x < input1

Output:

  Input size: 1 bytes
Compressing...
=================================================================
==3603184==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000038 at pc 0x555590dbc6f8 bp 0x7fff24db8a00 sp 0x7fff24db89f0
WRITE of size 4 at 0x602000000038 thread T0
    #0 0x555590dbc6f7 in flush_buffer (/home/ppodds/x-compressor/x+0x26f7)
    #1 0x555590dbd048 in finalize (/home/ppodds/x-compressor/x+0x3048)
    #2 0x555590dbdf5a in x_compress (/home/ppodds/x-compressor/x+0x3f5a)
    #3 0x555590dbe9c8 in main (/home/ppodds/x-compressor/x+0x49c8)
    #4 0x7fdf7da37d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #5 0x7fdf7da37e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #6 0x555590dbc384 in _start (/home/ppodds/x-compressor/x+0x2384)

0x602000000038 is located 0 bytes to the right of 8-byte region [0x602000000030,0x602000000038)
allocated by thread T0 here:
    #0 0x7fdf7dcea867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x555590dbe93a in main (/home/ppodds/x-compressor/x+0x493a)
    #2 0x7fdf7da37d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/ppodds/x-compressor/x+0x26f7) in flush_buffer
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 01 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
  Shadow gap:              cc
==3603184==ABORTING

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions