Skip to contentSkip to conversation

x86/boot: Check if the input parameter (buffer) of the function is a null pointer

PATCH In review Liam Ni 2 participants 2 messages Dec 6, 2022 – Jan 7, 2023

Subsystems (6)
lore
Share & tools
lore

Liam Ni

author
#0 lore raw

PATCH 1/1 x86/boot: Check if the input parameter (buffer) of the function is a null pointer

If the variable buffer is a null pointer, it may cause the kernel to crash.

---
 arch/x86/boot/cmdline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/cmdline.c +1 -1
index 21d56ae83cdf..d0809f66054c 100644
@@ -39,7 +39,7 @@ int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *b
 		st_bufcpy	/* Copying this to buffer */
 	} state = st_wordstart;
 
-	if (!cmdline_ptr)
+	if (!cmdline_ptr || buffer == NULL)
 		return -1;      /* No command line */
 
 	cptr = cmdline_ptr & 0xf;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 12 lines · Liam Ni

If the variable buffer is a null pointer, it may cause the kernel to crash.

---
 arch/x86/boot/cmdline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/cmdline.c +0 -0
index 21d56ae83cdf..d0809f66054c 100644

arch/x86/boot/cmdline.c int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *b · line 43

Quoted 6 lines
arch/x86/boot/cmdline.c +1 -1
@@ -39,7 +39,7 @@ int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *b
 		st_bufcpy	/* Copying this to buffer */
 	} state = st_wordstart;
 
-	if (!cmdline_ptr)
+	if (!cmdline_ptr || buffer == NULL)
 		return -1;      /* No command line */

Can this ever happen?

Thanks,

Ingo