From 811b8952d574e3fbd2e5e186217369dab8b3e824 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Fri, 1 May 2026 14:05:57 +0900 Subject: [PATCH] coreutils: fix panic on linux < 6.4 when /proc is not mounted --- .vscode/cspell.dictionaries/workspace.wordlist.txt | 1 + Cargo.toml | 5 ++--- src/common/validation.rs | 10 ++++++++-- tests/test_util_name.rs | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.vscode/cspell.dictionaries/workspace.wordlist.txt b/.vscode/cspell.dictionaries/workspace.wordlist.txt index 2faa150d30..7d0661357e 100644 --- a/.vscode/cspell.dictionaries/workspace.wordlist.txt +++ b/.vscode/cspell.dictionaries/workspace.wordlist.txt @@ -367,6 +367,7 @@ getcwd setpipe # * other +auxv getlimits weblate algs diff --git a/Cargo.toml b/Cargo.toml index 7665710c72..7589c83ec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -450,9 +450,8 @@ rstest = "0.26.0" rstest_reuse = "0.7.0" rustc-hash = "2.1.1" rust-ini = "0.21.0" -# binary name of coreutils can be hijacked by overriding getauxval via LD_PRELOAD -# So we use param and avoid libc backend -rustix = { version = "1.1.4", features = ["param"] } +# raw-backend's linux_execfn is not supported on linux < 6.4 if /proc is not mounted. So use-libc-auxv is needed +rustix = { version = "1.1.4", features = ["param", "use-libc-auxv"] } same-file = "1.0.6" self_cell = "1.0.4" selinux = "0.6" diff --git a/src/common/validation.rs b/src/common/validation.rs index ad55165df4..124fa1dbb6 100644 --- a/src/common/validation.rs +++ b/src/common/validation.rs @@ -74,7 +74,10 @@ fn get_canonical_util_name(util_name: &str) -> &str { /// Gets the binary path from command line arguments /// Panics if the binary path cannot be determined -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(any( + not(any(target_os = "linux", target_os = "android")), + target_env = "musl" +))] pub fn binary_path(args: &mut impl Iterator) -> PathBuf { match args.next() { Some(ref s) if !s.is_empty() => PathBuf::from(s), @@ -84,7 +87,10 @@ pub fn binary_path(args: &mut impl Iterator) -> PathBuf { } /// Get actual binary path from kernel, not argv0, to prevent `env -a` from bypassing /// AppArmor, SELinux policies on hard-linked binaries -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(all( + any(target_os = "linux", target_os = "android"), + not(target_env = "musl") +))] pub fn binary_path(args: &mut impl Iterator) -> PathBuf { use std::fs::File; use std::io::Read; diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index 71d6f6ebea..a716b512a8 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -27,7 +27,11 @@ fn init() { } #[test] -#[cfg(all(feature = "env", any(target_os = "linux", target_os = "android")))] +#[cfg(all( + feature = "env", + any(target_os = "linux", target_os = "android"), + not(target_env = "musl") +))] fn binary_name_protection() { let ts = TestScenario::new("env"); let bin = ts.bin_path.clone();