From patchwork Wed Oct 19 07:32:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 13011425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23F09C433FE for ; Wed, 19 Oct 2022 07:32:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E2426B0072; Wed, 19 Oct 2022 03:32:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 392946B0073; Wed, 19 Oct 2022 03:32:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 281676B0074; Wed, 19 Oct 2022 03:32:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 19BEE6B0072 for ; Wed, 19 Oct 2022 03:32:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E0418120B10 for ; Wed, 19 Oct 2022 07:32:39 +0000 (UTC) X-FDA: 80036881638.08.E878627 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf26.hostedemail.com (Postfix) with ESMTP id 61AF9140035 for ; Wed, 19 Oct 2022 07:32:38 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 8A3855FB28; Wed, 19 Oct 2022 09:32:36 +0200 (CEST) From: Rolf Eike Beer To: Alexander Viro , Eric Biederman , Kees Cook Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs/exec.c: simplify initial stack size expansion Date: Wed, 19 Oct 2022 09:32:35 +0200 Message-ID: <2017429.gqNitNVd0C@mobilepool36.emlix.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666164758; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=buZDcvWO+atElmwqPIu/HHrzCOQ1xStjjwci/5ELBHQ=; b=BzwpaDEy6CjmLHdwJByFHA9XGMnQdsK8C1Z09e7rD4Lzi+LuGOIKAApgTSu7YWnAUUcPGm LDAyoxZkWEn6Pat2uZWhPp+Vd8DjJERKX/pFsi26OX5vz65wxOx+brJi329ld8UbteVQYe e+2EX71rZ5Yq+xNuks5PMOF10EzT38U= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666164758; a=rsa-sha256; cv=none; b=b8TYn8/k8Cl9VCnXV5f/H85SZbnW7biZyUu9ZhzAW/ikiBsNVQzQfvOIj8jnUlsVQ/nKs1 i4u4labWbS9bQb8nd30v7q2k/J+hcXJHm5395sfF2wd6AUj2ark6VVROdgnyKBGfckzQZl 6TPM5eaopAGojncExTY4DjRODadv/G4= Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com X-Stat-Signature: 6w111xmy3zye58ity13hqac4yff3ck3i X-Rspamd-Queue-Id: 61AF9140035 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1666164758-387485 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: I had a hard time trying to understand completely why it is using vm_end in one side of the expression and vm_start in the other one, and using something in the "if" clause that is not an exact copy of what is used below. The whole point is that the stack_size variable that was used in the "if" clause is the difference between vm_start and vm_end, which is not far away but makes this thing harder to read than it must be. Signed-off-by: Rolf Eike Beer --- fs/exec.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 768843477a49..990891c5d8fe 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -840,16 +840,13 @@ int setup_arg_pages(struct linux_binprm *bprm, * will align it up. */ rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK; + + stack_expand = min(rlim_stack, stack_size + stack_expand); + #ifdef CONFIG_STACK_GROWSUP - if (stack_size + stack_expand > rlim_stack) - stack_base = vma->vm_start + rlim_stack; - else - stack_base = vma->vm_end + stack_expand; + stack_base = vma->vm_start + stack_expand; #else - if (stack_size + stack_expand > rlim_stack) - stack_base = vma->vm_end - rlim_stack; - else - stack_base = vma->vm_start - stack_expand; + stack_base = vma->vm_end - stack_expand; #endif current->mm->start_stack = bprm->p; ret = expand_stack(vma, stack_base);