Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp868559rdg; Wed, 11 Oct 2023 07:44:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtHwoApLAPyweb+vc0D/HsIMDAOVVG2c8+dLEdVzTLKTG5tEu+0FtiJXN5b1Dq++36iK1I X-Received: by 2002:a05:6871:79c:b0:1c0:1424:5e6c with SMTP id o28-20020a056871079c00b001c014245e6cmr21332334oap.17.1697035477230; Wed, 11 Oct 2023 07:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697035477; cv=none; d=google.com; s=arc-20160816; b=JxfNcoHcAAaatXbeCnOGj+RALEej3E1sWJlGnm/iatOu3zUaWgLETBaq4FQwUjuQAt aSRykl5qZnxP/LgwEomkjS/h66G4UAeSK7JS8RBdWRWRvu+3kJ8wzMnbxp2IoYp2JSVE C29cxH+n9yogFstQVfvdLKURhCq6gSXcbSI2ZHmDeb33Aw2OXr9J3V/UFeMplNsuVNYv G1VtcxPzdmhMRAxxH8GHI+uloX+zZcQRH4ls42r4wwep7Hq/ksXme8nK0t7xQcCOHoL0 CjDqxCa7+f0GijQht6A8aI+ouF4UI8G/LZ5sy+gDugqyucYHH8ioaB4+YVKI7UzZVKjN 9cSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=K13775fUSKkksiMmSLXUwvxBImQkMNDg3MVSLkx3vbY=; fh=VE1bJDb2b7aEr9CXfVUE1FmnQumUgnC71nAdtHzhXlg=; b=FWsUYtxIchNpQfJiDLQDo0vxJ/BHLpapqsn2zuBc9wJp0JvoT4ySQOT3A4b+3ZpamK zlSsTjzfb4g9IIK6jJ4w//Rx3FOfGy5lOQPWgBVs3lPEu2yaE9uYLdZqJj5GeBlScNQL 7cll/Rws2Uf332p53GiPZ0msWEMq3gQKlWodBnXtJcEaVh1U/tAhXGsc0czLaGsdA8yU 5RoKYf9rlKqmQPdqR/w4yr/MAxrJFRJWv6vnfGudPR4GIvh02Ughc5gp1e92mwUCT8h0 AJbE/Y8dZn7NSKr4dflKKnqwwDmesnffVe/0EP+8EEbUxpknZQYKs3Dt650KbQiYbloY zU5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mX7iLpEA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id y24-20020a63fa18000000b005787a30e1b7si14195410pgh.369.2023.10.11.07.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 07:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mX7iLpEA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 756C580F4E09; Wed, 11 Oct 2023 07:44:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346706AbjJKOoW (ORCPT + 99 others); Wed, 11 Oct 2023 10:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235050AbjJKOoU (ORCPT ); Wed, 11 Oct 2023 10:44:20 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C0B39D; Wed, 11 Oct 2023 07:44:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DFCEC433C8; Wed, 11 Oct 2023 14:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697035458; bh=+yR23TOJN+Xmz9Lb4zxvgkbSPWcLWaKrsKLjuBEPNzc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mX7iLpEAk08MdoBBF+GxGElmoNo1IzYjHSOr3HjcdmOkdQdpZ0YUWGCpHVLlSBrwN gUpkhOXDWfaUBnJfBEWaUqIJ0CbNEdhPDTlSqYHh9KfYWQRj28Zbq2pA66bEtlDjOc jwa6ACSID0JMi7CzCyAZbdsuSrG9Z9So5TUYe6WlCJkCXncdykvYTL4HTHQHk7sESG VI0MrlvkHormwraSdBvdtUZZCLc0vcsFycICZFqrTG2u6qKdkTaPschD4NphQ2tb11 kaF1jCRXY2uT6TJKU2sq5Wj5q2j8J+PE9VpU1qK2f2PYB5mMLMDY0+e+E7sfLb8aFV mmGRg+kn5BwAQ== Date: Wed, 11 Oct 2023 16:44:14 +0200 From: Alejandro Colomar To: Matthew House Cc: Rik van Riel , linux-man@vger.kernel.org, LKML , kernel-team@meta.com, Eric Biederman Subject: Re: [PATCH] execve.2: execve also returns E2BIG if a string is too long Message-ID: References: <20231010234153.021826b1@imladris.surriel.com> <60b4d916663ea31ae05a958b6dea8aa5bf740d0a.camel@surriel.com> <20231011134437.750422-1-mattlloydhouse@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="w7jaJI5jMx6pA59R" Content-Disposition: inline In-Reply-To: <20231011134437.750422-1-mattlloydhouse@gmail.com> X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 07:44:34 -0700 (PDT) X-Spam-Level: ** --w7jaJI5jMx6pA59R Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Date: Wed, 11 Oct 2023 16:44:14 +0200 From: Alejandro Colomar To: Matthew House Cc: Rik van Riel , linux-man@vger.kernel.org, LKML , kernel-team@meta.com, Eric Biederman Subject: Re: [PATCH] execve.2: execve also returns E2BIG if a string is too long Hi Matthew, On Wed, Oct 11, 2023 at 09:44:29AM -0400, Matthew House wrote: >=20 > To expand on this, there are basically two separate byte limits in > fs/exec.c, one for each individual argv/envp string, and another for all > strings and all pointers to them as a whole. To put the whole thing in > pseudocode, the checks work effectively like this, assuming I haven't made > any errors: >=20 > int argc, envc; > unsigned long bytes, limit; >=20 > /* assume that argv has already been adjusted to add an empty argv[0] */ > argc =3D 0, envc =3D 0, bytes =3D 0; > for (char **a =3D argv; *a !=3D NULL; a++, argc++) { > if (strlen(*a) >=3D MAX_ARG_STRLEN) > return -E2BIG; > bytes +=3D strlen(*a) + 1; > } > for (char **e =3D envp; *e !=3D NULL; e++, envc++) { > if (strlen(*e) >=3D MAX_ARG_STRLEN) > return -E2BIG; > bytes +=3D strlen(*e) + 1; > } >=20 > if (argc > MAX_ARG_STRINGS || envc > MAX_ARG_STRINGS) > return -E2BIG; > bytes +=3D (argc + envc) * sizeof(void *); >=20 > limit =3D max(min(_STK_LIM / 4 * 3, rlim_stack.rlim_cur / 4), ARG_MAX); > if (bytes > limit) > return -E2BIG; >=20 > Thank you, > Matthew House Thanks! This thing would be useful in the commit message. An example program demonstrating it would be even better. Cheers, Alex --=20 --w7jaJI5jMx6pA59R Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmUmtL4ACgkQnowa+77/ 2zJjZxAAqrH8dlVZ8bDdOzaxordiMlVbUvj6UcexmDlle29byjFVQcjgJfmvHh18 6o+bIav3sizGh7ht1vhj7+x0673z6K5d8/QlhrBkqB5Qunx4YgpiaXrpOPOYt3gf trS4lkbxrI9WU0ifT0A7HeVz3KQlNXmtyUlue4N4kH6b92KZnpdDtStnnHSWwuco Uf+R66ir8+lWjhXNI5IpplYiQz3SFAo/9ztjwxHXesVSbpnqwCVD6oP6dL+dc0W1 B7PreIcJmn+HykjX1hk8Y4+FIqWdP0tJZ4Tv7JSeR653grEFsQhc9bzenNg2+kvd ymz8gDoGwpgbEfLIH6G/MLXShU+7PGmcYEYjev1WBGEeZg1BY1DqUUi4VnZAWL4Y 0dno5do4fd0stjNL3vM7JBU6iCZ2reaoV6yMBbs4Wi4vsix19A+o0ds/aIMGF2iA +z/ti1HEsm8lXs6D7U5nusj/F6ZeNMyQWpXV7K1CUX+vzZCMuEXx80vf1FeWNMEI V/bOCYPd6AjQaQ/Ox4HBzi5gnATNvPhiLCkQnkKwZTi501sQhIIBU3IbnvT7z8dW F7phHREEszDVQSAckPHsatmQ/LdLNtBpJA9JVlj1YavTlIORlTDmmOIQJtZNlgL6 F4XLvPvDMMFozKjIhBsAcoGI5sWXlhDKW5m1I2jdv+A31pUFDCg= =zFqm -----END PGP SIGNATURE----- --w7jaJI5jMx6pA59R--