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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52800 in the body.
You can then email your comments to 52800 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#52800; Package coreutils. (Sun, 26 Dec 2021 09:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Max Filippov <jcmvbkbc <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 26 Dec 2021 09:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

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





Reply sent to Pádraig Brady <P <at> draigBrady.com>:
You have taken responsibility. (Sun, 26 Dec 2021 17:27:01 GMT) Full text and rfc822 format available.

Notification sent to Max Filippov <jcmvbkbc <at> gmail.com>:
bug acknowledged by developer. (Sun, 26 Dec 2021 17:27:01 GMT) Full text and rfc822 format available.

Message #10 received at 52800-done <at> debbugs.gnu.org (full text, mbox):

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




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 24 Jan 2022 12:24:04 GMT) Full text and rfc822 format available.

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.