* [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing
@ 2026-04-09 16:15 Thorsten Blum
2026-04-27 8:17 ` Thorsten Blum
2026-05-04 12:23 ` [tip: x86/cleanups] x86/boot/compressed: Use " tip-bot2 for Thorsten Blum
0 siblings, 2 replies; 6+ messages in thread
From: Thorsten Blum @ 2026-04-09 16:15 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Changyuan Lyu, Andrew Morton, Alexander Graf,
Mike Rapoport (Microsoft)
Cc: Thorsten Blum, linux-kernel
Replace simple_strtoull() with boot_kstrtoul() for parsing the
hugepages= boot parameter.
Unlike simple_strtoull(), boot_kstrtoul() performs strict validation and
returns an error on invalid inputs instead of silently accepting partial
input. Use boot_kstrtoul() to reject and warn about invalid hugepages=
values.
boot_kstrtoul() also converts the input directly to an unsigned long and
avoids implicit casting.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Adjust warning message (Boris)
- The value pointer cannot be NULL after [1] has been applied (Boris)
- Update patch subject and description
- Link to v1: https://lore.kernel.org/lkml/20260202173223.865709-1-thorsten.blum@linux.dev/
[1] https://lore.kernel.org/lkml/20260409105437.108686-4-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..8e4bf5365ac6 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 hugepages= boot parameter\n");
return;
}
}
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing
2026-04-09 16:15 [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing Thorsten Blum
@ 2026-04-27 8:17 ` Thorsten Blum
2026-05-04 10:14 ` Borislav Petkov
2026-05-04 12:23 ` [tip: x86/cleanups] x86/boot/compressed: Use " tip-bot2 for Thorsten Blum
1 sibling, 1 reply; 6+ messages in thread
From: Thorsten Blum @ 2026-04-27 8:17 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Changyuan Lyu, Andrew Morton, Alexander Graf,
Mike Rapoport (Microsoft)
Cc: linux-kernel
On Thu, Apr 09, 2026 at 06:15:59PM +0200, Thorsten Blum wrote:
> Replace simple_strtoull() with boot_kstrtoul() for parsing the
> hugepages= boot parameter.
>
> Unlike simple_strtoull(), boot_kstrtoul() performs strict validation and
> returns an error on invalid inputs instead of silently accepting partial
> input. Use boot_kstrtoul() to reject and warn about invalid hugepages=
> values.
>
> boot_kstrtoul() also converts the input directly to an unsigned long and
> avoids implicit casting.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Changes in v2:
> - Adjust warning message (Boris)
> - The value pointer cannot be NULL after [1] has been applied (Boris)
> - Update patch subject and description
> - Link to v1: https://lore.kernel.org/lkml/20260202173223.865709-1-thorsten.blum@linux.dev/
>
> [1] https://lore.kernel.org/lkml/20260409105437.108686-4-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..8e4bf5365ac6 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 hugepages= boot parameter\n");
> return;
> }
> }
Hi Boris,
Could you give this another look now that [1] is in mainline and 'val'
can no longer be NULL?
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing
2026-04-27 8:17 ` Thorsten Blum
@ 2026-05-04 10:14 ` Borislav Petkov
2026-05-04 10:27 ` Thorsten Blum
0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2026-05-04 10:14 UTC (permalink / raw)
To: Thorsten Blum
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Changyuan Lyu, Andrew Morton, Alexander Graf,
Mike Rapoport (Microsoft), linux-kernel
On Mon, Apr 27, 2026 at 10:17:58AM +0200, Thorsten Blum wrote:
> Could you give this another look now that [1] is in mainline and 'val'
> can no longer be NULL?
I did but looking at arch/x86/boot/string.c - we have kstrtoull() - notice the
two "ll" - there already because we copied it from kernel proper.
So, I'm thinking you should rename it to boot_kstrtoull() in a pre-patch and
then use it in kaslr.c.
Right?
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing
2026-05-04 10:14 ` Borislav Petkov
@ 2026-05-04 10:27 ` Thorsten Blum
2026-05-04 12:14 ` Borislav Petkov
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Blum @ 2026-05-04 10:27 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Changyuan Lyu, Andrew Morton, Alexander Graf,
Mike Rapoport (Microsoft), linux-kernel
On Mon, May 04, 2026 at 12:14:39PM +0200, Borislav Petkov wrote:
> On Mon, Apr 27, 2026 at 10:17:58AM +0200, Thorsten Blum wrote:
> > Could you give this another look now that [1] is in mainline and 'val'
> > can no longer be NULL?
>
> I did but looking at arch/x86/boot/string.c - we have kstrtoull() - notice the
> two "ll" - there already because we copied it from kernel proper.
>
> So, I'm thinking you should rename it to boot_kstrtoull() in a pre-patch and
> then use it in kaslr.c.
>
> Right?
Keep in mind that max_gb_huge_pages is an unsigned long (not ull), so I
think boot_kstrtoul() is the better fit.
The last sentence in my commit message also mentions that
boot_kstrtoul() avoids casting the parsed value from ull to ul.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing
2026-05-04 10:27 ` Thorsten Blum
@ 2026-05-04 12:14 ` Borislav Petkov
0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2026-05-04 12:14 UTC (permalink / raw)
To: Thorsten Blum
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Changyuan Lyu, Andrew Morton, Alexander Graf,
Mike Rapoport (Microsoft), linux-kernel
On Mon, May 04, 2026 at 12:27:50PM +0200, Thorsten Blum wrote:
> Keep in mind that max_gb_huge_pages is an unsigned long (not ull), so I
> think boot_kstrtoul() is the better fit.
>
> The last sentence in my commit message also mentions that
> boot_kstrtoul() avoids casting the parsed value from ull to ul.
Bah, what a mess that code is...
Ok, lemme apply it as is.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip: x86/cleanups] x86/boot/compressed: Use boot_kstrtoul() for hugepages= parsing
2026-04-09 16:15 [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing Thorsten Blum
2026-04-27 8:17 ` Thorsten Blum
@ 2026-05-04 12:23 ` tip-bot2 for Thorsten Blum
1 sibling, 0 replies; 6+ messages in thread
From: tip-bot2 for Thorsten Blum @ 2026-05-04 12:23 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Thorsten Blum, Borislav Petkov (AMD), x86, linux-kernel
The following commit has been merged into the x86/cleanups branch of tip:
Commit-ID: 7b894dac26e56eb1de7a8e198af4b994c5d6da82
Gitweb: https://git.kernel.org/tip/7b894dac26e56eb1de7a8e198af4b994c5d6da82
Author: Thorsten Blum <thorsten.blum@linux.dev>
AuthorDate: Thu, 09 Apr 2026 18:15:59 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 04 May 2026 14:16:11 +02:00
x86/boot/compressed: Use boot_kstrtoul() for hugepages= parsing
Replace simple_strtoull() with boot_kstrtoul() for parsing the hugepages= boot
parameter.
Unlike simple_strtoull(), boot_kstrtoul() performs strict validation and
returns an error on invalid inputs instead of silently accepting partial
input. Use boot_kstrtoul() to reject and warn about invalid hugepages= values.
boot_kstrtoul() also converts the input directly to an unsigned long and
avoids implicit casting as max_gb_huge_pages *is* an unsigned long.
[ bp: Massage commit message. ]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260409161600.152012-2-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 3b0948a..8e4bf53 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 hugepages= boot parameter\n");
return;
}
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-04 12:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 16:15 [PATCH v2] x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing Thorsten Blum
2026-04-27 8:17 ` Thorsten Blum
2026-05-04 10:14 ` Borislav Petkov
2026-05-04 10:27 ` Thorsten Blum
2026-05-04 12:14 ` Borislav Petkov
2026-05-04 12:23 ` [tip: x86/cleanups] x86/boot/compressed: Use " tip-bot2 for Thorsten Blum
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.