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@xxxxxxxxxxxxxx> --- 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