From 5b2acfa526fe85782df53111f6b32d23d2d35010 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Thu, 22 Oct 2026 14:59:28 +0200 Subject: [PATCH] Don't work init if user is 0:0 --- init/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/init/src/main.rs b/init/src/main.rs index 8b7ba87..c0b93e9 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -353,6 +353,9 @@ fn exec_command(argv: &[String], user: Option) -> ! { let c_prog = cstrings[0].clone(); let c_refs: Vec<&CString> = cstrings.iter().collect(); + // If UserSpec is 0:0, don't fork. + let user = user.filter(|u| !u.uid.is_root() || u.gid != Gid::from_raw(0)); + match user { None => { // No privilege drop: exec directly, PID 1 becomes the command. @@ -362,6 +365,7 @@ fn exec_command(argv: &[String], user: Option) -> ! { std::process::exit(1); } Some(user) => { + warn(&format!("dropping privileges to {}:{}", user.uid, user.gid)); // Drop privileges in a child so PID 1 (root) can poweroff afterwards. match unsafe { fork() } { Ok(ForkResult::Child) => {