mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/5] KASan: report: print shadow memory state to stderr
Date: Wed, 31 Jul 2024 09:14:13 +0200	[thread overview]
Message-ID: <20240731071416.2558182-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240731071416.2558182-1-a.fatoum@pengutronix.de>

The hexdump is currently printed to stdout via printk in
print_hex_dump. KASAN reports are special: They should be printed to
stderr, but they should not be logged as that would involve
reallocation. Therefore instead of calling print_hex_dump, call eprintf
with the %*ph format specifier instead. This allows us to consolidate
the code some more.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/kasan/Kconfig  | 1 +
 lib/kasan/report.c | 8 ++------
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/kasan/Kconfig b/lib/kasan/Kconfig
index e96638304cd8..895a62d88439 100644
--- a/lib/kasan/Kconfig
+++ b/lib/kasan/Kconfig
@@ -11,6 +11,7 @@ config KASAN
 	depends on (HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC)
 	depends on MALLOC_TLSF
 	select CONSTRUCTORS
+	select PRINTF_HEXSTR
 	help
 	  Enables KASAN (KernelAddressSANitizer) - runtime memory debugger,
 	  designed to find out-of-bounds accesses and use-after-free bugs.
diff --git a/lib/kasan/report.c b/lib/kasan/report.c
index a9050546e7a6..b7844e93553c 100644
--- a/lib/kasan/report.c
+++ b/lib/kasan/report.c
@@ -116,20 +116,16 @@ static void print_shadow_for_address(const void *addr)
 
 	for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) {
 		const void *kaddr = kasan_shadow_to_mem(shadow_row);
-		char buffer[4 + (BITS_PER_LONG/8)*2];
 		char shadow_buf[SHADOW_BYTES_PER_ROW];
 
-		snprintf(buffer, sizeof(buffer),
-			(i == 0) ? ">%px: " : " %px: ", kaddr);
 		/*
 		 * We should not pass a shadow pointer to generic
 		 * function, because generic functions may try to
 		 * access kasan mapping for the passed address.
 		 */
 		memcpy(shadow_buf, shadow_row, SHADOW_BYTES_PER_ROW);
-		print_hex_dump(KERN_ERR, buffer,
-			DUMP_PREFIX_NONE, SHADOW_BYTES_PER_ROW, 1,
-			shadow_buf, SHADOW_BYTES_PER_ROW, 0);
+		eprintf("%c%px: %*ph\n", (i == 0) ? '>' : ' ', kaddr,
+			SHADOW_BYTES_PER_ROW, shadow_buf);
 
 		if (row_is_guilty(shadow_row, shadow))
 			eprintf("%*c\n",
-- 
2.39.2




  reply	other threads:[~2024-07-31  7:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  7:14 [PATCH 1/5] console: provide veprintf and eputchar helpers Ahmad Fatoum
2024-07-31  7:14 ` Ahmad Fatoum [this message]
2024-07-31  7:14 ` [PATCH 3/5] ARM: print exception reports to stderr Ahmad Fatoum
2024-07-31  7:14 ` [PATCH 4/5] common: print panic " Ahmad Fatoum
2024-07-31  7:14 ` [PATCH 5/5] RISC-V: stacktrace: output stack traces to standard error Ahmad Fatoum
2024-08-01 11:33 ` [PATCH 1/5] console: provide veprintf and eputchar helpers Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240731071416.2558182-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox