From nobody Fri Jan 2 11:56:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3191ECDB465 for ; Thu, 12 Oct 2023 01:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235257AbjJLBr2 (ORCPT ); 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 ); 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 ) 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 To: Alejandro Colomar Cc: linux-man@vger.kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, Matthew House , Eric Biederman 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-Transfer-Encoding: quoted-printable Sender: riel@surriel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The execve syscall returns -E2BIG in 3 cases: - The total length of the command line arguments and environment is too lar= ge. - 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=3D"a" for loop in `seq 20`; do STRING=3D"$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 Suggested-by: Matthew House --- 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 --=20 2.41.0