mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH lkdtm] lkdtm: Fix reference preceded by free
@ 2021-10-22  1:28 davidcomponentone
       [not found] ` <CA+E=9osPJSZDqHkd0j-JwL7Tufs3vG3tRtG94+Rsdo4kVgBjAg@mail.gmail.com>
  2021-10-22  3:38 ` He Ying
  0 siblings, 2 replies; 3+ messages in thread
From: davidcomponentone @ 2021-10-22  1:28 UTC (permalink / raw)
  To: keescook; +Cc: arnd, gregkh, linux-kernel, Yang Guang, Zeal Robot

From: Yang Guang <yang.guang5@zte.com.cn>

The coccinelle check report:
./drivers/misc/lkdtm/heap.c:115:7-11:
ERROR: reference preceded by free on line 112
Moving the "kfree(base)" after using place to fix it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
 drivers/misc/lkdtm/heap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/misc/lkdtm/heap.c b/drivers/misc/lkdtm/heap.c
index 8a92f5a800fa..4c6341e7bdca 100644
--- a/drivers/misc/lkdtm/heap.c
+++ b/drivers/misc/lkdtm/heap.c
@@ -109,8 +109,6 @@ void lkdtm_READ_AFTER_FREE(void)
 	base[offset] = *val;
 	pr_info("Value in memory before free: %x\n", base[offset]);
 
-	kfree(base);
-
 	pr_info("Attempting bad read from freed memory\n");
 	saw = base[offset];
 	if (saw != *val) {
@@ -121,6 +119,7 @@ void lkdtm_READ_AFTER_FREE(void)
 		pr_expected_config_param(CONFIG_INIT_ON_FREE_DEFAULT_ON, "init_on_free");
 	}
 
+	kfree(base);
 	kfree(val);
 }
 
-- 
2.30.2


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

end of thread, other threads:[~2021-10-22  3:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-22  1:28 [PATCH lkdtm] lkdtm: Fix reference preceded by free davidcomponentone
     [not found] ` <CA+E=9osPJSZDqHkd0j-JwL7Tufs3vG3tRtG94+Rsdo4kVgBjAg@mail.gmail.com>
2021-10-22  3:36   ` Kees Cook
2021-10-22  3:38 ` He Ying

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®