public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages
@ 2026-02-02 17:32 Thorsten Blum
  2026-03-01 10:44 ` Borislav Petkov
  0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2026-02-02 17:32 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Changyuan Lyu, Alexander Graf, Andrew Morton,
	Mike Rapoport (Microsoft)
  Cc: Thorsten Blum, linux-kernel

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.

Check the return value of boot_kstrtoul() and warn about invalid values.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/boot/compressed/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 3b0948ad449f..e6c44a0d3640 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -219,7 +219,8 @@ 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 (boot_kstrtoul(p, 0, &max_gb_huge_pages))
+			warn("Failed to parse boot parameter hugepages\n");
 		return;
 	}
 }
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages
  2026-02-02 17:32 [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages Thorsten Blum
@ 2026-03-01 10:44 ` Borislav Petkov
  2026-03-01 12:13   ` Thorsten Blum
  2026-03-01 18:30   ` David Laight
  0 siblings, 2 replies; 5+ messages in thread
From: Borislav Petkov @ 2026-03-01 10:44 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
	Changyuan Lyu, Alexander Graf, Andrew Morton,
	Mike Rapoport (Microsoft), linux-kernel

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?

> Check the return value of boot_kstrtoul() and warn about invalid values.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/x86/boot/compressed/kaslr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index 3b0948ad449f..e6c44a0d3640 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -219,7 +219,8 @@ 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 (boot_kstrtoul(p, 0, &max_gb_huge_pages))
> +			warn("Failed to parse boot parameter hugepages\n");

Make that

	warn("Failed to parse hugepages= boot parameter\n");

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages
  2026-03-01 10:44 ` Borislav Petkov
@ 2026-03-01 12:13   ` Thorsten Blum
  2026-03-01 18:30   ` David Laight
  1 sibling, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-03-01 12:13 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
	Changyuan Lyu, Alexander Graf, Andrew Morton,
	Mike Rapoport (Microsoft), linux-kernel

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;
 	}
 }


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages
  2026-03-01 10:44 ` Borislav Petkov
  2026-03-01 12:13   ` Thorsten Blum
@ 2026-03-01 18:30   ` David Laight
  2026-03-02 11:12     ` Thorsten Blum
  1 sibling, 1 reply; 5+ messages in thread
From: David Laight @ 2026-03-01 18:30 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thorsten Blum, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
	H. Peter Anvin, Changyuan Lyu, Alexander Graf, Andrew Morton,
	Mike Rapoport (Microsoft), linux-kernel

On Sun, 1 Mar 2026 11:44:54 +0100
Borislav Petkov <bp@alien8.de> 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?
> 
> > Check the return value of boot_kstrtoul() and warn about invalid values.
> > 
> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > ---
> >  arch/x86/boot/compressed/kaslr.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> > index 3b0948ad449f..e6c44a0d3640 100644
> > --- a/arch/x86/boot/compressed/kaslr.c
> > +++ b/arch/x86/boot/compressed/kaslr.c
> > @@ -219,7 +219,8 @@ 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 (boot_kstrtoul(p, 0, &max_gb_huge_pages))
> > +			warn("Failed to parse boot parameter hugepages\n");  
> 
> Make that
> 
> 	warn("Failed to parse hugepages= boot parameter\n");
> 

I'd suggest including the 'val' that failed to parse.

	David

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages
  2026-03-01 18:30   ` David Laight
@ 2026-03-02 11:12     ` Thorsten Blum
  0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-03-02 11:12 UTC (permalink / raw)
  To: David Laight
  Cc: Borislav Petkov, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
	H. Peter Anvin, Changyuan Lyu, Alexander Graf, Andrew Morton,
	Mike Rapoport (Microsoft), linux-kernel

On 1. Mar 2026, at 19:30, David Laight wrote:
> On Sun, 1 Mar 2026 11:44:54 +0100 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?
>> 
>>> Check the return value of boot_kstrtoul() and warn about invalid values.
>>> 
>>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>>> ---
>>> arch/x86/boot/compressed/kaslr.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>> [...]
>> 
>> Make that
>> 
>> warn("Failed to parse hugepages= boot parameter\n");
> 
> I'd suggest including the 'val' that failed to parse.

warn() isn't variadic and cannot print format arguments. We could add
another helper (e.g., warn_param()) or use error_putstr() manually, but
I'm not sure it's worth it for this case. Any other thoughts on this?

Thanks,
Thorsten


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-02 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 17:32 [PATCH RESEND] x86/boot: Replace simple_strtoull in parse_gb_huge_pages Thorsten Blum
2026-03-01 10:44 ` Borislav Petkov
2026-03-01 12:13   ` Thorsten Blum
2026-03-01 18:30   ` David Laight
2026-03-02 11:12     ` Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox