From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by sourceware.org (Postfix) with ESMTPS id 638B63943541 for ; Tue, 13 Apr 2021 14:45:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 638B63943541 Received: by mail-qv1-xf2a.google.com with SMTP id o11so8138636qvh.11 for ; Tue, 13 Apr 2021 07:45:45 -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=SPAjLD9SjCur+U3HCEF9R2ONHTjF1jNvS9KNrd69B4Y=; b=fZRiAelCCV8hd/i85g/zlBC0GFF3fDhVhGnexKcoPB4FGhuWw8zhihDAZGOKLLeR1K yLae2zQLbAnNT/j85DO1gywefnBOic0TNYJOCuYUGp6vc8rCedTnZjyJzG/T9KCbh8sl 2b+sUkPm5dJ+rWF+VEt937MDMlu2fRVeYpIHTDj+3Nm0l3fYnAF4JH6l6tvLfhG0IXKl x0Q0HN7etVF71qp/9rEWqhphJi+3c+FoO7G+h/u+kcDgjcpmx15sjZCkuuso3OD8t7ow wCdFLmtGvaRQs6BlBXSUjWSSFC/xZ1NPKzukgYIVx8dM1FPCtneG23eFPP0hqJbuwoy0 sK8A== X-Gm-Message-State: AOAM530Cm098PMN9L8nc4HD/UOhy7Omb4O82go5DFgd1imlP684r/r2X h6w0eQxMfHF487CXAl5mAOWHDabm321il7yh X-Google-Smtp-Source: ABdhPJyPEV/MC0mFcqV2OnFdVK6KYaUF3c/pUKzfGUHN+diwMSi9nAGy1oCHoSvcmtS/1b+fR42N4w== X-Received: by 2002:ad4:458b:: with SMTP id x11mr451560qvu.36.1618325144780; Tue, 13 Apr 2021 07:45:44 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id a4sm9523180qta.19.2021.04.13.07.45.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Apr 2021 07:45:44 -0700 (PDT) Subject: Re: [PATCH] linux: sysconf: limit _SC_MAX_ARG to 6 MiB [BZ #25305] To: Andreas Schwab Cc: Michal Nazarewicz , libc-alpha@sourceware.org References: <20210407151058.1176364-1-mina86@mina86.com> <46c3ea60-7a57-14f7-92f9-e915e3b12dae@linaro.org> <87im4qe61s.fsf@igel.home> <87eefedz76.fsf@igel.home> From: Adhemerval Zanella Message-ID: Date: Tue, 13 Apr 2021 11:45:41 -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: <87eefedz76.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 14:45:46 -0000 On 13/04/2021 11:41, Andreas Schwab wrote: > On Apr 13 2021, Adhemerval Zanella wrote: > >> 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 > > I'd still use 6 * 1024 * 1024 here, small numbers are much easier to > grok. Ack.