]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
all: fix adjustment of /proc/$pid/cmdline by single binary
authorMax Filippov <jcmvbkbc@gmail.com>
Mon, 27 Dec 2021 11:58:28 +0000 (11:58 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 27 Dec 2021 12:09:39 +0000 (12:09 +0000)
When configured with --enable-single-binary tools issue incorrect prctl:

  prctl(PR_SET_KEEPCAPS, ...)      = -1 EINVAL (Invalid argument)

PR_SET_MM_ARG_START is not a prctl 'option' parameter, it's 'arg2'
parameter for the option PR_SET_MM.  It also has to have 'arg4' and
'arg5' set to 0 explicitly, otherwise the kernel also returns -EINVAL.

* src/coreutils.c (launch_program): Fix prctl arguments.
* NEWS: Mention the improvement.
Fixes https://bugs.gnu.org/52800

NEWS
src/coreutils.c

diff --git a/NEWS b/NEWS
index 811e27e3af820554e987410f70061a2f86e01ec0..72453dc4b5bf8da51d4eab505fb1e97aa1018efb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   sort --debug now diagnoses issues with --field-separator characters
   that conflict with characters possibly used in numbers.
 
+  root invoked coreutils, that are built and run in single binary mode,
+  now adjust /proc/$pid/cmdline to be more specific to the utility
+  being run, rather than using the general "coreutils" binary name.
+
 
 * Noteworthy changes in release 9.0 (2021-09-24) [stable]
 
index 6db5a8f05ce3a28b48b96142ebf6ddfb2afc550f..63dfa228cb3e3f8e3e8bf864b75a616ea650dbfb 100644 (file)
@@ -120,8 +120,9 @@ launch_program (char const *prog_name, int prog_argc, char **prog_argv)
 #endif
 #if HAVE_PRCTL && defined PR_SET_MM_ARG_START
   /* Shift the beginning of the command line to prog_argv[0] (if set) so
-     /proc/pid/cmdline reflects the right value.  */
-  prctl (PR_SET_MM_ARG_START, prog_argv[0]);
+     /proc/$pid/cmdline reflects a more specific value.  Note one needs
+     CAP_SYS_RESOURCE or root privileges for this to succeed.  */
+  prctl (PR_SET_MM, PR_SET_MM_ARG_START, prog_argv[0], 0, 0);
 #endif
 
   exit (prog_main (prog_argc, prog_argv));