Project: mruby (mruby/mruby), language: c++
Vulnerability instance: mruby.cve-2018-12248
Sanitizer: address

================= Bug Report (1/1) ==================
## Source: GitHub Issue
## URL: https://github.com/mruby/mruby/issues/4038
## Description:
Issue: mruby/mruby#4038
Title: Heap buffer overflow in OP_ENTER
State: closed
Created by: clayton-shopify
Created at: 2018-06-05 22:08:03+00:00

Issue Body:
The following input demonstrates a crash:
```ruby
Fiber::new {|x|}.transfer(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62) 
```
This issue looks similar to #3641.

ASAN report:
```
==42706==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000000e80 at pc 0x00010d30e3fe bp 0x7ffee2dcd970 sp 0x7ffee2dcd120
READ of size 16 at 0x619000000e80 thread T0
    #0 0x10d30e3fd in __asan_memcpy (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f3fd)
    #1 0x10cedd8a8 in mrb_vm_exec vm.c:1859
    #2 0x10cec672b in mrb_vm_run vm.c:950
    #3 0x10cefe483 in mrb_top_run vm.c:3005
    #4 0x10d0fe067 in mrb_load_exec parse.y:5835
    #5 0x10d0feea9 in mrb_load_file_cxt parse.y:5844
    #6 0x10ce2a685 in main mruby.c:279
    #7 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)

0x619000000e80 is located 0 bytes to the right of 1024-byte region [0x619000000a80,0x619000000e80)
allocated by thread T0 here:
    #0 0x10d3161a7 in wrap_realloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x571a7)
    #1 0x10ceb2af5 in mrb_default_allocf state.c:55
    #2 0x10cfc9908 in mrb_realloc_simple gc.c:206
    #3 0x10cfca0d1 in mrb_realloc gc.c:220
    #4 0x10cfcaba3 in mrb_malloc gc.c:242
    #5 0x10d09953e in fiber_init fiber.c:97
    #6 0x10ce71499 in mrb_instance_new class.c:1591
    #7 0x10ced2fe1 in mrb_vm_exec vm.c:1472
    #8 0x10cec672b in mrb_vm_run vm.c:950
    #9 0x10cefe483 in mrb_top_run vm.c:3005
    #10 0x10d0fe067 in mrb_load_exec parse.y:5835
    #11 0x10d0feea9 in mrb_load_file_cxt parse.y:5844
    #12 0x10ce2a685 in main mruby.c:279
    #13 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)

SUMMARY: AddressSanitizer: heap-buffer-overflow (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f3fd) in __asan_memcpy
Shadow bytes around the buggy address:
  0x1c3200000180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c3200000190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c32000001a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c32000001b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c32000001c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1c32000001d0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c32000001e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c32000001f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c3200000200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c3200000210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c3200000220: 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
==42706==ABORTING
Abort trap: 6
```
This issue was reported by Daniel Teuchert, Cornelius Aschermann, Tommaso Frassetto and Tigist Abera (https://hackerone.com/pnoltof).


Comments:
Comment by jzySaber1996 on 2024-05-10 03:02:23+00:00:
 Hello, we're investigating the issue reports in security. Since we observed that this issue may relate to a potential vulnerability, has it been disclosed in CVE already? Hope to receive your reply.

---

Comment by matz on 2024-05-10 06:04:52+00:00:
I don't think so. It's a 6-year-old bug, and no one currently uses the version with this issue.

---

Comment by jzySaber1996 on 2024-05-10 06:16:21+00:00:
That's OK, we have found that it is disclosed in CVE-2018-12248. Thank you so much for your reply!

Build script:
#!/bin/bash -eu
# Minimized build script with only core build commands
set -eu
export LD=clang
export LDFLAGS="$CFLAGS"
./minirake clean && ./minirake -j$(nproc) all

Dockerfile:
FROM hwiwonlee/secb.base:latest
RUN apt-get update && apt-get install -y make autoconf automake libtool ruby bison
RUN git clone https://github.com/mruby/mruby mruby
RUN git -C mruby checkout ff0a4f78674308b7643db1da9b9dc591f25c21d0
WORKDIR $SRC/mruby
COPY build.sh $SRC/

Additional files: