coreutils: Protect against env -a for security (#10773)

This prevents an attacker from spoofing argv[0] to bypass apparmor restrictions.

- `env -a false ls` now correctly runs `ls` instead of dispatching as `false`
- Also works under masked `/proc` (does not rely on /proc/self/exe).

Closes #10135
This commit is contained in:
oech3
2026-04-05 00:45:42 +02:00
committed by GitHub
parent 4552c0f9fd
commit b6c5dd1325
5 changed files with 52 additions and 5 deletions
+14
View File
@@ -26,6 +26,20 @@ fn init() {
eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}");
}
#[test]
#[cfg(all(feature = "env", any(target_os = "linux", target_os = "android")))]
fn binary_name_protection() {
let ts = TestScenario::new("env");
let bin = ts.bin_path.clone();
ts.ucmd()
.arg("-a")
.arg("hijacked")
.arg(&bin)
.arg("--version")
.succeeds()
.stdout_contains("coreutils");
}
#[test]
#[cfg(feature = "ls")]
fn execution_phrase_double() {