You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
We found a crashing test case when testing with the fuzzing driver mruby_fuzzer.
Here is the PoC:
class Object
def method_missing(nale, *args)
def method_missing(name, *args)
time2 = Time. == A 21,*30, Exception => 39
end
end
time = Time-utc(2019, 9, 15)
IPV6_MULTICAST_IFtime2 =
mod = Module.new
end
with the output and gdb backtrace:
Program received signal SIGSEGV, Segmentation fault.
#0 mrb_hash_size (mrb=<optimized out>, hash=hash@entry=...) at src/hash.c:1760
#1 in mrb_vm_exec (mrb=0x7c17a0, begin_proc=<optimized out>, iseq=<optimized out>) at src/vm.c:2403
#2 in mrb_load_exec (mrb=<optimized out>, p=0x7e0f30, c=<optimized out>) at mrbgems/mruby-compiler/core/parse.y:6971
#3 in LLVMFuzzerTestOneInput (Data=<optimized out>, size=218) at /src/mruby_fuzzer.c:14
This is fundamentally stack overflow from infinite recursion (method_missing is called within method_missing). Even CRuby causes stack overflow error. You shouldn't do it anyway. The problem is we cannot detect it. We will try to fix it, but the priory is low.
Although it is not perfect, I have previously conducted experiments to detect the limits of the system stack.
I'll organize the necessary pieces and send a PR.
@matz
This issue is not a system stack overflow, but rather an “Out-of-Bounds Read” in mruby.
To resolve it, could you merge #6598 or explore another solution?
Even if the recursion level is limited on the Ruby side, this issue will still crash on the second recursive call.
% valgrind -- build/host/bin/mruby topics/6584b.rb==81181== Memcheck, a memory error detector==81181== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.==81181== Using Valgrind-3.26.0 and LibVEX; rerun with -h for copyright info==81181== Command: build/host/bin/mruby topics/6584b.rb==81181====81181== Invalid read of size 8==81181== at 0x43036A: prepare_missing (vm.c:711)==81181== by 0x439317: mrb_vm_exec (vm.c:2300)==81181== by 0x442371: mrb_load_exec (parse.y:7798)==81181== by 0x44268F: mrb_load_detect_file_cxt (parse.y:7841)==81181== by 0x403CB8: main (mruby.c:355)==81181== Address 0x5616188 is 24 bytes after a block of size 1,024 in arena "client"==81181====81181== Invalid read of size 1==81181== at 0x435952: mrb_vm_exec (vm.c:2583)==81181== by 0x442371: mrb_load_exec (parse.y:7798)==81181== by 0x44268F: mrb_load_detect_file_cxt (parse.y:7841)==81181== by 0x403CB8: main (mruby.c:355)==81181== Address 0x448 is not stack'd, malloc'd or (recently) free'd==81181====81181====81181== Process terminating with default action of signal 11 (SIGSEGV): dumping core==81181== Access not within mapped region at address 0x448==81181== at 0x435952: mrb_vm_exec (vm.c:2583)==81181== by 0x442371: mrb_load_exec (parse.y:7798)==81181== by 0x44268F: mrb_load_detect_file_cxt (parse.y:7841)==81181== by 0x403CB8: main (mruby.c:355)==81181== If you believe this happened as a result of a stack==81181== overflow in your program's main thread (unlikely but==81181== possible), you can try to increase the size of the==81181== main thread stack using the --main-stacksize= flag.==81181== The main thread stack size used in this run was 16777216.==81181====81181== HEAP SUMMARY:==81181== in use at exit: 114,236 bytes in 718 blocks==81181== total heap usage: 805 allocs, 87 frees, 199,980 bytes allocated==81181====81181== LEAK SUMMARY:==81181== definitely lost: 0 bytes in 0 blocks==81181== indirectly lost: 0 bytes in 0 blocks==81181== possibly lost: 0 bytes in 0 blocks==81181== still reachable: 114,236 bytes in 718 blocks==81181== suppressed: 0 bytes in 0 blocks==81181== Rerun with --leak-check=full to see details of leaked memory==81181====81181== For lists of detected and suppressed errors, rerun with: -s==81181== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)zsh: segmentation fault valgrind -- build/host/bin/mruby topics/6584b.rb
Activity
dearblue commentedon Jul 28, 2025
Nice catch!
This is caused by a bug in the function that prepares
#method_missingwhen the method does not exist.mruby/src/vm.c
Line 700 in 2d054d5
matz commentedon Jul 30, 2025
This is fundamentally stack overflow from infinite recursion (method_missing is called within method_missing). Even CRuby causes stack overflow error. You shouldn't do it anyway. The problem is we cannot detect it. We will try to fix it, but the priory is low.
Fixed heap buffer overflow in `#method_missing`
dearblue commentedon Jul 30, 2025
Although it is not perfect, I have previously conducted experiments to detect the limits of the system stack.
I'll organize the necessary pieces and send a PR.
dearblue commentedon Mar 8, 2026
@matz
This issue is not a system stack overflow, but rather an “Out-of-Bounds Read” in mruby.
To resolve it, could you merge #6598 or explore another solution?
Even if the recursion level is limited on the Ruby side, this issue will still crash on the second recursive call.