From nobody Tue Apr 7 19:02:27 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB485C433FE for ; Wed, 19 Oct 2022 07:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbiJSHkg convert rfc822-to-8bit (ORCPT ); Wed, 19 Oct 2022 03:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbiJSHke (ORCPT ); Wed, 19 Oct 2022 03:40:34 -0400 X-Greylist: delayed 474 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 19 Oct 2022 00:40:33 PDT Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C9F05F133; Wed, 19 Oct 2022 00:40:32 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =3D bprm->rlim_stack.rlim_cur & PAGE_MASK; + + stack_expand =3D min(rlim_stack, stack_size + stack_expand); + #ifdef CONFIG_STACK_GROWSUP - if (stack_size + stack_expand > rlim_stack) - stack_base =3D vma->vm_start + rlim_stack; - else - stack_base =3D vma->vm_end + stack_expand; + stack_base =3D vma->vm_start + stack_expand; #else - if (stack_size + stack_expand > rlim_stack) - stack_base =3D vma->vm_end - rlim_stack; - else - stack_base =3D vma->vm_start - stack_expand; + stack_base =3D vma->vm_end - stack_expand; #endif current->mm->start_stack =3D bprm->p; ret =3D expand_stack(vma, stack_base); --=20 2.37.3 --=20 Rolf Eike Beer, emlix GmbH, https://www.emlix.com Fon +49 551 30664-0, Fax +49 551 30664-11 Gothaer Platz 3, 37083 G=C3=B6ttingen, Germany Sitz der Gesellschaft: G=C3=B6ttingen, Amtsgericht G=C3=B6ttingen HR B 3160 Gesch=C3=A4ftsf=C3=BChrung: Heike Jordan, Dr. Uwe Kracke =E2=80=93 Ust-IdNr= .: DE 205 198 055 emlix - smart embedded open source