@@ -238,8 +238,10 @@ pub fn sv_loop(
238238 init_pid : unistd:: Pid ,
239239 event_tx : ipc:: IpcSender < MemEvents > ,
240240 confirm_tx : ipc:: IpcSender < Confirmation > ,
241- page_size : usize ,
242241) -> Result < !, Option < i32 > > {
242+ let page_size = PAGE_SIZE . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ;
243+ assert_ne ! ( page_size, 0 ) ;
244+
243245 // Things that we return to the child process.
244246 let mut acc_events = Vec :: new ( ) ;
245247
@@ -289,6 +291,7 @@ pub fn sv_loop(
289291 event_tx. send ( MemEvents { acc_events } ) . unwrap ( ) ;
290292 // And reset our values.
291293 acc_events = Vec :: new ( ) ;
294+ ch_pages = Vec :: new ( ) ;
292295 ch_stack = None ;
293296
294297 // No need to monitor syscalls anymore, they'd just be ignored.
@@ -550,6 +553,12 @@ fn handle_segfault(
550553 // - Parse executed code to estimate size & type of access
551554 // - Reprotect the memory
552555 // - Continue
556+
557+ // Zero out the stack
558+ for a in ( ch_stack..ch_stack. strict_add ( FAKE_STACK_SIZE ) ) . step_by ( ARCH_WORD_SIZE ) {
559+ ptrace:: write ( pid, std:: ptr:: with_exposed_provenance_mut ( a) , 0 ) . unwrap ( ) ;
560+ }
561+
553562 let stack_ptr = ch_stack. strict_add ( FAKE_STACK_SIZE / 2 ) ;
554563 let regs_bak = ptrace:: getregs ( pid) . unwrap ( ) ;
555564 let mut new_regs = regs_bak;
@@ -591,6 +600,11 @@ fn handle_segfault(
591600 // Also, don't let it continue with unprotected memory if something errors!
592601 let _ = wait:: waitid ( wait:: Id :: Pid ( pid) , WAIT_FLAGS ) . map_err ( |_| ExecError :: Died ( None ) ) ?;
593602
603+ // Zero it out again to be safe
604+ for a in ( ch_stack..ch_stack. strict_add ( FAKE_STACK_SIZE ) ) . step_by ( ARCH_WORD_SIZE ) {
605+ ptrace:: write ( pid, std:: ptr:: with_exposed_provenance_mut ( a) , 0 ) . unwrap ( ) ;
606+ }
607+
594608 // Save registers and grab the bytes that were executed. This would
595609 // be really nasty if it was a jump or similar but those thankfully
596610 // won't do memory accesses and so can't trigger this!
0 commit comments