From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by sourceware.org (Postfix) with ESMTPS id 8907E385702C for ; Tue, 13 Apr 2021 13:36:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8907E385702C Received: by mail-qt1-x82f.google.com with SMTP id f12so12708192qtf.2 for ; Tue, 13 Apr 2021 06:36:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=R9VmtiIwsJCfiUG92cly5tDEzlByQeP7k2NQEONbvas=; b=EXLceo/yPZs/5wWBbY/gDdGqEHZZMmtrIqUnoFOf3fKel2ZC4gVgvjr5FdSdlH/laq LI/SXNRZtRsUbV5djo3vrzBzQnj2RqPGtlUT3F2jy94K09iIyCGFTQJUP5ir5r8RZEop LyqU7CcUrKAXpK4cYFRwAf78M8HEbebOi0E7PKgCU5EYSqMKwnXjmWDeN3TRBxHIXn6g 4MlGKR2AtGv5St4T8lfcCvvK5qo8L80gnyeRswPr7/3SaaV5ZD//YGh+oFYY3F5Fvn1F BJWW81SdReDkA81BPigeH70BEgW5SyfTIDdj0zu479uZpmQ6FuXpYFlQZpM1YD4bE2L4 Iekw== X-Gm-Message-State: AOAM532KHpxSgulmLJ1dRGoS3h4psMWcxb2lU8SZmD9CR+Wqp3IwhSQD 8h+eY1h5YQRNeEL+zM/YSAyY0uHJ3l4/brYM X-Google-Smtp-Source: ABdhPJzbE8TgPF5t8UjLKNbosBQqHFNkeVV8WxUZLbndV1AwHcAOWve4Je6I5CXQZ3zgX2E9IKKSzw== X-Received: by 2002:a05:622a:646:: with SMTP id a6mr21222966qtb.383.1618320991837; Tue, 13 Apr 2021 06:36:31 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id g4sm9665243qtg.86.2021.04.13.06.36.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Apr 2021 06:36:31 -0700 (PDT) Subject: Re: [PATCH] linux: sysconf: limit _SC_MAX_ARG to 6 MiB [BZ #25305] To: Andreas Schwab , Michal Nazarewicz Cc: libc-alpha@sourceware.org References: <20210407151058.1176364-1-mina86@mina86.com> <46c3ea60-7a57-14f7-92f9-e915e3b12dae@linaro.org> <87im4qe61s.fsf@igel.home> From: Adhemerval Zanella Message-ID: Date: Tue, 13 Apr 2021 10:36:29 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <87im4qe61s.fsf@igel.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2021 13:36:33 -0000 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 >>> >>>> --- >>>> 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; }