[PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()

From: Ren Yu
Date: Mon Jul 25 2022 - 04:13:05 EST


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

Signed-off-by: Ren Yu <renyu@xxxxxxxxxxxx>
---
drivers/misc/lkdtm/perms.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index b93404d65650..34b43b9ea1f1 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -180,6 +180,9 @@ static void lkdtm_EXEC_STACK(void)
static void lkdtm_EXEC_KMALLOC(void)
{
u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
+ if (!kmalloc_area)
+ return;
+
execute_location(kmalloc_area, CODE_WRITE);
kfree(kmalloc_area);
}
@@ -187,6 +190,9 @@ static void lkdtm_EXEC_KMALLOC(void)
static void lkdtm_EXEC_VMALLOC(void)
{
u32 *vmalloc_area = vmalloc(EXEC_SIZE);
+ if (!vmalloc_area)
+ return;
+
execute_location(vmalloc_area, CODE_WRITE);
vfree(vmalloc_area);
}
--
2.11.0