Repository navigation
Fix buffer overflow in Proc#== when no env - #19978
Merged
Merged
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Crashes with: