Skip to contentSkip to conversation

lkdtm/fortify: Check possible NULL pointer returned by kmalloc()

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 1/3 lkdtm/fortify: Check possible NULL pointer returned by kmalloc()

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

---
 drivers/misc/lkdtm/fortify.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/misc/lkdtm/fortify.c +3 -0
index 080293fa3c52..5d70c5ef918b 100644
@@ -41,6 +41,9 @@ static void lkdtm_FORTIFIED_SUBOBJECT(void)
 	char *src;
 
 	src = kmalloc(size, GFP_KERNEL);
+	if (!src)
+		return;
+
 	strscpy(src, "over ten bytes", size);
 	size = strlen(src) + 1;
 
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 7 lines · Ren Yu

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

---
 drivers/misc/lkdtm/fortify.c | 3 +++
 1 file changed, 3 insertions(+)

For some reason this patch series is not properly threaded, so our tools can not pick them up automatically. Can you please resend them threaded properly (git send-email can do this for you)?

thanks,

greg k-h