mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: Borislav Petkov <bp@alien8.de>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Changyuan Lyu <changyuanl@google.com>,
	Alexander Graf <graf@amazon.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages
Date: Sun, 1 Mar 2026 13:13:01 +0100	[thread overview]
Message-ID: <1360622D-8B92-451B-80E8-7377F81028FB@linux.dev> (raw)
In-Reply-To: <20260301104454.GBaaQYpia9Kcul6bbo@fat_crate.local>

On 1. Mar 2026, at 11:44, Borislav Petkov wrote:
> On Mon, Feb 02, 2026 at 06:32:20PM +0100, Thorsten Blum wrote:
>> Replace simple_strtoull() with the recommended boot_kstrtoul() for
>> parsing the 'hugepages=' boot parameter. Unlike simple_strtoull(), which
>> returns an unsigned long long, boot_kstrtoul() converts the string
>> directly to an unsigned long and avoids implicit casting.
> 
> "The respective kstrtol(), kstrtoll(), kstrtoul(), and kstrtoull() functions
> tend to be the correct replacements, though note that those require the string
> to be NUL or newline terminated."
> 
> Where are we making sure of that?

next_arg() provides NUL-terminated substrings, but 'val' could be NULL
when '=' is missing in the boot parameter, but that would also break
memparse() and simple_strtoull().

Should I fix this for both 'hugepagesz' and 'hugepages' in this patch?
Something like this:

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 3b0948ad449f..b98b574dd937 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -202,9 +202,15 @@ static unsigned long max_gb_huge_pages;
 static void parse_gb_huge_pages(char *param, char *val)
 {
 	static bool gbpage_sz;
-	char *p;
 
 	if (!strcmp(param, "hugepagesz")) {
+		char *p;
+
+		if (!val) {
+			warn("Missing value in hugepagesz= boot parameter\n");
+			return;
+		}
+
 		p = val;
 		if (memparse(p, &p) != PUD_SIZE) {
 			gbpage_sz = false;
@@ -218,8 +224,13 @@ static void parse_gb_huge_pages(char *param, char *val)
 	}
 
 	if (!strcmp(param, "hugepages") && gbpage_sz) {
-		p = val;
-		max_gb_huge_pages = simple_strtoull(p, &p, 0);
+		if (!val) {
+			warn("Missing value in hugepages= boot parameter\n");
+			return;
+		}
+
+		if (boot_kstrtoul(val, 0, &max_gb_huge_pages))
+			warn("Failed to parse hugepages= boot parameter\n");
 		return;
 	}
 }


  reply	other threads:[~2026-03-01 12:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 17:32 Thorsten Blum
2026-03-01 10:44 ` Borislav Petkov
2026-03-01 12:13   ` Thorsten Blum [this message]
2026-03-01 18:30   ` David Laight
2026-03-02 11:12     ` Thorsten Blum

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=1360622D-8B92-451B-80E8-7377F81028FB@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=changyuanl@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=graf@amazon.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rppt@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome