Subject: bug#52800: closed (Re: bug#52800: [PATCH] maint: fix prctl arguments)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 26 Dec 2021 17:27:01 +0000

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 [email-masked].

-- 
52800: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=52800
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#52800: [PATCH] maint: fix prctl arguments
From: Pádraig Brady <[email-masked]>
To: Max Filippov <[email-masked]>, [email-masked]
Date: Sun, 26 Dec 2021 17:26:20 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

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

Subject: [PATCH] maint: fix prctl arguments
From: Max Filippov <[email-masked]>
To: [email-masked]
Cc: Max Filippov <[email-masked]>
Date: Sat, 25 Dec 2021 21:17:44 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

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