Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp690245rwi; Wed, 19 Oct 2022 01:24:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+mhcLPl2CTUgQOyI7eIGaK01mhJUCH16oFlAlHXQsly9ijCnvh31wU4Y9rXosSzkKtJMh X-Received: by 2002:a17:907:d08:b0:72f:b107:c07a with SMTP id gn8-20020a1709070d0800b0072fb107c07amr5776466ejc.340.1666167884322; Wed, 19 Oct 2022 01:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666167884; cv=none; d=google.com; s=arc-20160816; b=aJ0GtHLgwZrG1mshznY7Bhgx6TW+HIpVRuFLvrkglbvOneRrQj7Pn7wRMfs4MmcUts SkU7xWNmP741NNpF6p36OONhkCWqsy3kYJpKFCj3u+R2bqFcnaE7/tZmqDrZCxs7npet BGOYrxKIRAxioJpurnsTvdTTRIhQ+K9TMJ+gJb6mhGTB9KVVtD5SaaMqL5qiHAK5jYut uBASQD3UwU+gZBGaGuoc0gC8Ft1oZsabIbn9tRz5vIV6EYQRIzydwKYdPdxXjGnQ8fcg 1ZgGvVwjHuELmCX93MpACVVZm3wdu6+FEMZ5Ttq3FEqKgA6mN8LHNa+QYqg1W1fFm3wZ 4KNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=dIO0sd0sGkD4z1SmNDwkEN3gUc0bUCh5tjIRPGJ/Ips=; b=JdpdFviJiEsKe+c9J2c3syrhL76qpi2gebLK24oGs/Xr3/0OE/xvZVQNhj8RYfDsgh FALHbP7/lJ2OoesrNda/F3uirevfxz26jHNjHZE9SKdzbE5i6Dyeuk8d88tQpnocx3YY U9UuIe+NEBRxXDTTjos+qkHLJ6+SC9S4O+PqQyO0VXZ0DWytCGTBz2uQ9eJj7Cnwd9c6 WTtjKL7URWDiz8MPtgRSm7RfTSXWba/LeeQJsH/cJuts46aWbw/U8Z2hMiXo0Q5mN/Pc K0CFvP1Pg8b/gjIxFHHzENA63puAGZ+D3NUUk64Vn4sS2kFj2QF8GCHN5UQ0+0exqNjC KVdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d21-20020a170906345500b0078d2f0bf546si10698431ejb.186.2022.10.19.01.24.17; Wed, 19 Oct 2022 01:24:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbiJSHkg convert rfc822-to-8bit (ORCPT + 99 others); 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: 8BIT Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 = 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); -- 2.37.3 -- Rolf Eike Beer, emlix GmbH, https://www.emlix.com Fon +49 551 30664-0, Fax +49 551 30664-11 Gothaer Platz 3, 37083 Göttingen, Germany Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160 Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055 emlix - smart embedded open source