[PATCH 4/4] KASan: don't allocate memory while printing report

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The logging functions call the pr_* family of functions, which not only
add pretty-colored prefix, but also allocate memory appending to the
log.

While KASAN protects against recursion while printing the log, this can
falsify debugging results, so let's ensure, we only print to stderr and
nothing more.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 lib/kasan/generic.c |  2 --
 lib/kasan/report.c  | 20 ++++++++++----------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/lib/kasan/generic.c b/lib/kasan/generic.c
index 1eccacf2b4b0..3709b8da9aae 100644
--- a/lib/kasan/generic.c
+++ b/lib/kasan/generic.c
@@ -14,8 +14,6 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <common.h>
 
 #include "kasan.h"
diff --git a/lib/kasan/report.c b/lib/kasan/report.c
index 3d8f0c3b5162..f701e5fa2ac9 100644
--- a/lib/kasan/report.c
+++ b/lib/kasan/report.c
@@ -48,9 +48,9 @@ EXPORT_SYMBOL_GPL(kasan_restore_multi_shot);
 
 static void print_error_description(struct kasan_access_info *info)
 {
-	pr_err("BUG: KASAN: %s in %pS\n",
+	eprintf("BUG: KASAN: %s in %pS\n",
 		get_bug_type(info), (void *)info->ip);
-	pr_err("%s of size %zu at addr %px\n",
+	eprintf("%s of size %zu at addr %px\n",
 		info->is_write ? "Write" : "Read", info->access_size,
 		info->access_addr);
 }
@@ -67,12 +67,12 @@ static void start_report(unsigned long *flags)
 	 * Make sure we don't end up in loop.
 	 */
 	kasan_disable_current();
-	pr_err("==================================================================\n");
+	eprintf("==================================================================\n");
 }
 
 static void end_report(unsigned long *flags)
 {
-	pr_err("==================================================================\n");
+	eprintf("==================================================================\n");
 	kasan_enable_current();
 }
 
@@ -86,11 +86,11 @@ static inline bool kernel_or_module_addr(const void *addr)
 static void print_address_description(void *addr, u8 tag)
 {
 	dump_stack();
-	pr_err("\n");
+	eprintf("\n");
 
 	if (kernel_or_module_addr(addr)) {
-		pr_err("The buggy address belongs to the variable:\n");
-		pr_err(" %pS\n", addr);
+		eprintf("The buggy address belongs to the variable:\n");
+		eprintf(" %pS\n", addr);
 	}
 }
 
@@ -118,7 +118,7 @@ static void print_shadow_for_address(const void *addr)
 					SHADOW_BYTES_PER_ROW)
 		- SHADOW_ROWS_AROUND_ADDR * SHADOW_BYTES_PER_ROW;
 
-	pr_err("Memory state around the buggy address:\n");
+	eprintf("Memory state around the buggy address:\n");
 
 	for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) {
 		const void *kaddr = kasan_shadow_to_mem(shadow_row);
@@ -181,11 +181,11 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write,
 	start_report(&flags);
 
 	print_error_description(&info);
-	pr_err("\n");
+	eprintf("\n");
 
 	if (addr_has_shadow(untagged_addr)) {
 		print_address_description(untagged_addr, get_tag(tagged_addr));
-		pr_err("\n");
+		eprintf("\n");
 		print_shadow_for_address(info.first_bad_addr);
 	} else {
 		dump_stack();
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux