[PATCH] linux: sysconf: limit _SC_MAX_ARG to 6 MiB [BZ #25305]

Michal Nazarewicz mina86@mina86.com
Tue Apr 13 19:57:25 GMT 2021


> On 13/04/2021 09:13, Andreas Schwab wrote:
>> In addition, I'd give it a symbolic name with a comment.

On Tue, Apr 13 2021, Adhemerval Zanella wrote:
> 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

I’d still go with (6 * 1024 * 1024).  Otherwise looks good to me.

>  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;
>        }

On Tue, Apr 13 2021, Adhemerval Zanella wrote:
> Alright, I will change it and commit for you.

Thanks.

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»


More information about the Libc-alpha mailing list