public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc()
@ 2022-07-25  8:11 Ren Yu
  2022-07-25  8:42 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Ren Yu @ 2022-07-25  8:11 UTC (permalink / raw)
  To: keescook, arnd, gregkh, linux-kernel; +Cc: liqiong, yuzhe, Ren Yu

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@nfschina.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-27 21:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-25  8:11 [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc() Ren Yu
2022-07-25  8:42 ` Greg KH
2022-07-25  9:54   ` tury
2022-07-25 12:37     ` Greg KH
2022-07-26  5:43       ` tury
2022-07-27 21:00         ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox