Skip to content

coreutils: Protect against env -a for security#10773

Open
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:auxval
Open

coreutils: Protect against env -a for security#10773
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:auxval

Conversation

@oech3
Copy link
Contributor

@oech3 oech3 commented Feb 6, 2026

env -a false ls does not fail. Works under masked /proc.
Closes #10135

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/usage_vs_getopt (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/basenc/bounded-memory is now being skipped but was previously passing.

@oech3 oech3 marked this pull request as ready for review February 6, 2026 19:18
@oech3 oech3 force-pushed the auxval branch 3 times, most recently from 01b6655 to 753f86c Compare February 7, 2026 07:47
@github-actions
Copy link

github-actions bot commented Feb 7, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/shuf/shuf-reservoir (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/sort/sort-stale-thread-mem (fails in this run but passes in the 'main' branch)

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 7, 2026

Merging this PR will not alter performance

✅ 118 untouched benchmarks
⏩ 228 skipped benchmarks1


Comparing oech3:auxval (3b4ab62) with main (1ee881b)

Open in CodSpeed

Footnotes

  1. 228 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@oech3 oech3 force-pushed the auxval branch 2 times, most recently from 59e307c to ac75ff7 Compare February 8, 2026 15:58
@github-actions
Copy link

github-actions bot commented Feb 8, 2026

GNU testsuite comparison:

GNU test failed: tests/cut/bounded-memory. tests/cut/bounded-memory is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/pr/bounded-memory is no longer failing!

@ChrisDryden
Copy link
Collaborator

I think it would make sense for this code to go into the validation.rs file instead of in the main.rs, then you don't have to worry about importing libc.

It would be good to have an additional integration test that shows the env -a working

@oech3

This comment was marked as resolved.

@oech3

This comment was marked as outdated.

@oech3

This comment was marked as resolved.

@oech3 oech3 force-pushed the auxval branch 3 times, most recently from 1337cbc to 40581ee Compare February 8, 2026 21:47
@github-actions
Copy link

github-actions bot commented Feb 8, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/tail/tail-n0f is now passing!

@oech3 oech3 force-pushed the auxval branch 2 times, most recently from a5dd042 to 526f6fc Compare February 9, 2026 08:32
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/shuf/shuf-reservoir (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/sort/sort-stale-thread-mem (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/tail/tail-n0f is now passing!

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

GNU testsuite comparison:

GNU test failed: tests/cut/bounded-memory. tests/cut/bounded-memory is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/pr/bounded-memory. tests/pr/bounded-memory is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tail/follow-name (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Congrats! The gnu test tests/pr/bounded-memory is now passing!

1 similar comment
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Congrats! The gnu test tests/pr/bounded-memory is now passing!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Congrats! The gnu test tests/pr/bounded-memory is now passing!

@Ecordonnier
Copy link
Collaborator

Ecordonnier commented Mar 11, 2026

Can you please check this CI failure?

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?

For reference, an AI tools suggests this fix. Maybe you have a better idea:

 #[cfg(any(target_os = "linux", target_os = "android"))]
 pub fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
-    let _ = args.next();
     use std::os::unix::ffi::OsStrExt;
-    OsStr::from_bytes(rustix::param::linux_execfn().to_bytes()).into()
+    
+    let argv0 = args.next().unwrap_or_default();
+    let execfn = rustix::param::linux_execfn();
+    let execfn_path: PathBuf = OsStr::from_bytes(execfn.to_bytes()).into();
+    
+    // When invoked via shebang, linux_execfn() returns the script path, not the interpreter.
+    // Check if execfn points to our actual binary by comparing canonical paths.
+    // If they match (direct execution), use execfn to prevent env -a hijacking.
+    // If not (shebang case), use argv[0] which contains the interpreter path.
+    if let (Ok(current_exe), Ok(execfn_canonical)) = (
+        std::env::current_exe(),
+        std::fs::canonicalize(&execfn_path)
+    ) {
+        if execfn_canonical == current_exe {
+            return execfn_path;
+        }
+    }
+    
+    // Fallback to argv[0] for shebang execution
+    PathBuf::from(argv0)
 }
 /// Extracts the binary name from a path
 pub fn name(binary_path: &Path) -> Option<&str> {

@oech3

This comment was marked as resolved.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@oech3

This comment was marked as outdated.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/cp/parent-perm-race. tests/cp/parent-perm-race is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/env/env. tests/env/env is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/csplit/csplit-heap is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@oech3

This comment was marked as outdated.

@oech3 oech3 force-pushed the auxval branch 2 times, most recently from b9cb65f to 5a57da3 Compare March 12, 2026 06:40
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Congrats! The gnu test tests/pr/bounded-memory is now passing!

@oech3
Copy link
Contributor Author

oech3 commented Mar 12, 2026

I was considering calling true under the symlink chain:
invalid-name -> coreutils -> true for better symlink support.
Does it cover some usecase for shebang call?

@oech3

This comment was marked as outdated.

@oech3 oech3 marked this pull request as draft March 12, 2026 09:50
@oech3
Copy link
Contributor Author

oech3 commented Mar 12, 2026

Is read()ing #! faster than reading /proc/self/exe?

@oech3 oech3 force-pushed the auxval branch 2 times, most recently from a2fec5c to 880c4ba Compare March 12, 2026 14:23
@oech3
Copy link
Contributor Author

oech3 commented Mar 12, 2026

I did too many conversion for file pathes. Please drop them by review...

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/pipe-f is now passing!

@oech3 oech3 marked this pull request as ready for review March 12, 2026 14:50
Co-authored-by: Etienne Cordonnier <ecordonnier@snap.com>
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/io-errors. tests/misc/io-errors is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ubuntu patch prevents custom argv[0]

3 participants