Skip to contentSkip to conversation

lkdtm/fortify: Check for NULL return of kmalloc()

PATCH New QintaoShen 1 participant 1 message Mar 24, 2022

Subsystems (2)
lore
Share & tools
lore

QintaoShen

author
#0 lore raw

PATCH 1/1 lkdtm/fortify: Check for NULL return of kmalloc()

The memory allocation function kmalloc() may return a NULL pointer. If 'src' is NULL, the strscpy() would copy the string to a NULL address.

Therefore, it is better to check the return value of kmalloc() to avoid the confusion.

---
 drivers/misc/lkdtm/fortify.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/misc/lkdtm/fortify.c +3 -0
index ab33bb5..93eeaef 100644
@@ -41,6 +41,9 @@ 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.7.4