fortify: Increase pointer assignment check

Message ID 20230217183740.3039-1-zeming@nfschina.com
State New
Headers
Series fortify: Increase pointer assignment check |

Commit Message

Li zeming Feb. 17, 2023, 6:37 p.m. UTC
  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 <zeming@nfschina.com>
---
 drivers/misc/lkdtm/fortify.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

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;