[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220831065355.2125181-1-jiasheng@iscas.ac.cn>
Date: Wed, 31 Aug 2022 14:53:55 +0800
From: Jiasheng Jiang <jiasheng@...as.ac.cn>
To: keescook@...omium.org, arnd@...db.de, gregkh@...uxfoundation.org
Cc: linux-kernel@...r.kernel.org, Jiasheng Jiang <jiasheng@...as.ac.cn>
Subject: [PATCH] lkdtm: Add checks after calling kmalloc and vmalloc
As the potential failure of the memory allocation,
it should be better to check the return value after
calling kmalloc and vmalloc and skip the execute_location
if fails.
Fixes: cc33c537c12f ("lkdtm: add "EXEC_*" triggers")
Signed-off-by: Jiasheng Jiang <jiasheng@...as.ac.cn>
---
drivers/misc/lkdtm/perms.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index b93404d65650..9ba927d74973 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -180,14 +180,16 @@ static void lkdtm_EXEC_STACK(void)
static void lkdtm_EXEC_KMALLOC(void)
{
u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
- execute_location(kmalloc_area, CODE_WRITE);
+ if (kmalloc_area)
+ execute_location(kmalloc_area, CODE_WRITE);
kfree(kmalloc_area);
}
static void lkdtm_EXEC_VMALLOC(void)
{
u32 *vmalloc_area = vmalloc(EXEC_SIZE);
- execute_location(vmalloc_area, CODE_WRITE);
+ if (vmalloc_area)
+ execute_location(vmalloc_area, CODE_WRITE);
vfree(vmalloc_area);
}
--
2.25.1
Powered by blists - more mailing lists