Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp13219rdg; Wed, 11 Oct 2023 18:47:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfJEHD53Hac5VzWPIUTdLFf9CXojKXdA7sYsPZSyh3BglR77JD5VKjhd3R/g77rQjgJREL X-Received: by 2002:a17:902:f7cf:b0:1c6:1c80:5663 with SMTP id h15-20020a170902f7cf00b001c61c805663mr18070792plw.41.1697075255702; Wed, 11 Oct 2023 18:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697075255; cv=none; d=google.com; s=arc-20160816; b=BMj18zjFBX1aIGDIx4hc+79zKJgS/S7L17GDVNuJsyLKuraTRdB97D296xfXjhNH6X AfB2wBOeMDtqbjPGnc5ZfDTABUY61mQYr4GOwHnv9if+CYeldIbf4b3tjt1xNBvzuc8x Ixh5XIkeHp2ziWFsb8qNbtB9v2Vw/JLIfWCp+dq5l8ZH1x3QA89nFHlPx6odhste1D+U yC18KbKje2mLFE2VBiFdrz6VPNroOOKgy8Jg1vPj+gfKwRXVd2GPR6NR0/8sL03Op7+3 8GbyMShp/MDGwFvE3KuX88FLs7XWITGwEm3jDizdYkxK3k+PO6dtKMtlzK6wlWj2DbF3 MXYQ== 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 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s5-20020a170902988500b001c60d1de681si926671plp.108.2023.10.11.18.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 18:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 4B3698112ABC; Wed, 11 Oct 2023 18:47:33 -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 S234032AbjJLBr2 (ORCPT + 99 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 ); 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-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: 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:33 -0700 (PDT) X-Spam-Level: ** 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 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