From patchwork Sat Jun 27 07:27:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11629273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DE42618 for ; Sat, 27 Jun 2020 07:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75DA0214D8 for ; Sat, 27 Jun 2020 07:28:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XI6CndVI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbgF0H1v (ORCPT ); Sat, 27 Jun 2020 03:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbgF0H1t (ORCPT ); Sat, 27 Jun 2020 03:27:49 -0400 Received: from casper.infradead.org (unknown [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F17DAC03E979; Sat, 27 Jun 2020 00:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=6JtQFSFZNuHNYVW/hbRiOl0cmjzNgKOe7nvuIEAqZOM=; b=XI6CndVIJXMc32UDFraE+/6BDg kgds46nEXHDzwZqAki7Xb/CkKeJmq+gVJ2JvzJ+lQCBP0sos5RAoQ3vxfhbkC+HV9yZJWF5cYmSlt yJzPIZc1/FtkoJpBFgLIg6cR0UZEiIYy/d3lp4NDmonFbNY45srXYi70rr1817pjw+ECoDyEWFE4i RWKBBRkhhsWXJwaX4Gee6Ibaxv79W68lBh2leHgVD/F2uOHmizhBuO1H84Aq4FfnyBZUyjmrpaLul AfaqHFl5sBzlXCSXZ33BEukRpaDWm9lpNdx9d5FLRiYJSgKkNbGtmyNGWh24+udriGn3MVst9oeaO S4UZ/j6g==; Received: from [2001:4bb8:184:76e3:595:ba65:ae56:65a6] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jp5FG-0006XG-3J; Sat, 27 Jun 2020 07:27:27 +0000 From: Christoph Hellwig To: Al Viro Cc: Arnd Bergmann , Brian Gerst , 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/5] exec: split prepare_arg_pages Date: Sat, 27 Jun 2020 09:27:03 +0200 Message-Id: <20200627072704.2447163-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200627072704.2447163-1-hch@lst.de> References: <20200627072704.2447163-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@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 a5d91f8b1341d5..34781db6bf6889 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -435,20 +435,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. @@ -1886,7 +1876,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;