2023-02-16 02:06:30

by Li zeming

[permalink] [raw]
Subject: [PATCH] fortify: Increase pointer assignment check

Increase the check after the src pointer allocates memory. If these two
functions are used, at least increase some robustness.

Signed-off-by: Li zeming <[email protected]>
---
drivers/misc/lkdtm/fortify.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c
index 015927665678..5c32e4e81d37 100644
--- a/drivers/misc/lkdtm/fortify.c
+++ b/drivers/misc/lkdtm/fortify.c
@@ -44,6 +44,9 @@ 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 +112,9 @@ 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.18.2