Skip to content

Fix buffer overflow in Proc#== when no env - #19978

Merged
peterzhu2118 merged 1 commit into
ruby:masterfrom
peterzhu2118:proc-eq-no-env
Nov 18, 2026
Merged

peterzhu2118 merged 1 commit into
ruby:masterfrom
peterzhu2118:proc-eq-no-env

Conversation

@peterzhu2118

Copy link
Copy Markdown
Member

If an ifunc Proc doesn't have an env, then it can have a buffer overflow read in Proc#==.

For example, the following script crashes under ASAN:

c = proc { |a, b| }.curry
p(c == c)

Crashes with:

ERROR: AddressSanitizer: heap-buffer-overflow on address 0x604000013c38 at pc 0x000101bdb4f4 bp 0x00016fdf8f30 sp 0x00016fdf86c8
READ of size 32 at 0x604000013c38 thread T0
    #0 0x000101bdb4f0 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long)+0x594 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x1b4f0)
    #1 0x000101bdb8c8 in memcmp+0x54 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x1b8c8)
    #2 0x0001003fa160 in rb_proc_eq proc.c:2109
    #3 0x0001006c7624 in vm_call_cfunc_with_frame_ vm_insnhelper.c:3936
    #4 0x0001006b2898 in vm_call_method_each_type vm_insnhelper.c:5041
    #5 0x0001006b1f54 in vm_call_method vm_insnhelper.c
    #6 0x00010066f85c in vm_sendish vm_insnhelper.c:6443
    #7 0x00010066f85c in vm_exec_core insns.def:912
    #8 0x00010065aeb4 in rb_vm_exec vm.c:2930
    #9 0x0001001f0740 in rb_ec_exec_node eval.c:300
    #10 0x0001001f0568 in ruby_run_node eval.c:338
    #11 0x000100004c20 in rb_main main.c:42
    #12 0x000100004c20 in main main.c:62
    #13 0x0001916bcd78 in start+0x19f8 (dyld:arm64e+0x31d78)

If an ifunc Proc doesn't have an env, then it can have a buffer overflow
read in Proc#==.

For example, the following script crashes under ASAN:

    c = proc { |a, b| }.curry
    p(c == c)

Crashes with:

    ERROR: AddressSanitizer: heap-buffer-overflow on address 0x604000013c38 at pc 0x000101bdb4f4 bp 0x00016fdf8f30 sp 0x00016fdf86c8
    READ of size 32 at 0x604000013c38 thread T0
        #0 0x000101bdb4f0 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long)+0x594 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x1b4f0)
        #1 0x000101bdb8c8 in memcmp+0x54 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x1b8c8)
        ruby#2 0x0001003fa160 in rb_proc_eq proc.c:2109
        ruby#3 0x0001006c7624 in vm_call_cfunc_with_frame_ vm_insnhelper.c:3936
        ruby#4 0x0001006b2898 in vm_call_method_each_type vm_insnhelper.c:5041
        ruby#5 0x0001006b1f54 in vm_call_method vm_insnhelper.c
        ruby#6 0x00010066f85c in vm_sendish vm_insnhelper.c:6443
        ruby#7 0x00010066f85c in vm_exec_core insns.def:912
        ruby#8 0x00010065aeb4 in rb_vm_exec vm.c:2930
        ruby#9 0x0001001f0740 in rb_ec_exec_node eval.c:300
        ruby#10 0x0001001f0568 in ruby_run_node eval.c:338
        ruby#11 0x000100004c20 in rb_main main.c:42
        ruby#12 0x000100004c20 in main main.c:62
        ruby#13 0x0001916bcd78 in start+0x19f8 (dyld:arm64e+0x31d78)
@peterzhu2118
peterzhu2118 merged commit 333e489 into ruby:master Nov 18, 2026
139 checks passed
@peterzhu2118
peterzhu2118 deleted the proc-eq-no-env branch November 18, 2026 13:08
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 this pull request may close these issues.

1 participant