Skip to contentSkip to conversation

lkdtm/heap: Check possible NULL pointer returned by vzalloc()

PATCH In review Ren Yu 2 participants 2 messages Jul 25, 2022

Subsystems (2)
lore
Share & tools
lore

Ren Yu

author
#0 lore raw

PATCH 3/3 lkdtm/heap: Check possible NULL pointer returned by vzalloc()

As the possible alloc failure of the vzalloc(),the
return pointer could be NULL.therefore it should be better to check it.

---
 drivers/misc/lkdtm/heap.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/lkdtm/heap.c +4 -0
index 62516078a619..399cdbbfd5b7 100644
@@ -33,9 +33,13 @@ static void lkdtm_VMALLOC_LINEAR_OVERFLOW(void)
 	one = vzalloc(PAGE_SIZE);
 	two = vzalloc(PAGE_SIZE);
 
+	if (!one || !two)
+		goto free_kernel;
+
 	pr_info("Attempting vmalloc linear overflow ...\n");
 	memset(one, 0xAA, PAGE_SIZE + __offset);
 
+free_kernel:
 	vfree(two);
 	vfree(one);
 }
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 2 lines · Ren Yu

As the possible alloc failure of the vzalloc(),the
return pointer could be NULL.therefore it should be better to check it.

Odd punctuation and wrapping :(

greg k-h