Skip to content

Commit ab328d1

Browse files
authored
coreutils: fix panic on linux < 6.4 when /proc is not mounted (#12104)
1 parent 9e3ab20 commit ab328d1

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

.vscode/cspell.dictionaries/workspace.wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ mkfifoat
368368
setpipe
369369

370370
# * other
371+
auxv
371372
getlimits
372373
weblate
373374
algs

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,8 @@ rstest = "0.26.0"
451451
rstest_reuse = "0.7.0"
452452
rustc-hash = "2.1.1"
453453
rust-ini = "0.21.0"
454-
# binary name of coreutils can be hijacked by overriding getauxval via LD_PRELOAD
455-
# So we use param and avoid libc backend
456-
rustix = { version = "1.1.4", features = ["param"] }
454+
# raw-backend's linux_execfn is not supported on linux < 6.4 if /proc is not mounted. So use-libc-auxv is needed
455+
rustix = { version = "1.1.4", features = ["param", "use-libc-auxv"] }
457456
same-file = "1.0.6"
458457
self_cell = "1.0.4"
459458
selinux = "0.6"

src/common/validation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ fn get_canonical_util_name(util_name: &str) -> &str {
7474

7575
/// Gets the binary path from command line arguments
7676
/// Panics if the binary path cannot be determined
77-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
77+
#[cfg(any(
78+
not(any(target_os = "linux", target_os = "android")),
79+
target_env = "musl"
80+
))]
7881
pub fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
7982
match args.next() {
8083
Some(ref s) if !s.is_empty() => PathBuf::from(s),
@@ -84,7 +87,10 @@ pub fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
8487
}
8588
/// Get actual binary path from kernel, not argv0, to prevent `env -a` from bypassing
8689
/// AppArmor, SELinux policies on hard-linked binaries
87-
#[cfg(any(target_os = "linux", target_os = "android"))]
90+
#[cfg(all(
91+
any(target_os = "linux", target_os = "android"),
92+
not(target_env = "musl")
93+
))]
8894
pub fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
8995
use std::fs::File;
9096
use std::io::Read;

tests/test_util_name.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ fn init() {
2626
}
2727

2828
#[test]
29-
#[cfg(all(feature = "env", any(target_os = "linux", target_os = "android")))]
29+
#[cfg(all(
30+
feature = "env",
31+
any(target_os = "linux", target_os = "android"),
32+
not(target_env = "musl")
33+
))]
3034
fn binary_name_protection() {
3135
let ts = TestScenario::new("env");
3236
let bin = ts.bin_path.clone();

0 commit comments

Comments
 (0)