linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] lkdtm/fortify: Check for NULL return of kmalloc()
@ 2022-03-24  9:44 QintaoShen
  0 siblings, 0 replies; only message in thread
From: QintaoShen @ 2022-03-24  9:44 UTC (permalink / raw)
  To: keescook; +Cc: linux-kernel, QintaoShen

The memory allocation function kmalloc() may return a NULL pointer.
If 'src' is NULL, the strscpy() would copy the string to a NULL address.

Therefore, it is better to check the return value of kmalloc() to avoid the confusion.

Signed-off-by: QintaoShen <unSimple1993@163.com>
---
 drivers/misc/lkdtm/fortify.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c
index ab33bb5..93eeaef 100644
--- a/drivers/misc/lkdtm/fortify.c
+++ b/drivers/misc/lkdtm/fortify.c
@@ -41,6 +41,9 @@ void lkdtm_FORTIFIED_SUBOBJECT(void)
 	char *src;
 
 	src = kmalloc(size, GFP_KERNEL);
+	if (!src)
+		return ;
+
 	strscpy(src, "over ten bytes", size);
 	size = strlen(src) + 1;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-24  9:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  9:44 [PATCH v1] lkdtm/fortify: Check for NULL return of kmalloc() QintaoShen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).