cloudwu / pbc

A protocol buffers library for C
MIT License
1.62k stars 567 forks source link

Buffer overflows detected by ASAN in program pbc #124

Open fCorleone opened 6 years ago

fCorleone commented 6 years ago

1: A global buffer overflow has been detected

When I was running program pbc, a global buffer overflow has been detected. The input file has been put at :https://github.com/fCorleone/fuzz_programs/blob/master/pbc/testcase1 Details provided by ASAN:

=================================================================
==23750==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000000431c61 at pc 0x7f129017220b bp 0x7ffd4f964360 sp 0x7ffd4f963b08
READ of size 1 at 0x000000431c61 thread T0
    #0 0x7f129017220a in __interceptor_strlen (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x7020a)
    #1 0x4093bf in calc_hash src/map.c:35
    #2 0x40d9f7 in _pbcM_sp_query src/map.c:384
    #3 0x417c5e in set_field_one src/bootstrap.c:170
    #4 0x418386 in _pbcB_register_fields src/bootstrap.c:198
    #5 0x404e15 in _register src/register.c:246
    #6 0x40553b in _register_no_dependency src/register.c:296
    #7 0x405b47 in pbc_register src/register.c:329
    #8 0x401d5b in test_des ../test/pbc.c:37
    #9 0x401f25 in main ../test/pbc.c:49
    #10 0x7f128fd5882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #11 0x401588 in _start (/home/mfc_fuzz/pbc/build/pbc+0x401588)

0x000000431c61 is located 0 bytes to the right of global variable '*.LC5' defined in 'src/bootstrap.c' (0x431c60) of size 1
  '*.LC5' is ascii string ''
SUMMARY: AddressSanitizer: global-buffer-overflow ??:0 __interceptor_strlen
Shadow bytes around the buggy address:
  0x00008007e330: f9 f9 f9 f9 00 00 00 00 02 f9 f9 f9 f9 f9 f9 f9
  0x00008007e340: 00 00 00 00 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 03
  0x00008007e350: f9 f9 f9 f9 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9
  0x00008007e360: 00 00 00 00 00 00 00 04 f9 f9 f9 f9 00 00 00 00
  0x00008007e370: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x00008007e380: 00 00 00 00 00 00 00 00 00 00 00 00[01]f9 f9 f9
  0x00008007e390: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007e3a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007e3b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007e3c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007e3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
==23750==ABORTING
fCorleone commented 6 years ago

Another buffer overflow has been detected, it's a heap buffer overflow. I was running program pbc as: ./pbc testcase2 which testcase2 is put at: https://github.com/fCorleone/fuzz_programs/blob/master/pbc/testcase2 and the heap buffer overflow has occurred:

=================================================================
==20500==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000eeb0 at pc 0x00000040a96e bp 0x7ffe53104be0 sp 0x7ffe53104bd0
READ of size 4 at 0x60200000eeb0 thread T0
    #0 0x40a96d in _pbcM_ip_new src/map.c:143
    #1 0x406c77 in _pbcP_push_enum src/proto.c:83
    #2 0x402bf2 in _register_enum src/register.c:52
    #3 0x4048e2 in _register_message src/register.c:211
    #4 0x404db5 in _register src/register.c:241
    #5 0x40553b in _register_no_dependency src/register.c:296
    #6 0x405b47 in pbc_register src/register.c:329
    #7 0x401d5b in test_des ../test/pbc.c:37
    #8 0x401f25 in main ../test/pbc.c:49
    #9 0x7fe25d95082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #10 0x401588 in _start (/home/mfc_fuzz/pbc/build/pbc+0x401588)

0x60200000eeb1 is located 0 bytes to the right of 1-byte region [0x60200000eeb0,0x60200000eeb1)
allocated by thread T0 here:
    #0 0x7fe25dd92602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x40ef56 in _pbcM_malloc src/alloc.c:8
    #2 0x402909 in _register_enum src/register.c:39
    #3 0x4048e2 in _register_message src/register.c:211
    #4 0x404db5 in _register src/register.c:241
    #5 0x40553b in _register_no_dependency src/register.c:296
    #6 0x405b47 in pbc_register src/register.c:329
    #7 0x401d5b in test_des ../test/pbc.c:37
    #8 0x401f25 in main ../test/pbc.c:49
    #9 0x7fe25d95082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: heap-buffer-overflow src/map.c:143 _pbcM_ip_new
Shadow bytes around the buggy address:
  0x0c047fff9d80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9d90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff9dd0: fa fa fa fa fa fa[01]fa fa fa 00 00 fa fa fd fd
  0x0c047fff9de0: fa fa 00 00 fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c047fff9df0: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa fd fd
  0x0c047fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e20: 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
==20500==ABORTING