]> git.lizzy.rs Git - rust.git/commitdiff
panic/fork: Command: Do not unwind after fork() in child
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 20 Apr 2021 19:04:31 +0000 (20:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 May 2021 10:17:44 +0000 (11:17 +0100)
Unwinding after fork() in the child is UB on some platforms, because
on those (including musl) malloc can be UB in the child of a
multithreaded program, and unwinding must box for the payload.

Even if it's safe, unwinding past fork() in the child causes whatever
traps the unwind to return twice.  This is very strange and clearly
not desirable.  With the default behaviour of the thread library, this
can even result in a panic in the child being transformed into zero
exit status (ie, success) as seen in the parent!

Fixes #79740.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
library/std/src/sys/unix/process/process_unix.rs

index ed9044382a898c98e655f10d08ba28d01d4533be..08b500b9c825a32d810c7d708c0ffae59e79130f 100644 (file)
@@ -54,6 +54,7 @@ pub fn spawn(
         let (env_lock, pid) = unsafe { (sys::os::env_read_lock(), cvt(libc::fork())?) };
 
         if pid == 0 {
+            crate::panic::always_abort();
             mem::forget(env_lock);
             drop(input);
             let Err(err) = unsafe { self.do_exec(theirs, envp.as_ref()) };