[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tencent_5585FF0A904C66C5DC1D8E120AC0F0002507@qq.com>
Date: Fri, 4 Mar 2022 18:30:35 +0800
From: xkernel.wang@...mail.com
To: keescook@...omium.org
Cc: arnd@...db.de, gregkh@...uxfoundation.org,
linux-kernel@...r.kernel.org,
Xiaoke Wang <xkernel.wang@...mail.com>
Subject: [PATCH] lkdtm: add checks for the return of memory allocation functions
From: Xiaoke Wang <xkernel.wang@...mail.com>
kmalloc() and vmalloc() are all memory allocation functions which can
return NULL when some internal errors happen. So it is better to check
the return value of it for better testing the preset purpose.
Signed-off-by: Xiaoke Wang <xkernel.wang@...mail.com>
---
drivers/misc/lkdtm/perms.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index 2dede2e..3eabc6f 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -138,6 +138,10 @@ void lkdtm_EXEC_STACK(void)
void lkdtm_EXEC_KMALLOC(void)
{
u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
+ if (!kmalloc_area) {
+ pr_warn("Failed to allocate memory\n");
+ return;
+ }
execute_location(kmalloc_area, CODE_WRITE);
kfree(kmalloc_area);
}
@@ -145,6 +149,10 @@ void lkdtm_EXEC_KMALLOC(void)
void lkdtm_EXEC_VMALLOC(void)
{
u32 *vmalloc_area = vmalloc(EXEC_SIZE);
+ if (!vmalloc_area) {
+ pr_warn("Failed to allocate memory\n");
+ return;
+ }
execute_location(vmalloc_area, CODE_WRITE);
vfree(vmalloc_area);
}
--
Powered by blists - more mailing lists