Skip to content

Commit de2e483

Browse files
committed
Only use clone3 when needed for pidfd
In #89522 we learned that `clone3` is interacting poorly with Gentoo's `sandbox` tool. We only need that for the unstable pidfd extensions, so otherwise avoid that and use a normal `fork`.
1 parent 58268ff commit de2e483

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/std/src/sys/unix/process/process_unix.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,18 @@ impl Command {
166166
fn clone3(cl_args: *mut clone_args, len: libc::size_t) -> libc::c_long
167167
}
168168

169+
// Bypassing libc for `clone3` can make further libc calls unsafe,
170+
// so we use it sparingly for now. See #89522 for details.
171+
let want_clone3 = self.get_create_pidfd();
172+
169173
// If we fail to create a pidfd for any reason, this will
170174
// stay as -1, which indicates an error.
171175
let mut pidfd: pid_t = -1;
172176

173177
// Attempt to use the `clone3` syscall, which supports more arguments
174178
// (in particular, the ability to create a pidfd). If this fails,
175179
// we will fall through this block to a call to `fork()`
176-
if HAS_CLONE3.load(Ordering::Relaxed) {
180+
if want_clone3 && HAS_CLONE3.load(Ordering::Relaxed) {
177181
let mut flags = 0;
178182
if self.get_create_pidfd() {
179183
flags |= CLONE_PIDFD;

0 commit comments

Comments
 (0)