Note this has security implications as the following could
be used to invoke any command for a USER where
their login shell has been set to /bin/false.

  $ su -l -- USER --coreutils-prog=env CMD

In that case, su passes "-false" to the multi-call binary,
and it then processes the options, invoking any CMD.

* src/coreutils.c: Strip a leading '-', to support logins
shells that flag they're login shells by prepending a '-'.
* tests/misc/coreutils.sh: Add test cases.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-RLLE8E8F.
---
 NEWS                    |  6 ++++++
 src/coreutils.c         |  9 ++++++++-
 tests/misc/coreutils.sh | 21 +++++++++++++++++++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 8e7098784..2aaddbed7 100644
--- a/NEWS
+++ b/NEWS
@@ -419,6 +419,12 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   contain path components.
   [bug introduced with multi-call binary support in coreutils-8.23]
 
+  The multi-call binary now recognizes login-shell names such as '-false'.
+  Previously, when an account's shell was 'false' linked to the multi-call
+  binary, an authenticated caller could pass arguments to the login shell
+  and run commands as that account.
+  [bug introduced with multi-call binary support in coreutils-8.23]
+
 ** New Features
 
   The multi-call binary accepts 'coreutils PROGRAM [ARG]...' as a shorthand
diff --git a/src/coreutils.c b/src/coreutils.c
index 10f852a8c..66b658e25 100644
--- a/src/coreutils.c
+++ b/src/coreutils.c
@@ -166,7 +166,14 @@ launch_program (char const *prog_name, int prog_argc, char 
**prog_argv)
 int
 main (int argc, char **argv)
 {
-  char *prog_name = last_component (argv[0]);
+  /* A login shell can have '-' prepended to argv[0].
+     It's important we match e.g. "false" so that
+     we don't fall through and run --coreutils-prog=...
+     as that would bypass a configured /bin/false shell.  */
+  char const *invocation = argv[0];
+  if (*invocation == '-')
+    invocation++;
+  char *prog_name = last_component (invocation);
   int optc;
 
   /* A built-in selected by argv[0] takes precedence over argv[1].  */
diff --git a/tests/misc/coreutils.sh b/tests/misc/coreutils.sh
index 4138cb963..ee03a7829 100755
--- a/tests/misc/coreutils.sh
+++ b/tests/misc/coreutils.sh
@@ -49,6 +49,27 @@ echo yes > exp || framework_failure_
 ./yes yes | head -n1 > out
 compare exp out || fail=1
 
+# A login-style argv[0] selects the built-in before processing arguments.
+coreutils --list > progs || fail=1
+if grep '^true$' progs >/dev/null; then
+  env -a -true ./blah >out 2>&1 || fail=1
+  compare /dev/null out || fail=1
+fi
+if grep '^false$' progs >/dev/null; then
+  for name in -false -/bin/false; do
+    returns_ 1 env -a "$name" ./blah >out 2>&1 || fail=1
+    compare /dev/null out || fail=1
+  done
+fi
+
+# Strip just one leading '-', and leave a '-' after a slash intact.
+echo "coreutils: unknown program '-false'" > exp || framework_failure_
+returns_ 1 env -a --false ./blah 2>err || fail=1
+compare exp err || fail=1
+ln -s blah ./-false || framework_failure_
+returns_ 1 ./-false 2>err || fail=1
+compare exp err || fail=1
+
 # Ensure empty arg is rejected
 returns_ 1 coreutils $unset_command || fail=1
 
-- 
2.56.0


Reply via email to