GNU bug report logs - #52800
[PATCH] maint: fix prctl arguments

Previous Next

Package: coreutils;

Reported by: Max Filippov <jcmvbkbc <at> gmail.com>

Date: Sun, 26 Dec 2021 09:03:01 UTC

Severity: normal

Tags: patch

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Max Filippov <jcmvbkbc <at> gmail.com>
Subject: bug#52800: closed (Re: bug#52800: [PATCH] maint: fix prctl arguments)
Date: Sun, 26 Dec 2021 17:27:01 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#52800: [PATCH] maint: fix prctl arguments

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 52800 <at> debbugs.gnu.org.

-- 
52800: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=52800
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Pádraig Brady <P <at> draigBrady.com>
To: Max Filippov <jcmvbkbc <at> gmail.com>, 52800-done <at> debbugs.gnu.org
Subject: Re: bug#52800: [PATCH] maint: fix prctl arguments
Date: Sun, 26 Dec 2021 17:26:20 +0000
On 26/12/2021 05:17, Max Filippov wrote:
> When configured with --enable-single-binary tools issue incorrect prctl:
> 
>    prctl(PR_SET_KEEPCAPS, 1071091381)      = -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.
> ---
>   src/coreutils.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/coreutils.c b/src/coreutils.c
> index 6db5a8f05ce3..d8f6e97a6d2f 100644
> --- a/src/coreutils.c
> +++ b/src/coreutils.c
> @@ -121,7 +121,7 @@ launch_program (char const *prog_name, int prog_argc, char **prog_argv)
>   #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]);
> +  prctl (PR_SET_MM, PR_SET_MM_ARG_START, prog_argv[0], 0, 0);
>   #endif
>   
>     exit (prog_main (prog_argc, prog_argv));

Nice one.

This functionality allows programs like ps to attribute
to more specific "utilities", rather than the general "coreutils" binary.

However this is only available with CAP_SYS_RESOURCE or root.
Note CAP_SYS_RESOURCE wouldn't be appropriate to set on the coreutils binary in general.
I confirmed your patch is effective for coreutils invoked by root with:

$ src/sleep 5 & { sleep 1; tr '\0' '\n' < /proc/$!/cmdline; }
/home/padraig/git/coreutils/src/coreutils
--coreutils-prog-shebang=sleep
src/sleep
5

# src/sleep 5 & { sleep 1; tr '\0' '\n' < /proc/$!/cmdline; }
sleep
5

I'll apply later (with some adjustments to NEWS)
Marking this as done.

thanks!
Pádraig

[Message part 3 (message/rfc822, inline)]
From: Max Filippov <jcmvbkbc <at> gmail.com>
To: bug-coreutils <at> gnu.org
Cc: Max Filippov <jcmvbkbc <at> gmail.com>
Subject: [PATCH] maint: fix prctl arguments
Date: Sat, 25 Dec 2021 21:17:44 -0800
When configured with --enable-single-binary tools issue incorrect prctl:

  prctl(PR_SET_KEEPCAPS, 1071091381)      = -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.
---
 src/coreutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/coreutils.c b/src/coreutils.c
index 6db5a8f05ce3..d8f6e97a6d2f 100644
--- a/src/coreutils.c
+++ b/src/coreutils.c
@@ -121,7 +121,7 @@ launch_program (char const *prog_name, int prog_argc, char **prog_argv)
 #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]);
+  prctl (PR_SET_MM, PR_SET_MM_ARG_START, prog_argv[0], 0, 0);
 #endif
 
   exit (prog_main (prog_argc, prog_argv));
-- 
2.20.1




This bug report was last modified 3 years and 143 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.