x86/kaslr: Fix potential dereference of NULL pointer.
PATCH 1/1 x86/kaslr: Fix potential dereference of NULL pointer.
Pointer val can have NULL value. Then its value is assigned to the pointer p. p is dereferenced by calling strcmp().
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- arch/x86/boot/compressed/kaslr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/kaslr.c +1 -1
@@ -291,7 +291,7 @@ static void handle_mem_options(void) }else if (!strcmp (param,"mem" )) {char *p = val; -if (!strcmp (p,"nopentium" )) +if (!p || !strcmp (p,"nopentium" ))continue ; mem_size =memparse (p, &p);if (mem_size ==0 )
Signature · 1 line
2.25.1
Quoted 4 lines · Daniil Dulov
Pointer val can have NULL value. Then its value is assigned to the pointer p. p is dereferenced by calling
strcmp().Found by Linux Verification Center (linuxtesting.org) with SVACE.
It's true for strcmp from lib/string.c, while may not be so true for strcmp in arch/x86/boot/string.c which I copy at below for reference. Here, boot/compressed/kaslr.c is using the strcmp in arch/x86/boot/string.c. So leaving it as is or fixing it, either looks good to me, I even prefer the former.
int strcmp(const char *str1, const char *str2)
{
const unsigned char *s1 = (const unsigned char *)str1;
const unsigned char *s2 = (const unsigned char *)str2;
int delta = 0;
while (*s1 || *s2) {
delta = *s1 - *s2;
if (delta)
return delta;
s1++;
s2++;
}
return 0;
}Quoted 23 lines
Fixes 4cdba14f84c9 ("x86/KASLR: Handle the memory limit specified by the 'memmap=' and 'mem=' boot options")Signed-off-by Daniil Dulov <[email protected]>--- arch/x86/boot/compressed/kaslr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/boot/compressed/kaslr.c +1
-1@@ -291,7 +291,7 @@ static void handle_mem_options(void) }else if (!strcmp (param,"mem" )) {char *p = val; -if (!strcmp (p,"nopentium" )) +if (!p || !strcmp (p,"nopentium" ))continue ; mem_size =memparse (p, &p);if (mem_size ==0 )Signature · 1 line
2.25.1