Skip to content

Commit f8564cc

Browse files
committed
Fix stack-use-after-return on jit_module_noslotsdef (ASAN root cause python#1)
PyModule_Create stores a pointer to the PyModuleDef in the module object's md_def field. jit_module_noslotsdef was a stack-local in jit::initialize(), so md_def dangled after the function returned. GC's module_traverse then read from dead stack memory, causing heap corruption under sustained GC pressure (the 7/17 single-process crash). Fix: make jit_module_noslotsdef static so it survives the function call.
1 parent d00fd65 commit f8564cc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Python/jit/pyjit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,8 +3679,10 @@ int initialize() {
36793679
return -1;
36803680
}
36813681

3682-
// Use a copy with slots cleared for PyModule_Create compatibility
3683-
PyModuleDef jit_module_noslotsdef = jit_module;
3682+
// Use a copy with slots cleared for PyModule_Create compatibility.
3683+
// Must be static: PyModule_Create stores a pointer to the PyModuleDef in
3684+
// the module object (md_def). A stack-local would be use-after-return.
3685+
static PyModuleDef jit_module_noslotsdef = jit_module;
36843686
jit_module_noslotsdef.m_slots = nullptr;
36853687
PyObject* mod = PyModule_Create(&jit_module_noslotsdef);
36863688
if (mod == nullptr) {

0 commit comments

Comments
 (0)