ZJIT: Reject ISEQs with too-large stack_max (#13770)

This commit is contained in:
Takashi Kokubun 2025-07-02 13:01:24 -07:00 committed by GitHub
parent e240b415a5
commit d5f5a56bf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View file

@ -125,6 +125,7 @@ jobs:
../src/bootstraptest/test_literal_suffix.rb \ ../src/bootstraptest/test_literal_suffix.rb \
../src/bootstraptest/test_load.rb \ ../src/bootstraptest/test_load.rb \
../src/bootstraptest/test_marshal.rb \ ../src/bootstraptest/test_marshal.rb \
../src/bootstraptest/test_massign.rb \
../src/bootstraptest/test_method.rb \ ../src/bootstraptest/test_method.rb \
../src/bootstraptest/test_objectspace.rb \ ../src/bootstraptest/test_objectspace.rb \
../src/bootstraptest/test_string.rb \ ../src/bootstraptest/test_string.rb \
@ -136,7 +137,6 @@ jobs:
../src/bootstraptest/test_yjit_rust_port.rb ../src/bootstraptest/test_yjit_rust_port.rb
# ../src/bootstraptest/test_eval.rb \ # ../src/bootstraptest/test_eval.rb \
# ../src/bootstraptest/test_insns.rb \ # ../src/bootstraptest/test_insns.rb \
# ../src/bootstraptest/test_massign.rb \
# ../src/bootstraptest/test_proc.rb \ # ../src/bootstraptest/test_proc.rb \
# ../src/bootstraptest/test_ractor.rb \ # ../src/bootstraptest/test_ractor.rb \
# ../src/bootstraptest/test_yjit.rb \ # ../src/bootstraptest/test_yjit.rb \

View file

@ -936,7 +936,7 @@ pub fn stur(cb: &mut CodeBlock, rt: A64Opnd, rn: A64Opnd) {
let bytes: [u8; 4] = match (rt, rn) { let bytes: [u8; 4] = match (rt, rn) {
(A64Opnd::Reg(rt), A64Opnd::Mem(rn)) => { (A64Opnd::Reg(rt), A64Opnd::Mem(rn)) => {
assert!(rn.num_bits == 32 || rn.num_bits == 64); assert!(rn.num_bits == 32 || rn.num_bits == 64);
assert!(mem_disp_fits_bits(rn.disp), "Expected displacement to be 9 bits or less"); assert!(mem_disp_fits_bits(rn.disp), "Expected displacement {} to be 9 bits or less", rn.disp);
LoadStore::stur(rt.reg_no, rn.base_reg_no, rn.disp as i16, rn.num_bits).into() LoadStore::stur(rt.reg_no, rn.base_reg_no, rn.disp as i16, rn.num_bits).into()
}, },

View file

@ -72,6 +72,14 @@ pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, _ec: EcPtr) -> *co
return std::ptr::null(); return std::ptr::null();
} }
// Reject ISEQs with very large temp stacks.
// We cannot encode too large offsets to access locals in arm64.
let stack_max = unsafe { rb_get_iseq_body_stack_max(iseq) };
if stack_max >= i8::MAX as u32 {
debug!("ISEQ stack too large: {stack_max}");
return std::ptr::null();
}
// Take a lock to avoid writing to ISEQ in parallel with Ractors. // Take a lock to avoid writing to ISEQ in parallel with Ractors.
// with_vm_lock() does nothing if the program doesn't use Ractors. // with_vm_lock() does nothing if the program doesn't use Ractors.
let code_ptr = with_vm_lock(src_loc!(), || { let code_ptr = with_vm_lock(src_loc!(), || {