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 buffer overflow in printstr #3588

Closed
clayton-shopify opened this Issue Apr 4, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@clayton-shopify
Contributor

clayton-shopify commented Apr 4, 2017

The following input demonstrates a crash:

puts '', '', '', '', '', '', '', '', '000000000000000000000000' while true

ASAN report:

==63782==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000b309 at pc 0x00010fd15846 bp 0x7fff502b4270 sp 0x7fff502b3a20
READ of size 1341 at 0x60300000b309 thread T0
    #0 0x10fd15845 in wrap_memchr (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x19845)
    #1 0x7fffbbc2f4d1 in __sfvwrite (libsystem_c.dylib:x86_64+0x404d1)
    #2 0x7fffbbc2f88c in fwrite (libsystem_c.dylib:x86_64+0x4088c)
    #3 0x10faeec23 in printstr (mruby:x86_64+0x1001acc23)
    #4 0x10faee56b in mrb_printstr (mruby:x86_64+0x1001ac56b)
    #5 0x10fab1d88 in mrb_vm_exec (mruby:x86_64+0x10016fd88)
    #6 0x10faa6f39 in mrb_vm_run (mruby:x86_64+0x100164f39)
    #7 0x10fad9849 in mrb_top_run (mruby:x86_64+0x100197849)
    #8 0x10fbaa845 in mrb_load_exec (mruby:x86_64+0x100268845)
    #9 0x10fbab655 in mrb_load_file_cxt (mruby:x86_64+0x100269655)
    #10 0x10f943e66 in main mruby.c:227
    #11 0x7fffbbbba234 in start (libdyld.dylib:x86_64+0x5234)

0x60300000b309 is located 0 bytes to the right of 25-byte region [0x60300000b2f0,0x60300000b309)
allocated by thread T0 here:
    #0 0x10fd52520 in wrap_realloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x56520)
    #1 0x10fa3bcf5 in mrb_default_allocf (mruby:x86_64+0x1000f9cf5)
    #2 0x10f9bd4f8 in mrb_realloc_simple gc.c:202
    #3 0x10f9bdbde in mrb_realloc gc.c:216
    #4 0x10f9be663 in mrb_malloc gc.c:237
    #5 0x10fa3d240 in mrb_str_pool (mruby:x86_64+0x1000fb240)
    #6 0x10fb7b3e4 in new_lit (mruby:x86_64+0x1002393e4)
    #7 0x10fb64b73 in codegen (mruby:x86_64+0x100222b73)
    #8 0x10fb77378 in gen_values (mruby:x86_64+0x100235378)
    #9 0x10fb7454e in gen_call (mruby:x86_64+0x10023254e)
    #10 0x10fb5a507 in codegen (mruby:x86_64+0x100218507)
    #11 0x10fb58e9b in codegen (mruby:x86_64+0x100216e9b)
    #12 0x10fb56681 in codegen (mruby:x86_64+0x100214681)
    #13 0x10fb6edd6 in scope_body (mruby:x86_64+0x10022cdd6)
    #14 0x10fb5a4d9 in codegen (mruby:x86_64+0x1002184d9)
    #15 0x10fb53c41 in mrb_generate_code (mruby:x86_64+0x100211c41)
    #16 0x10fba9cc0 in mrb_load_exec (mruby:x86_64+0x100267cc0)
    #17 0x10fbab655 in mrb_load_file_cxt (mruby:x86_64+0x100269655)
    #18 0x10f943e66 in main mruby.c:227
    #19 0x7fffbbbba234 in start (libdyld.dylib:x86_64+0x5234)

SUMMARY: AddressSanitizer: heap-buffer-overflow (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x19845) in wrap_memchr
Shadow bytes around the buggy address:
  0x1c0600001610: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0600001620: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0600001630: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0600001640: fa fa fa fa fa fa 00 00 00 fa fa fa 00 00 00 00
  0x1c0600001650: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
=>0x1c0600001660: 00[01]fa fa fd fd fd fd fa fa fd fd fd fd fa fa
  0x1c0600001670: 00 00 00 00 fa fa 00 00 00 fa fa fa 00 00 00 00
  0x1c0600001680: fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa 00 00
  0x1c0600001690: 00 fa fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa
  0x1c06000016a0: 00 00 00 fa fa fa 00 00 00 fa fa fa 00 00 00 fa
  0x1c06000016b0: fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa 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
  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
==63782==ABORTING
Abort trap: 6

This issue was reported by https://hackerone.com/titanous

@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Apr 10, 2017

Member

Fixed by #3596

Member

matz commented Apr 10, 2017

Fixed by #3596

@matz matz closed this Apr 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment