Message ID | 20231011214652.1c4db8b7@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 ib8csp926685vqb; Wed, 11 Oct 2023 18:47:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDCyrV6yvPEQwJ26g5/a/x4bcXDLCgq3Noj8iBnE9K0mHGyyEsdV+LhlK+sr/ObWuN0Bis X-Received: by 2002:a17:90a:4ca4:b0:274:99ed:a80c with SMTP id k33-20020a17090a4ca400b0027499eda80cmr20343904pjh.3.1697075263250; Wed, 11 Oct 2023 18:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697075263; cv=none; d=google.com; s=arc-20160816; b=XmkZo02V9jJDjlvGWSYWvkRSDin79C3xFnNVLnOweka9gQcMVgKYvF9m48R4ytLoCK UqkFsM4Y81Hnsbu/qvmFBHvx/nsjpMBjQheOceHaZtWPEh5JnavwGJbC0vcfFFW3UkYV TfkX6hjDDyrI2VTDEmn/sYpnKW8eRgizHhaN0JHpyszkGm4gD0+NQd+u/SfYiU50rZsG EO2dNCaNGhXFDgU6TK4uUnNq1RbdUhARaS8HB42FSbztdCIWTh1FX16pk8r7kSQe509+ WvJGGor/WNG4AipO7TszhZGxjwNGnWtVkBQxbEIpKiCpMK8nrD+BWTqISaGq112ky3Om YlGA== 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 :message-id:subject:cc:to:from:date; bh=Mz5MIubZ/sqCCNZv1S74TOE05MIYMmyILZOvwx8DJxU=; fh=HYxLO3S768M7tUNLkDARmUq/zTs37P/jEkR4H0foy4g=; b=hFvT+2NO1bbJchd36CIn5YSiqI1X2lIQA8BK8fuYW63gutixR9Sy8V4A4sD+9sh6vW QyhnUFK7bdz+WmNWOBZZrW6D5+gFOs5NMLgOBeWHXwatsz7xkGcu2qHczCluEUnVJVyk 2kS53m4Aeo8YpCHhBwAK8M1aynhXjzQyu5VtVTzfArMGnt9fAGB5M0tM/Tn2fZG1Zf9U wVyShK8S3Sfw3dWiGN2OM9WWTz2xKB5yoCUlm37pZ5z42xexb9KzVlNKQ/ZbovglAUT9 /+6XPdk2z/X8q+mQX5CdYEf+Gi5/2bkT5h7oCHxehvmNYbtE7NWucjCueDtyiU6PCMpO 74xQ== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ci6-20020a17090afc8600b00274c8943b59si1047265pjb.64.2023.10.11.18.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 18:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 5083F8112ABC; Wed, 11 Oct 2023 18:47:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234080AbjJLBr2 (ORCPT <rfc822;kartikey406@gmail.com> + 18 others); Wed, 11 Oct 2023 21:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234068AbjJLBr1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 11 Oct 2023 21:47:27 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E6FBB6; Wed, 11 Oct 2023 18:47:25 -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 1qqkmu-0000Ci-2X; Wed, 11 Oct 2023 21:46:56 -0400 Date: Wed, 11 Oct 2023 21:46:52 -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 v5] execve.2: execve also returns E2BIG if a string is too long Message-ID: <20231011214652.1c4db8b7@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=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Wed, 11 Oct 2023 18:47:41 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779512391079806027 X-GMAIL-MSGID: 1779512391079806027 |
Series |
[v5] execve.2: execve also returns E2BIG if a string is too long
|
|
Commit Message
Rik van Riel
Oct. 12, 2023, 1:46 a.m. UTC
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 (including the NUL byte) is longer than MAX_ARG_STRLEN.
- The full path to the executable (including the NUL byte) 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
#!/bin/sh
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 09:46:52PM -0400, Rik van Riel wrote: > 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 (including the NUL byte) is longer than MAX_ARG_STRLEN. > - The full path to the executable (including the NUL byte) exceeds MAX_ARG_STRLEN. I changed the above to fit in 72 columns. > > 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 Moved this to after the script. > > #!/bin/sh And indented the script to avoid issues with git and hashes in commit messages. > 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> And reordered this. Patch applied. :) <https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=39a4ac5820cbdc8c9f7ebaad70f1adcc59955cbb> > --- > 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. I replaced s/NUL/null byte/ man-pages(7): NULL, NUL, null pointer, and null byte A null pointer is a pointer that points to nothing, and is nor‐ mally indicated by the constant NULL. On the other hand, NUL is the null byte, a byte with the value 0, represented in C via the character constant '\0'. The preferred term for the pointer is "null pointer" or simply "NULL"; avoid writing "NULL pointer". The preferred term for the byte is "null byte". Avoid writing "NUL", since it is too easily confused with "NULL". Avoid also the terms "zero byte" and "null character". The byte that ter‐ minates a C string should be described as "the terminating null byte"; strings may be described as "null‐terminated", but avoid the use of "NUL‐terminated". I kept NUL in the commit message, because I actually like using NUL, but Michael didn't, and for consistency, I keep that in the body of the manual pages. In the commit message, it's fine for me. Cheers, Alex > .TP > .B EACCES > Search permission is denied on a component of the path prefix of > -- > 2.41.0 >
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