mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lkdtm: fortify: Fix potential NULL dereference on kmalloc failure
@ 2025-08-14  6:06 Junjie Cao
  2025-08-25 13:32 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Junjie Cao @ 2025-08-14  6:06 UTC (permalink / raw)
  To: Kees Cook; +Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, Junjie Cao

Add missing NULL pointer checks after kmalloc() calls in
lkdtm_FORTIFY_STR_MEMBER() and lkdtm_FORTIFY_MEM_MEMBER() functions.

Signed-off-by: Junjie Cao <junjie.cao@intel.com>
---
 drivers/misc/lkdtm/fortify.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c
index 015927665678..715598226037 100644
--- a/drivers/misc/lkdtm/fortify.c
+++ b/drivers/misc/lkdtm/fortify.c
@@ -44,6 +44,10 @@ static void lkdtm_FORTIFY_STR_MEMBER(void)
 	char *src;
 
 	src = kmalloc(size, GFP_KERNEL);
+
+	if (src == NULL)
+		return;
+
 	strscpy(src, "over ten bytes", size);
 	size = strlen(src) + 1;
 
@@ -109,6 +113,10 @@ static void lkdtm_FORTIFY_MEM_MEMBER(void)
 	char *src;
 
 	src = kmalloc(size, GFP_KERNEL);
+
+	if (src == NULL)
+		return;
+
 	strscpy(src, "over ten bytes", size);
 	size = strlen(src) + 1;
 
-- 
2.43.0


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

* Re: [PATCH] lkdtm: fortify: Fix potential NULL dereference on kmalloc failure
  2025-08-14  6:06 [PATCH] lkdtm: fortify: Fix potential NULL dereference on kmalloc failure Junjie Cao
@ 2025-08-25 13:32 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2025-08-25 13:32 UTC (permalink / raw)
  To: Junjie Cao; +Cc: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel

On Thu, 14 Aug 2025 14:06:05 +0800, Junjie Cao wrote:
> Add missing NULL pointer checks after kmalloc() calls in
> lkdtm_FORTIFY_STR_MEMBER() and lkdtm_FORTIFY_MEM_MEMBER() functions.
> 
> 

Applied to for-next/hardening, thanks!

[1/1] lkdtm: fortify: Fix potential NULL dereference on kmalloc failure
      https://git.kernel.org/kees/c/a3db14be3e90

Take care,

-- 
Kees Cook


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

end of thread, other threads:[~2025-08-25 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-14  6:06 [PATCH] lkdtm: fortify: Fix potential NULL dereference on kmalloc failure Junjie Cao
2025-08-25 13:32 ` Kees Cook

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

all inboxes | Powered by JetHome®