Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap out-of-bounds read in funcs.c:310 #2953

Closed
m4drat opened this issue Aug 22, 2022 · 2 comments · Fixed by #2977
Closed

Heap out-of-bounds read in funcs.c:310 #2953

m4drat opened this issue Aug 22, 2022 · 2 comments · Fixed by #2977
Milestone

Comments

@m4drat
Copy link

m4drat commented Aug 22, 2022

Hi! We've been fuzzing your project and found the following error in librz/magic/funcs.c:310

Work environment

OS: Ubuntu 20.04
File format: -
rizin version: 4b38597

Bug description

Heap out-of-bounds read of size 1 in librz/magic/funcs.c:310

Steps to reproduce

  1. Build docker container from https://github.com/ispras/oss-sydr-fuzz/tree/master/projects/rizin: sudo docker build -t oss-sydr-fuzz-rizin .

  2. Run docker container: sudo docker run --privileged --network host -v /etc/localtime:/etc/localtime:ro --rm -it -v $PWD:/fuzz oss-sydr-fuzz-rizin /bin/bash

  3. Execute rizin with crashing input (we sent all crashing inputs to you by email):
    /rizin-fuzzing/libfuzzer-asan/bin/rizin -qq crash-sydr_afl_s12-id_015412_time_0_execs_0_orig_id_004735_sync_afl_main-worker_src_005101_int_overflow_1_unsigned

  4. You will see the following output:

=================================================================
==2470365==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300025d15e at pc 0x00000065bda1 bp 0x7ffdcb3552d0 sp 0x7ffdcb3552c8
READ of size 1 at 0x60300025d15e thread T0
    #0 0x65bda0 in file_getbuffer /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/funcs.c:310:40
    #1 0xaf124f in get_filetype /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/p/bin_any.c:24:8
    #2 0xaf124f in info /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/p/bin_any.c:39:14
    #3 0xae7fd3 in rz_bin_object_set_items /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/bobj.c:488:22
    #4 0xae706b in rz_bin_object_new /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/bobj.c:319:2
    #5 0xad7d31 in rz_bin_file_new_from_buffer /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/bfile.c:150:19
    #6 0xadf3c7 in rz_bin_open_buf /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/bin.c:272:8
    #7 0xadec27 in rz_bin_open_io /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/bin/bin.c:330:18
    #8 0x1003353 in core_file_do_load_for_io_plugin /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/core/cfile.c:727:23
    #9 0x1003353 in rz_core_bin_load /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/core/cfile.c:974:4
    #10 0x5b9af8 in rz_main_rizin /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/main/rizin.c:1119:14
    #11 0x7efe88964082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
    #12 0x41da3d in _start (/home/madrat/Desktop/rizin-report/rz-installation-asan/bin/rizin+0x41da3d)

0x60300025d15e is located 0 bytes to the right of 30-byte region [0x60300025d140,0x60300025d15e)
allocated by thread T0 here:
    #0 0x498c9d in malloc (/home/madrat/Desktop/rizin-report/rz-installation-asan/bin/rizin+0x498c9d)
    #1 0x65a99d in file_vprintf /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/funcs.c:76:12
    #2 0x65a718 in file_printf /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/funcs.c:107:8
    #3 0x665857 in mprint /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/softmagic.c:421:8
    #4 0x65d71f in match /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/softmagic.c:247:37
    #5 0x65d71f in file_softmagic /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/softmagic.c:74:13

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/madrat/Desktop/rizin-report/rizin/build-asan/../librz/magic/funcs.c:310:40 in file_getbuffer
Shadow bytes around the buggy address:
  0x0c06800439d0: 00 00 fa fa fd fd fd fa fa fa 00 00 00 00 fa fa
  0x0c06800439e0: 00 00 00 fa fa fa fd fd fd fa fa fa fd fd fd fd
  0x0c06800439f0: fa fa fd fd fd fa fa fa fd fd fd fd fa fa 00 00
  0x0c0680043a00: 00 00 fa fa 00 00 00 fa fa fa 00 00 00 00 fa fa
  0x0c0680043a10: fd fd fd fa fa fa 00 00 00 00 fa fa 00 00 00 00
=>0x0c0680043a20: fa fa fd fd fd fd fa fa 00 00 00[06]fa fa fa fa
  0x0c0680043a30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0680043a40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0680043a50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0680043a60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0680043a70: 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
==2470365==ABORTING
@wargio
Copy link
Member

wargio commented Aug 22, 2022

attach the bin here so we can reproduce this.

@XVilka XVilka added this to the 0.4.1 milestone Aug 22, 2022
wargio added a commit that referenced this issue Aug 22, 2022
This was referenced Aug 22, 2022
wargio added a commit that referenced this issue Aug 23, 2022
@XVilka XVilka closed this as completed in ca370dd Aug 24, 2022
XVilka pushed a commit that referenced this issue Aug 24, 2022
XVilka pushed a commit that referenced this issue Aug 24, 2022
imbillow pushed a commit that referenced this issue Aug 24, 2022
XVilka pushed a commit that referenced this issue Aug 30, 2022
XVilka pushed a commit that referenced this issue Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants