Restrict the dispatcher name to (or suffixed with) "coreutils".
This gives stronger protection where argv[0] may be set to
something arbitrary. E.g. FreeBSD su sets argv[0] to "su" or "-su".
If a user's shell is configured as /bin/false (linked to the
dispatcher), we don't want the dispatcher honoring --coreutils-prog.
For example we want to disallow the following:
$ su -l -- USER --coreutils-prog=env CMD
I.e. this is a stronger mitigation that provided in
commit v9.12-344-g2f223b9c9. This is seen as more important
that supporting arbitrary dispatcher names.
Installing a dispatcher with non "coreutils" suffix
is seen to be very unusual, and if so probably not required.
* NEWS: Augment the bug fix item, and the Build-related change.
* configure.ac: Ensure the dispatcher is always "*coreutils".
* doc/coreutils.texi: Remove the now defunct detail on --coreutils-prog.
* src/coreutils.c: Restrict the dispatcher functionality
to dispatchers suffixed with "coreutils".
* tests/misc/coreutils.sh: Adjust accordingly.
---
NEWS | 4 ++++
configure.ac | 12 +++++++++---
doc/coreutils.texi | 6 +-----
src/coreutils.c | 14 +++++---------
tests/misc/coreutils.sh | 7 +++++++
5 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/NEWS b/NEWS
index c63e5cffe..df86e62f1 100644
--- a/NEWS
+++ b/NEWS
@@ -423,6 +423,8 @@ GNU coreutils NEWS -*-
outline -*-
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.
+ The binary also rejects program-selection options when invoked under an
+ unknown name, as can happen when a login tool supplies its own name.
[bug introduced with multi-call binary support in coreutils-8.23]
** New Features
@@ -522,6 +524,8 @@ GNU coreutils NEWS -*-
outline -*-
The configure options --enable-single-binary=symlinks and =hardlinks
now support --program-prefix, e.g. --program-prefix=gnu.
+ All --enable-single-binary modes require the installed dispatcher name
+ to end in 'coreutils' before any platform executable suffix.
* Noteworthy changes in release 9.12 (2026-09-14) [stable]
diff --git a/configure.ac b/configure.ac
index 5f23e6d1a..527e89bca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -907,6 +907,15 @@ if test "$gl_single_binary" != no; then
esac
done
+ # Undo the quoting of '\' and '$' for make.
+ cu_transform=$(printf '%s\n' "$program_transform_name" |
+ sed 's/\([[\\$]]\)\1/\1/g')
+ case $(echo coreutils | sed "$cu_transform") in
+ *coreutils) ;;
+ *) AC_MSG_ERROR([the installed dispatcher name must end in 'coreutils'
+ with --enable-single-binary=$gl_single_binary]) ;;
+ esac
+
if test "$gl_single_binary" != shebangs; then
case $program_prefix in
-*) AC_MSG_ERROR([--program-prefix must not start with '-'
@@ -918,9 +927,6 @@ if test "$gl_single_binary" != no; then
cu_names=$(printf '%s\n' coreutils $single_binary_progs |
sed 's/^ginstall$/install/')
cu_expected=$(for p in $cu_names; do printf '%s\n' "$cu_prefix$p"; done)
- # Undo the quoting of '\' and '$' for make.
- cu_transform=$(printf '%s\n' "$program_transform_name" |
- sed 's/\([[\\$]]\)\1/\1/g')
if test "$(printf '%s\n' "$cu_names" | sed "$cu_transform")" \
!= "$cu_expected"; then
AC_MSG_ERROR([only --program-prefix is supported for renaming programs
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 18eb4cafe..1eeaf5c96 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -1694,13 +1694,9 @@ coreutils @var{program} @dots{}
coreutils @option{--coreutils-prog=@var{program}} @dots{}
@end example
-The first explicit form, e.g. @samp{coreutils ls}, requires that
+The explicit forms, e.g. @samp{coreutils ls}, requires that
the multi-call binary is invoked through name ending in @samp{coreutils}.
-The second explicit form with the @option{--coreutils-prog=@var{program}}
option
-gives the additional flexibility of invoking the multi-call binary
-through a name that does not end with @samp{coreutils}.
-
The program accepts the following options. Also see @ref{Common options}.
@table @samp
diff --git a/src/coreutils.c b/src/coreutils.c
index 39ea9c95a..178955b24 100644
--- a/src/coreutils.c
+++ b/src/coreutils.c
@@ -166,10 +166,7 @@ launch_program (char const *prog_name, int prog_argc, char
**prog_argv)
int
main (int argc, char **argv)
{
- /* 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. */
+ /* A login shell can have '-' prepended to argv[0]. */
char const *invocation = argv[0];
if (*invocation == '-')
invocation++;
@@ -185,17 +182,16 @@ main (int argc, char **argv)
/* A built-in selected by argv[0] takes precedence over argv[1]. */
launch_program (prog_name, argc, argv);
- /* Accept a positional program name only when invoked as the dispatcher. */
+ /* Only the dispatcher may select a built-in from its arguments. */
bool is_coreutils = (str_endswith (prog_name, PROGRAM_NAME)
|| (EXEEXT[0]
&& str_endswith (prog_name, PROGRAM_NAME EXEEXT)));
size_t nskip = 0;
- if (argc >= 2)
+ if (is_coreutils && argc >= 2)
{
char *arg_name = NULL;
- /* If calling coreutils directly, the "script" name isn't passed.
- Distinguish the two cases with a -shebang suffix. */
+ /* --coreutils-prog is deprecated since v9.13. */
if (STRPREFIX (argv[1], "--coreutils-prog="))
{
nskip = 1;
@@ -210,7 +206,7 @@ main (int argc, char **argv)
else
arg_name = prog_name;
}
- else if (is_coreutils && argv[1][0] != '-')
+ else if (argv[1][0] != '-')
{
nskip = 1;
arg_name = prog_name = argv[1];
diff --git a/tests/misc/coreutils.sh b/tests/misc/coreutils.sh
index c9bd8d916..ab0579b81 100755
--- a/tests/misc/coreutils.sh
+++ b/tests/misc/coreutils.sh
@@ -34,6 +34,9 @@ for cu in coreutils "./gcoreutils$EXEEXT"; do
$cu yes 'two words' ls | head -n1 > out
compare exp out || fail=1
done
+"./gcoreutils$EXEEXT" --coreutils-prog-shebang=yes renamed 'two words' ls |
+ head -n1 > out
+compare exp out || fail=1
# The installed name 'install' selects the ginstall built-in.
if coreutils --coreutils-prog=ginstall --version > exp 2>/dev/null; then
@@ -87,5 +90,9 @@ returns_ 1 ./blah --version 2>err || fail=1
compare exp err || fail=1
returns_ 1 ./blah yes --version 2>err || fail=1
compare exp err || fail=1
+returns_ 1 ./blah --coreutils-prog=yes --version 2>err || fail=1
+compare exp err || fail=1
+returns_ 1 ./blah --coreutils-prog-shebang=yes renamed --version 2>err ||
fail=1
+compare exp err || fail=1
Exit $fail
--
2.56.0