public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Andreas Schwab <schwab@linux-m68k.org>,
	Michal Nazarewicz <mina86@mina86.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] linux: sysconf: limit _SC_MAX_ARG to 6 MiB [BZ #25305]
Date: Tue, 13 Apr 2021 10:36:29 -0300	[thread overview]
Message-ID: <ed2aa039-d22a-8e04-7f7a-858aef18ae7e@linaro.org> (raw)
In-Reply-To: <87im4qe61s.fsf@igel.home>



On 13/04/2021 09:13, Andreas Schwab wrote:
> On Apr 12 2021, Michal Nazarewicz wrote:
> 
>>> On 07/04/2021 12:10, Michal Nazarewicz wrote:
>>>> Since Linux 4.13, kernel limits the maximum command line arguments
>>>> length to 6 MiB.¹  Normally the limit is still quarter of the maximum
>>>> stack size but if that limit exceeds 6 MiB it’s clamped down.
>>
>> On Mon, Apr 12 2021, Adhemerval Zanella wrote:
>>> Patch look good to me, thanks.
>>>
>>> Reviewed=by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>>>
>>>> ---
>>>>  sysdeps/unix/sysv/linux/sysconf.c | 5 ++++-
>>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
>>>> index 366fcef01e..bd711795c7 100644
>>>> --- a/sysdeps/unix/sysv/linux/sysconf.c
>>>> +++ b/sysdeps/unix/sysv/linux/sysconf.c
>>>> @@ -55,7 +55,10 @@ __sysconf (int name)
>>>>          struct rlimit rlimit;
>>>>          /* Use getrlimit to get the stack limit.  */
>>>>          if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
>>>> -	  return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
>>>> +	  {
>>>> +	    const long int limit = MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
>>>> +	    return MIN (limit, 6 << 10 << 10);
>>>
>>> I think it a bit easier to read with the value expanded (6291456).
>>
>> I’d rather go with ‘6 * 1024 * 1024’ if shifts aren’t readable.
> 
> In addition, I'd give it a symbolic name with a comment.

What about:

diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
index 366fcef01e..aceedfa87c 100644
--- a/sysdeps/unix/sysv/linux/sysconf.c
+++ b/sysdeps/unix/sysv/linux/sysconf.c
@@ -33,6 +33,9 @@
    actual value varies based on the stack size.  */
 #define legacy_ARG_MAX 131072
 
+/* Newer kernels (4.13) limit the maximum command line arguments lengths to
+   6MiB.  */
+#define maximum_ARG_MAX 6291456
 
 static long int posix_sysconf (int name);
 
@@ -55,7 +58,10 @@ __sysconf (int name)
         struct rlimit rlimit;
         /* Use getrlimit to get the stack limit.  */
         if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
-         return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
+         {
+           const long int limit = MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
+           return MIN (limit, maximum_ARG_MAX);
+         }
 
         return legacy_ARG_MAX;
       }


  reply	other threads:[~2021-04-13 13:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 15:10 Michal Nazarewicz
2021-04-07 18:36 ` Adhemerval Zanella
2021-04-07 18:41   ` Florian Weimer
2021-04-07 18:52     ` Adhemerval Zanella
2021-04-07 19:04       ` Florian Weimer
2021-04-07 19:34         ` Adhemerval Zanella
2021-04-07 19:36           ` Florian Weimer
2021-04-08  1:49           ` Michal Nazarewicz
2021-04-12 20:59 ` Adhemerval Zanella
2021-04-12 21:31   ` Michal Nazarewicz
2021-04-13 11:53     ` Adhemerval Zanella
2021-04-13 12:13     ` Andreas Schwab
2021-04-13 13:36       ` Adhemerval Zanella [this message]
2021-04-13 14:41         ` Andreas Schwab
2021-04-13 14:45           ` Adhemerval Zanella
2021-04-13 19:57         ` Michal Nazarewicz
2021-04-13 20:47           ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed2aa039-d22a-8e04-7f7a-858aef18ae7e@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=mina86@mina86.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).