Skip to contentSkip to conversation

lkdtm: Fix reference preceded by free

PATCH In review [email protected] 3 participants 3 messages Oct 22, 2021 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 8a92f5a800fa..4c6341e7bdca 100644
@@ -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

#2 lore raw
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.

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
#3 lore raw
In reply to [email protected]
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
---
  drivers/misc/lkdtm/heap.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/lkdtm/heap.c +1 -2
index 8a92f5a800fa..4c6341e7bdca 100644
@@ -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);
  }