Message ID | 20231011125330.13dfe148@imladris.surriel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp677424vqb; Wed, 11 Oct 2023 09:53:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESesABzxgNBWi0m5ODZa1FzDUxUcJLCBDuI/3O97SLjvrkt3czPvwnUOdZLQRYW3iD1Sfh X-Received: by 2002:a05:6358:e908:b0:147:47f2:2d54 with SMTP id gk8-20020a056358e90800b0014747f22d54mr17864366rwb.0.1697043223345; Wed, 11 Oct 2023 09:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697043223; cv=none; d=google.com; s=arc-20160816; b=gcyXJKk1EXHNWPY5ETXXdXHcu56aIvMjNty24vNsS9c2WuZOs9L3ulNxDmg8VNBmVQ VlX6xcaVUfOkueB6nq/l4au8eSN435bzjQIf0k64jFwdp0usggnsrcRa1JCmHcZ5+6se Fcd4h+iHkbfJVnlerIx8qwo0v3gKrYiwdlJSLI5Gl9LZdvFcQBF/fHc7hLsiNvlLMMbE RtwOxhA6aQONp4copYU+fiHmg3XFPGeSNiwtg2vaNKhhTHpMUU/zIkZSUA0cgdE45n9p aOLruWXqGt6Ob1MKHgW8bIfltMULZVD2I4c5KfPHujwGWCNTvXKXnj/Q+jT/9YScmlNr DRNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=E9Nu6MWqkgzopJiZbWfh36dE/tMxu5XcZps97Ik2zaI=; fh=HYxLO3S768M7tUNLkDARmUq/zTs37P/jEkR4H0foy4g=; b=cYlde6NUKHgN/7a0NiVgLb+p0LBixVdsbGC1znfLBcYr1YYcwly3/4Ct291tnQoVkz pCLghbFt6otqI5v6K7l6hemwpDp0sp7g7iZfDhUPTUia5POOvd/zzVGq0J9AaFJipmfb jPHZLxzoiTAGZ6wnr7VAEXn+XARBwtdS/1b3HaPSje4U3LeEEQBYe/6iv7haPw/b3tw1 qH99/cvgfE8nhJb6UL6KUTgLNLVGq2471cFHZUBdHmQ9aQcCbU/UYwZrZ1hW9Iih/cUF dJS0CCUuK0jF1lAXrNPA4DWOZEsgDkYlVSU59RSRuYUsch9uIMwhch+i4OfF5kL74XyU srpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f11-20020a056a0022cb00b00690de92ffe3si13209834pfj.309.2023.10.11.09.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 09:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 74A3081D4764; Wed, 11 Oct 2023 09:53:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232931AbjJKQxj (ORCPT <rfc822;kartikey406@gmail.com> + 18 others); Wed, 11 Oct 2023 12:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbjJKQxi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 11 Oct 2023 12:53:38 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D00998; Wed, 11 Oct 2023 09:53:37 -0700 (PDT) Received: from [2601:18c:9101:a8b6:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from <riel@shelob.surriel.com>) id 1qqcSg-0004XY-37; Wed, 11 Oct 2023 12:53:30 -0400 Date: Wed, 11 Oct 2023 12:53:30 -0400 From: Rik van Riel <riel@surriel.com> To: Alejandro Colomar <alx@kernel.org> Cc: linux-man@vger.kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, Matthew House <mattlloydhouse@gmail.com>, Eric Biederman <ebiederm@xmission.com> Subject: [PATCH v4] execve.2: execve also returns E2BIG if a string is too long Message-ID: <20231011125330.13dfe148@imladris.surriel.com> In-Reply-To: <20231011124301.4d93ea72@imladris.surriel.com> References: <20231011124301.4d93ea72@imladris.surriel.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: riel@surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 09:53:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779478167987928633 X-GMAIL-MSGID: 1779478794888403647 |
Series |
[v4] execve.2: execve also returns E2BIG if a string is too long
|
|
Commit Message
Rik van Riel
Oct. 11, 2023, 4:53 p.m. UTC
Sigh, once again I did a git commit --amend without the latest file change being
included. The change below should be good. Working with both git and hg gets me sometimes :/
---8<---
The execve syscall returns -E2BIG in 3 cases:
- The total length of the command line arguments and environment is too large.
- An argument or environment string is longer than MAX_ARG_STRLEN.
- The full path to the executable exceeds MAX_ARG_STRLEN.
Spell out all 3 cases in the -E2BIG section.
Discovered by moving a too large commandline parameter to an environment
variable, and finding that things still did not work. Examined the code
in fs/exec.c to get the details.
This simple shell script starts failing at 2^17 on a system with 4kB
page size:
./exec2big.sh: line 10: /bin/true: Argument list too long
fork failed at loop 17
STRING="a"
for loop in `seq 20`; do
STRING="$STRING$STRING"
export STRING
if /bin/true ; then
: # still under the limit
else
echo "fork failed at loop $loop"
fi
done
Signed-off-by: Rik van Riel <riel@surriel.com>
Suggested-by: Matthew House <mattlloydhouse@gmail.com>
---
man2/execve.2 | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
Hi Rik, On Wed, Oct 11, 2023 at 12:53:30PM -0400, Rik van Riel wrote: > Sigh, once again I did a git commit --amend without the latest file change being > included. The change below should be good. Working with both git and hg gets me sometimes :/ Been there. Hate that. I hope I don't touch hg(1) anymore. :D Did you know about git-remote-hg(1)? It lets you work with hg remotes without running hg(1) at all. It had some glitches from time to time --TBH, I'm not sure if the glitches were from git-remote-hg(1), or just that hg(1) is crap, or that the maintainers of the hg remote weren't so good at it--, but nothing too irritating or destructive. Cheers, Alex
Hi Rik, On Wed, Oct 11, 2023 at 12:53:30PM -0400, Rik van Riel wrote: > Sigh, once again I did a git commit --amend without the latest file change being > included. The change below should be good. Working with both git and hg gets me sometimes :/ > ---8<--- > > The execve syscall returns -E2BIG in 3 cases: > - The total length of the command line arguments and environment is too large. > - An argument or environment string is longer than MAX_ARG_STRLEN. I'm still concerned by the wording of this sentence (and the next one). When I (and any user-space programmer, I think) read "string is longer than FOO", I read `strlen(string) > FOO`. Since it's rather `strlen(string) >= FOO`, I think you should clarify. How about this? - An argument or environment string is longer (including the null byte) than MAX_ARG_STRLEN. Thanks, Alex > - The full path to the executable exceeds MAX_ARG_STRLEN. > > Spell out all 3 cases in the -E2BIG section. > > Discovered by moving a too large commandline parameter to an environment > variable, and finding that things still did not work. Examined the code > in fs/exec.c to get the details. > > This simple shell script starts failing at 2^17 on a system with 4kB > page size: > ./exec2big.sh: line 10: /bin/true: Argument list too long > fork failed at loop 17 > > STRING="a" > > for loop in `seq 20`; do > STRING="$STRING$STRING" > export STRING > if /bin/true ; then > : # still under the limit > else > echo "fork failed at loop $loop" > fi > done Thank you very much! > > Signed-off-by: Rik van Riel <riel@surriel.com> > Suggested-by: Matthew House <mattlloydhouse@gmail.com> > --- > man2/execve.2 | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/man2/execve.2 b/man2/execve.2 > index 0d9582492ad1..b689101771e5 100644 > --- a/man2/execve.2 > +++ b/man2/execve.2 > @@ -449,7 +449,12 @@ The total number of bytes in the environment > .RI ( envp ) > and argument list > .RI ( argv ) > -is too large. > +is too large, > +an argument or environment string is too long, > +or the full > +.I pathname > +of the executable is too long. > +The terminating NUL is counted as part of the string length. > .TP > .B EACCES > Search permission is denied on a component of the path prefix of > -- > 2.41.0 > >
On Wed, 2023-10-11 at 22:14 +0200, Alejandro Colomar wrote: > Hi Rik, > > On Wed, Oct 11, 2023 at 12:53:30PM -0400, Rik van Riel wrote: > > Sigh, once again I did a git commit --amend without the latest file > > change being > > included. The change below should be good. Working with both git > > and hg gets me sometimes :/ > > ---8<--- > > > > The execve syscall returns -E2BIG in 3 cases: > > - The total length of the command line arguments and environment is > > too large. > > - An argument or environment string is longer than MAX_ARG_STRLEN. > > I'm still concerned by the wording of this sentence (and the next > one). > When I (and any user-space programmer, I think) read "string is > longer > than FOO", I read `strlen(string) > FOO`. Since it's rather > `strlen(string) >= FOO`, I think you should clarify. How about this? > > - An argument or environment string is longer (including the null > byte) > than MAX_ARG_STRLEN. That works. Would you like me to re-send a v5, or do you want to massage the changelog when you apply the patch? I must admit I paid more attention to the wording in the man page than the wording in the changelog :)
On Wed, Oct 11, 2023 at 04:53:20PM -0400, Rik van Riel wrote: > On Wed, 2023-10-11 at 22:14 +0200, Alejandro Colomar wrote: > > Hi Rik, > > > > On Wed, Oct 11, 2023 at 12:53:30PM -0400, Rik van Riel wrote: > > > Sigh, once again I did a git commit --amend without the latest file > > > change being > > > included. The change below should be good. Working with both git > > > and hg gets me sometimes :/ > > > ---8<--- > > > > > > The execve syscall returns -E2BIG in 3 cases: > > > - The total length of the command line arguments and environment is > > > too large. > > > - An argument or environment string is longer than MAX_ARG_STRLEN. > > > > I'm still concerned by the wording of this sentence (and the next > > one). > > When I (and any user-space programmer, I think) read "string is > > longer > > than FOO", I read `strlen(string) > FOO`. Since it's rather > > `strlen(string) >= FOO`, I think you should clarify. How about this? > > > > - An argument or environment string is longer (including the null > > byte) > > than MAX_ARG_STRLEN. > > That works. Would you like me to re-send a v5, or do you > want to massage the changelog when you apply the patch? > > I must admit I paid more attention to the wording in the > man page than the wording in the changelog :) I wouldn't mind doing it myself, but I'll ask you to resend, if you don't mind. I usually find that doing so helps catch other accidents that I didn't catch. :) Cheers, Alex > > -- > All Rights Reversed. :)
diff --git a/man2/execve.2 b/man2/execve.2 index 0d9582492ad1..b689101771e5 100644 --- a/man2/execve.2 +++ b/man2/execve.2 @@ -449,7 +449,12 @@ The total number of bytes in the environment .RI ( envp ) and argument list .RI ( argv ) -is too large. +is too large, +an argument or environment string is too long, +or the full +.I pathname +of the executable is too long. +The terminating NUL is counted as part of the string length. .TP .B EACCES Search permission is denied on a component of the path prefix of