Skip to contentSkip to conversation

mm/hugetlb: fix early boot crash on parameters without '=' separator

PATCH Applied Thorsten Blum 2 participants 2 messages Apr 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hugetlb: fix early boot crash on parameters without '=' separator

If hugepages, hugepagesz, or default_hugepagesz are specified on the kernel command line without the '=' separator, early parameter parsing passes NULL to hugetlb_add_param(), which dereferences it in strlen() and can crash the system during early boot.

Reject NULL values in hugetlb_add_param() and return -EINVAL instead.

Fixes 5b47c02967ab ("mm/hugetlb: convert cmdline parameters from setup to early")
---
 mm/hugetlb.c | 3 +++
 1 file changed, 3 insertions(+)
mm/hugetlb.c +3 -0
index 327eaa4074d3..9fda39132d26 100644
@@ -4252,6 +4252,9 @@ static __init int hugetlb_add_param(char *s, int (*setup)(char *))
 	size_t len;
 	char *p;
 
+	if (!s)
+		return -EINVAL;
+
 	if (hugetlb_param_index >= HUGE_MAX_CMDLINE_ARGS)
 		return -EINVAL;
 
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Thorsten Blum

If hugepages, hugepagesz, or default_hugepagesz are specified on the kernel command line without the '=' separator, early parameter parsing passes NULL to hugetlb_add_param(), which dereferences it in strlen() and can crash the system during early boot.

Quoted 5 lines

Reject NULL values in hugetlb_add_param() and return -EINVAL instead.

Fixes 5b47c02967ab ("mm/hugetlb: convert cmdline parameters from setup to early")

Thanks.