Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp953069rdg; Wed, 11 Oct 2023 09:53:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVzWHVtbZdMBUcTeMxFPyt7eff5O7iOFfv4CPoUGeJnhnlbaEqpQAjKbInxCsHIXQHvlmM X-Received: by 2002:a17:902:f68b:b0:1c8:a68e:7f1 with SMTP id l11-20020a170902f68b00b001c8a68e07f1mr10340140plg.66.1697043221899; Wed, 11 Oct 2023 09:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697043221; cv=none; d=google.com; s=arc-20160816; b=wB+OaOHslhCMYtuZjx1CA4jefkyqMaptLDUqqxjaTy70apFEpDOyWmUUrUcJI6kYFn axoLeO6Vd28+uPDgTk56nGw8RFxATzzD/1eK0a9ZZ5U2BjjBlgrdxGYslZ0mYhmAdg73 1IL6pReOJT42jwyZQ+5TWa0mosf7tJccaMMfIINSQSPxc2XhPEvHOVTFOdkwQxDPXwUm F8x+PCBC6JbYdScdx8LID1FGP0lACOUt+t3/pER/omuUjepTKoELlpzG2e2xTzFFpa/O x3bDVvn2k1u50C4ll1mPweJ8f8CANY1QSzJyZkg5uAEnmmQ6X+eAXGR5EUcd0gJiatFX ipCA== 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 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b11-20020a170902d88b00b001b973681493si116607plz.16.2023.10.11.09.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 09:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 30CB581D2AF8; Wed, 11 Oct 2023 09:53:41 -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 S232917AbjJKQxj (ORCPT + 99 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 ); 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 ) 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 To: Alejandro Colomar Cc: linux-man@vger.kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, Matthew House , Eric Biederman 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: 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:41 -0700 (PDT) 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 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 -- 2.41.0