Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1901753ybt; Mon, 15 Jun 2020 12:23:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcpr/iu6W9gnUHrUfKHDXhoYHCwv6qFJJld6FrYy7QH5XifzPDJHduwnLwD81jbNb0Q4UN X-Received: by 2002:a17:906:cede:: with SMTP id si30mr27986698ejb.315.1592248999578; Mon, 15 Jun 2020 12:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592248999; cv=none; d=google.com; s=arc-20160816; b=Er0Vhsesu7wAbvLm+Y85pUU9wJl+AbYp7T9dqb5IACFJmTPE0kfo4ee3b2bvnNnfSI ziXv5ZgPTjeNINF4ivGHzuCZpJQTIrY/Hq5FgUxJle0h6+6i2SCvmHc17emhcYHfWYdh GhtpbGCJ3oqTZfWbqJpGRXEcP6miCICr7aksUaiRFIxgdCDAJiz0KBYkcNHuwNSjYy3D QGBDN1HPL0SirJBtAKmxq89JwZWFplXxDST3hs9WD1bw1SGSXJaFQcE1yWBK7rMWyKqu lXgvCS3WH1DPKyWZc4zLxz44rVIMaluxgExHeRL0Eef2BW7QRdLWfA/Wf+aLs6hiIAqh Gs4w== 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:date:subject:cc:to:from :dkim-signature; bh=ZZGHsoXTnXgAmRUOcfo4lrl/+NT7PZj7FPHx1htWx6U=; b=kEIPOtRxSgDjt6oE9PraehtLGdr+8Z65wbR3ud7JvNMlm3O6T2HA7D7pydnZBiSVrA TkP2wcUoEEXZv0CSoNIcyi3eQcn3ithMEN3Y973lYJ2fQ4eUPOSIEBEH11RRfRdXL6s7 Nm/ZCZs11KSZytVSbhGOS5+/s/5+0OJsLdGoP2nCuWnXOxS4N7e3oxgeJMJ6yqD4aPh7 tTv9CznyleZbqFD1qtLOJEd8xOgTh8hZWUQrteyNqBcbfKXoYHHFnugxNerUDrue1ip9 kdXaea/VcHXahLDo4Ad5IIL+N4ZlufZPBsMSXCcvJckzRDRPIR2ZCsW/Wq3NCTzX+9L0 dtzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=o2RhlHWQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si9439078edq.571.2020.06.15.12.22.57; Mon, 15 Jun 2020 12:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=o2RhlHWQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730394AbgFONBA (ORCPT + 99 others); Mon, 15 Jun 2020 09:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730365AbgFONAz (ORCPT ); Mon, 15 Jun 2020 09:00:55 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 232CBC05BD43; Mon, 15 Jun 2020 06:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=ZZGHsoXTnXgAmRUOcfo4lrl/+NT7PZj7FPHx1htWx6U=; b=o2RhlHWQ1U73lI4UBKreMeuh1d V96c20aFyOomEbcWIphJ3pyFjo5ItIgAm/KJIp5Sh1J+gPI5HXmI2YG1i19dy0QhOUqa5pA81t8KD 8/u9BQVaEmeq5snWMfRRjHfqH9pEVoWlA2NmGYotUCCMF4BVxoOflkeOJwlSnXr92QyTzmss9vYvp 2FljztR/Rre+glKjpQSOqFsSl+so6GyRD1Gz9+tBqcY5EzihIIRZ/cHIDuBAmZeBeHYYSHNAPg77K 9wpc/KR89+aovx2wkhPYW15B4NlsBqIVk/0t+F3bcJ4qSvUnBH8prQVTmMXJr70LHsZmWncdVjCvE mVSsqGbw==; Received: from 195-192-102-148.dyn.cablelink.at ([195.192.102.148] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jkojF-0007w7-BU; Mon, 15 Jun 2020 13:00:45 +0000 From: Christoph Hellwig To: Al Viro Cc: Arnd Bergmann , Luis Chamberlain , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] exec: split prepare_arg_pages Date: Mon, 15 Jun 2020 15:00:30 +0200 Message-Id: <20200615130032.931285-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200615130032.931285-1-hch@lst.de> References: <20200615130032.931285-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move counting the arguments and enviroment variables out of prepare_arg_pages and rename the rest of the function to check_arg_limit. This prepares for a version of do_execvat that takes kernel pointers. Signed-off-by: Christoph Hellwig --- fs/exec.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 6e4d9d1ffa35fa..696b1e8180d7d8 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -439,20 +439,10 @@ static int count_strings(const char __user *const __user *argv) return i; } -static int prepare_arg_pages(struct linux_binprm *bprm, - const char __user *const __user *argv, - const char __user *const __user *envp) +static int check_arg_limit(struct linux_binprm *bprm) { unsigned long limit, ptr_size; - bprm->argc = count_strings(argv); - if (bprm->argc < 0) - return bprm->argc; - - bprm->envc = count_strings(envp); - if (bprm->envc < 0) - return bprm->envc; - /* * Limit to 1/4 of the max stack size or 3/4 of _STK_LIM * (whichever is smaller) for the argv+env strings. @@ -1890,7 +1880,19 @@ int do_execveat(int fd, struct filename *filename, if (retval) goto out_unmark; - retval = prepare_arg_pages(bprm, argv, envp); + bprm->argc = count_strings(argv); + if (bprm->argc < 0) { + retval = bprm->argc; + goto out; + } + + bprm->envc = count_strings(envp); + if (bprm->envc < 0) { + retval = bprm->envc; + goto out; + } + + retval = check_arg_limit(bprm); if (retval < 0) goto out; -- 2.26.2