From edd239ce95a7762f567f8222c1e52588f49496a0 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Fri, 5 Mar 2021 21:38:48 +0100 Subject: [PATCH] more stable raw mem access in signal handlers --- libafl/src/executors/inprocess.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 266588a3f9..889c919a8d 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -51,8 +51,12 @@ where ) -> Result<(), Error> { #[cfg(unix)] unsafe { - unix_signal_handler::GLOBAL_STATE.current_input_ptr = - _input as *const _ as *const c_void; + let data = &mut unix_signal_handler::GLOBAL_STATE; + data.current_input_ptr = _input as *const _ as *const c_void; + // Direct raw pointers access /aliasing is pretty undefined behavior. + // Since the state and event may have moved in memory, refresh them right before the signal may happen + data.state_ptr = _state as *mut _ as *mut c_void; + data.event_mgr_ptr = _event_mgr as *mut _ as *mut c_void; } Ok(()) } @@ -123,8 +127,6 @@ where #[cfg(unix)] unsafe { let mut data = &mut unix_signal_handler::GLOBAL_STATE; - data.state_ptr = _state as *mut _ as *mut c_void; - data.event_mgr_ptr = _event_mgr as *mut _ as *mut c_void; data.observers_ptr = &observers as *const _ as *const c_void; data.crash_handler = unix_signal_handler::inproc_crash_handler::; data.timeout_handler =