@@ -238,8 +238,10 @@ pub fn sv_loop(
238
238
init_pid : unistd:: Pid ,
239
239
event_tx : ipc:: IpcSender < MemEvents > ,
240
240
confirm_tx : ipc:: IpcSender < Confirmation > ,
241
- page_size : usize ,
242
241
) -> Result < !, Option < i32 > > {
242
+ let page_size = PAGE_SIZE . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ;
243
+ assert_ne ! ( page_size, 0 ) ;
244
+
243
245
// Things that we return to the child process.
244
246
let mut acc_events = Vec :: new ( ) ;
245
247
@@ -289,6 +291,7 @@ pub fn sv_loop(
289
291
event_tx. send ( MemEvents { acc_events } ) . unwrap ( ) ;
290
292
// And reset our values.
291
293
acc_events = Vec :: new ( ) ;
294
+ ch_pages = Vec :: new ( ) ;
292
295
ch_stack = None ;
293
296
294
297
// No need to monitor syscalls anymore, they'd just be ignored.
@@ -550,6 +553,12 @@ fn handle_segfault(
550
553
// - Parse executed code to estimate size & type of access
551
554
// - Reprotect the memory
552
555
// - 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
+
553
562
let stack_ptr = ch_stack. strict_add ( FAKE_STACK_SIZE / 2 ) ;
554
563
let regs_bak = ptrace:: getregs ( pid) . unwrap ( ) ;
555
564
let mut new_regs = regs_bak;
@@ -591,6 +600,11 @@ fn handle_segfault(
591
600
// Also, don't let it continue with unprotected memory if something errors!
592
601
let _ = wait:: waitid ( wait:: Id :: Pid ( pid) , WAIT_FLAGS ) . map_err ( |_| ExecError :: Died ( None ) ) ?;
593
602
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
+
594
608
// Save registers and grab the bytes that were executed. This would
595
609
// be really nasty if it was a jump or similar but those thankfully
596
610
// won't do memory accesses and so can't trigger this!
0 commit comments