All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anshuman Khandual <anshuman.khandual@arm.com>
To: linux-mm@kvack.org
Cc: Anshuman Khandual <anshuman.khandual@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	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	[thread overview]
Message-ID: <20230828052212.748872-1-anshuman.khandual@arm.com> (raw)

Currently kernel command line 'stack_guard_gap=', 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 <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Depends on the following patch.

https://lore.kernel.org/all/20230828035248.678960-1-anshuman.khandual@arm.com/

 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, unsigned long address)
 /* enforced gap between the expanding stack and other mappings. */
 unsigned long stack_guard_gap = DEFAULT_STACK_GUARD_GAP;
 
-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;
 
-	val = simple_strtoul(p, &endptr, 10);
-	if (!*endptr)
-		stack_guard_gap = val << PAGE_SHIFT;
+	if (!str)
+		return 0;
 
-	return 1;
+	val = simple_strtoul(str, &str, 10);
+	if (!*str && val) {
+		stack_guard_gap = val << PAGE_SHIFT;
+		return 1;
+	}
+	return 0;
 }
 __setup("stack_guard_gap=", cmdline_parse_stack_guard_gap);
 
-- 
2.30.2


             reply	other threads:[~2023-08-28  5:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-28  5:22 Anshuman Khandual [this message]
2023-08-29 12:51 ` [PATCH] mm/mmap: Tighten up cmdline_parse_stack_guard_gap() Matthew Wilcox
2023-08-30  3:17   ` Anshuman Khandual
2023-08-30  3:24     ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230828052212.748872-1-anshuman.khandual@arm.com \
    --to=anshuman.khandual@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.