Skip to content

Commit fabd337

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Fix aarch64 SIGSEGV in linkLightWeightFunctionFrame for large frames
Summary: On aarch64 with Python 3.12, `add_signed_immediate()` can clobber `arch::reg_scratch_0` when the frame offset exceeds 4095 bytes (the maximum for ARM64 ADD/SUB immediates). On Python 3.12, `frame_holder` aliases x12 (it holds `tstate->cframe`), so the subsequent store to `frame_holder->current_frame` writes to a garbage address, causing a SIGSEGV. This only triggers for functions with large JIT stack frames (>4103 bytes). Reviewed By: DinoV Differential Revision: D96482818 fbshipit-source-id: ba4f08643e281ed80776fe8b22b8900aca381eb6
1 parent 663cf6a commit fabd337

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cinderx/Jit/codegen/frame_asm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,12 @@ void FrameAsm::linkLightWeightFunctionFrame(
828828
scratch,
829829
arch::ptr_offset(frame_holder, offsetof(PyThreadState, current_frame)));
830830
#else
831+
// add_signed_immediate may have clobbered arch::reg_scratch_0 (x12) when the
832+
// offset was too large for an ADD/SUB immediate. frame_holder aliases x12 on
833+
// 3.12, so reload it from tstate.
834+
as_->ldr(
835+
frame_holder,
836+
arch::ptr_offset(tstate_reg, offsetof(PyThreadState, cframe)));
831837
// (PyThreadState.cframe|PyThreadState).current_frame = &cur_frame
832838
as_->str(
833839
scratch,

0 commit comments

Comments
 (0)