lkdtm: Fix reference preceded by free
Subsystems (2)
PATCH 1/1 lkdtm: Fix reference preceded by free
From: Yang Guang <[email protected]>
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.
--- drivers/misc/lkdtm/heap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/lkdtm/heap.c +1 -2
@@ -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); }
Signature · 1 line
2.30.2
A message that is not in the archive (sent off-list or not yet received): CA+E=9osPJSZDqHkd0j-JwL7Tufs3vG3tRtG94+Rsdo4kVgBjAg@mail.gmail.com
Quoted 11 lines · David Yang
From: Yang Guang <[email protected]>
Quoted 8 lines
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 <[email protected]>Signed-off-by Yang Guang <[email protected]>Please ignore this patch. Thanks.
Heh, no worries. It's nice to know that the Coccinelle checks are finding broken things, though! :) (It's just that LKDTM is intentionally broken.) ;)
Signature · 1 line
Kees Cook
Quoted 6 lines · 在 2021/10/22 9:28, [email protected] 写道:
From: Yang Guang <[email protected]>
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.
Look at the name of the function "lkdtm_READ_AFTER_FREE". It's meant to
use after free to test something.
Quoted 28 lines
Reported-by Zeal Robot <[email protected]>Signed-off-by Yang Guang <[email protected]>--- drivers/misc/lkdtm/heap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/misc/lkdtm/heap.c +1
-2@@ -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); }