Skip to contentSkip to conversation

x86/boot/compressed: use boot_kstrtoul() for hugepages= parsing

PATCH Applied Thorsten Blum 3 participants 6 messages Apr 9 – May 4 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
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/[email protected]/

[1] https://lore.kernel.org/lkml/[email protected]/

---
 arch/x86/boot/compressed/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/kaslr.c +2 -1
index 3b0948ad449f..8e4bf5365ac6 100644
@@ -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;
 	}
 }
#1 lore raw
Quoted 29 lines · Thorsten Blum

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.

---
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/[email protected]/

[1] https://lore.kernel.org/lkml/[email protected]/

---
 arch/x86/boot/compressed/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/kaslr.c +0 -0
index 3b0948ad449f..8e4bf5365ac6 100644

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 226

Quoted 9 lines
arch/x86/boot/compressed/kaslr.c +2 -1
@@ -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

maintainer
#2 lore raw
Quoted 2 lines · Thorsten Blum

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.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 2 lines · Thorsten Blum

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

maintainer
#4 lore raw
Quoted 5 lines · Thorsten Blum

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.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
merge bot Applied
#5 lore raw

[tip: x86/cleanups] x86/boot/compressed: Use boot_kstrtoul() for hugepages= parsing

In reply to Thorsten Blum
The following commit has been merged into the x86/cleanups branch of tip:

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 <[email protected]>
AuthorDate:    Thu, 09 Apr 2026 18:15:59 +02:00
Committer:     Borislav Petkov (AMD) <[email protected]>
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. ]

---
 arch/x86/boot/compressed/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/kaslr.c +2 -1
index 3b0948a..8e4bf53 100644
@@ -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;
 	}
 }