The return value of kmalloc() needs to be checked.
To avoid use in execute_location() in case of the failure of alloc.
Fixes: 039a1c42058d ("lkdtm: Relocate code to subdirectory")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
drivers/misc/lkdtm/perms.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index 2dede2ef658f..ef87d9cc2e96 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -138,6 +138,8 @@ void lkdtm_EXEC_STACK(void)
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);
}
@@ -145,6 +147,8 @@ void lkdtm_EXEC_KMALLOC(void)
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.25.1