From e07ec7c6351d381fcd7319369ec8a5396388b03a Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 11 Sep 2023 14:56:18 +0200 Subject: KASan: only print to stderr Part of KASan output, like the stack trace, is already printed to stderr, while some others are printed to stdout. Let's print everything to stderr as not to complicate debugging when stdout and stderr go to different consoles. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20230911125619.2782229-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- lib/kasan/report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/kasan/report.c b/lib/kasan/report.c index 79442c00f4..593cced820 100644 --- a/lib/kasan/report.c +++ b/lib/kasan/report.c @@ -132,7 +132,7 @@ static void print_shadow_for_address(const void *addr) shadow_buf, SHADOW_BYTES_PER_ROW, 0); if (row_is_guilty(shadow_row, shadow)) - printf("%*c\n", + eprintf("%*c\n", shadow_pointer_offset(shadow_row, shadow), '^'); -- cgit v1.2.3 From 62231de1751867795b17cac49fd1b9168b025079 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 11 Sep 2023 14:56:19 +0200 Subject: KASan: don't allocate memory while printing report 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 Link: https://lore.barebox.org/20230911125619.2782229-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- lib/kasan/generic.c | 2 -- lib/kasan/report.c | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/kasan/generic.c b/lib/kasan/generic.c index 1eccacf2b4..3709b8da9a 100644 --- a/lib/kasan/generic.c +++ b/lib/kasan/generic.c @@ -14,8 +14,6 @@ * */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include "kasan.h" diff --git a/lib/kasan/report.c b/lib/kasan/report.c index 593cced820..a9050546e7 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); } @@ -61,12 +61,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(); } @@ -80,11 +80,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); } } @@ -112,7 +112,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); @@ -172,11 +172,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(); -- cgit v1.2.3