From patchwork Thu Oct 12 01:46:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 151637 Return-Path: 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 + 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 ); 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 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:41 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779512391079806027 X-GMAIL-MSGID: 1779512391079806027 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