From nobody Thu Dec 18 00:59:47 2025 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 4AA44C83F11 for ; Mon, 28 Aug 2023 05:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbjH1FWa (ORCPT ); Mon, 28 Aug 2023 01:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbjH1FWV (ORCPT ); Mon, 28 Aug 2023 01:22:21 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A3B40127 for ; Sun, 27 Aug 2023 22:22:18 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 919222F4; Sun, 27 Aug 2023 22:22:57 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.57.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 47D9E3F738; Sun, 27 Aug 2023 22:22:15 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH] mm/mmap: Tighten up cmdline_parse_stack_guard_gap() Date: Mon, 28 Aug 2023 10:52:12 +0530 Message-Id: <20230828052212.748872-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently kernel command line 'stack_guard_gap=3D', which does not provide = an explicit pages gap value, still assigns 0 to 'stack_guard_gap', which would not have been expected. In such cases it should just retain the default gap value (DEFAULT_STACK_GUARD_GAP). Instead let's assert a positive value for input gap pages before proceeding any further. While here, this tightens up cmdline_parse_stack_guard_gap() for other scenarios, where the command line parameter 'stack_guard_gap' is not successfully handled as expected. Cc: Andrew Morton Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Anshuman Khandual --- Depends on the following patch. https://lore.kernel.org/all/20230828035248.678960-1-anshuman.khandual@arm.c= om/ mm/mmap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 8679750333bb..adaa81d95518 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2122,16 +2122,19 @@ int expand_downwards(struct vm_area_struct *vma, un= signed long address) /* enforced gap between the expanding stack and other mappings. */ unsigned long stack_guard_gap =3D DEFAULT_STACK_GUARD_GAP; =20 -static int __init cmdline_parse_stack_guard_gap(char *p) +static int __init cmdline_parse_stack_guard_gap(char *str) { unsigned long val; - char *endptr; =20 - val =3D simple_strtoul(p, &endptr, 10); - if (!*endptr) - stack_guard_gap =3D val << PAGE_SHIFT; + if (!str) + return 0; =20 - return 1; + val =3D simple_strtoul(str, &str, 10); + if (!*str && val) { + stack_guard_gap =3D val << PAGE_SHIFT; + return 1; + } + return 0; } __setup("stack_guard_gap=3D", cmdline_parse_stack_guard_gap); =20 --=20 2.30.2