* [PATCH 2/5] KASan: report: print shadow memory state to stderr
2024-07-31 7:14 [PATCH 1/5] console: provide veprintf and eputchar helpers Ahmad Fatoum
@ 2024-07-31 7:14 ` Ahmad Fatoum
2024-07-31 7:14 ` [PATCH 3/5] ARM: print exception reports " Ahmad Fatoum
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-31 7:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] ARM: print exception reports to stderr
2024-07-31 7:14 [PATCH 1/5] console: provide veprintf and eputchar helpers Ahmad Fatoum
2024-07-31 7:14 ` [PATCH 2/5] KASan: report: print shadow memory state to stderr Ahmad Fatoum
@ 2024-07-31 7:14 ` Ahmad Fatoum
2024-07-31 7:14 ` [PATCH 4/5] common: print panic " Ahmad Fatoum
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-31 7:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We already print stack traces to stderr, but exception cause and
register dump is printed to stdout still. Fix that by using eprintf
instead of printf.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/interrupts_32.c | 26 +++++++++++++-------------
arch/arm/cpu/interrupts_64.c | 24 ++++++++++++------------
2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/arch/arm/cpu/interrupts_32.c b/arch/arm/cpu/interrupts_32.c
index 468dcdd30e93..623efb3966f0 100644
--- a/arch/arm/cpu/interrupts_32.c
+++ b/arch/arm/cpu/interrupts_32.c
@@ -42,21 +42,21 @@ void show_regs (struct pt_regs *regs)
flags = condition_codes (regs);
- printf ("pc : [<%08lx>] lr : [<%08lx>]\n"
+ eprintf("pc : [<%08lx>] lr : [<%08lx>]\n"
"sp : %08lx ip : %08lx fp : %08lx\n",
instruction_pointer (regs),
regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
- printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
+ eprintf("r10: %08lx r9 : %08lx r8 : %08lx\n",
regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
- printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
+ eprintf("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
- printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
+ eprintf("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
- printf ("Flags: %c%c%c%c",
+ eprintf("Flags: %c%c%c%c",
flags & PSR_N_BIT ? 'N' : 'n',
flags & PSR_Z_BIT ? 'Z' : 'z',
flags & PSR_C_BIT ? 'C' : 'c', flags & PSR_V_BIT ? 'V' : 'v');
- printf (" IRQs %s FIQs %s Mode %s%s\n",
+ eprintf(" IRQs %s FIQs %s Mode %s%s\n",
interrupts_enabled (regs) ? "on" : "off",
fast_interrupts_enabled (regs) ? "on" : "off",
processor_modes[processor_mode (regs)],
@@ -79,7 +79,7 @@ static void __noreturn do_exception(struct pt_regs *pt_regs)
*/
void do_undefined_instruction (struct pt_regs *pt_regs)
{
- printf ("undefined instruction\n");
+ eprintf("undefined instruction\n");
do_exception(pt_regs);
}
@@ -92,7 +92,7 @@ void do_undefined_instruction (struct pt_regs *pt_regs)
*/
void do_software_interrupt (struct pt_regs *pt_regs)
{
- printf ("software interrupt\n");
+ eprintf("software interrupt\n");
do_exception(pt_regs);
}
@@ -104,7 +104,7 @@ void do_software_interrupt (struct pt_regs *pt_regs)
*/
void do_prefetch_abort (struct pt_regs *pt_regs)
{
- printf ("prefetch abort\n");
+ eprintf("prefetch abort\n");
do_exception(pt_regs);
}
@@ -136,8 +136,8 @@ void do_data_abort (struct pt_regs *pt_regs)
asm volatile ("mrc p15, 0, %0, c6, c0, 0" : "=r" (far) : : "cc");
- printf("unable to handle %s at address 0x%08x\n",
- data_abort_reason(far), far);
+ eprintf("unable to handle %s at address 0x%08x\n",
+ data_abort_reason(far), far);
do_exception(pt_regs);
}
@@ -150,7 +150,7 @@ void do_data_abort (struct pt_regs *pt_regs)
*/
void do_fiq (struct pt_regs *pt_regs)
{
- printf ("fast interrupt request\n");
+ eprintf("fast interrupt request\n");
do_exception(pt_regs);
}
@@ -162,7 +162,7 @@ void do_fiq (struct pt_regs *pt_regs)
*/
void do_irq (struct pt_regs *pt_regs)
{
- printf ("interrupt request\n");
+ eprintf("interrupt request\n");
do_exception(pt_regs);
}
diff --git a/arch/arm/cpu/interrupts_64.c b/arch/arm/cpu/interrupts_64.c
index 6262ba8872db..8933cfeb4288 100644
--- a/arch/arm/cpu/interrupts_64.c
+++ b/arch/arm/cpu/interrupts_64.c
@@ -76,12 +76,12 @@ void show_regs(struct pt_regs *regs)
{
int i;
- printf("elr: %016lx lr : %016lx\n", regs->elr, regs->regs[30]);
+ eprintf("elr: %016lx lr : %016lx\n", regs->elr, regs->regs[30]);
for (i = 0; i < 29; i += 2)
- printf("x%-2d: %016lx x%-2d: %016lx\n",
+ eprintf("x%-2d: %016lx x%-2d: %016lx\n",
i, regs->regs[i], i + 1, regs->regs[i + 1]);
- printf("\n");
+ eprintf("\n");
}
static void __noreturn do_exception(struct pt_regs *pt_regs)
@@ -101,7 +101,7 @@ static void __noreturn do_exception(struct pt_regs *pt_regs)
*/
void do_fiq(struct pt_regs *pt_regs)
{
- printf ("fast interrupt request\n");
+ eprintf("fast interrupt request\n");
do_exception(pt_regs);
}
@@ -113,31 +113,31 @@ void do_fiq(struct pt_regs *pt_regs)
*/
void do_irq(struct pt_regs *pt_regs)
{
- printf ("interrupt request\n");
+ eprintf("interrupt request\n");
do_exception(pt_regs);
}
void do_bad_sync(struct pt_regs *pt_regs)
{
- printf("bad sync\n");
+ eprintf("bad sync\n");
do_exception(pt_regs);
}
void do_bad_irq(struct pt_regs *pt_regs)
{
- printf("bad irq\n");
+ eprintf("bad irq\n");
do_exception(pt_regs);
}
void do_bad_fiq(struct pt_regs *pt_regs)
{
- printf("bad fiq\n");
+ eprintf("bad fiq\n");
do_exception(pt_regs);
}
void do_bad_error(struct pt_regs *pt_regs)
{
- printf("bad error\n");
+ eprintf("bad error\n");
do_exception(pt_regs);
}
@@ -174,15 +174,15 @@ void do_sync(struct pt_regs *pt_regs, unsigned int esr, unsigned long far)
extra = data_abort_reason(far);
}
- printf("%s%s exception (ESR 0x%08x) at 0x%016lx\n", extra ?: "",
- esr_get_class_string(esr), esr, far);
+ eprintf("%s%s exception (ESR 0x%08x) at 0x%016lx\n", extra ?: "",
+ esr_get_class_string(esr), esr, far);
do_exception(pt_regs);
}
void do_error(struct pt_regs *pt_regs)
{
- printf("error exception\n");
+ eprintf("error exception\n");
do_exception(pt_regs);
}
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] RISC-V: stacktrace: output stack traces to standard error
2024-07-31 7:14 [PATCH 1/5] console: provide veprintf and eputchar helpers Ahmad Fatoum
` (2 preceding siblings ...)
2024-07-31 7:14 ` [PATCH 4/5] common: print panic " Ahmad Fatoum
@ 2024-07-31 7:14 ` Ahmad Fatoum
2024-08-01 11:33 ` [PATCH 1/5] console: provide veprintf and eputchar helpers Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-31 7:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
KASAN splats are currently split between standard output and standard
error, which looks ok, when both are enabled on the same consoles, but
is difficult to follow when mapping standard out/err to different
consoles. Let's move all stack trace dumping to standard error. This is
already the case for ARM.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/riscv/lib/stacktrace.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/riscv/lib/stacktrace.c b/arch/riscv/lib/stacktrace.c
index 663938019ee6..b678ad7d5241 100644
--- a/arch/riscv/lib/stacktrace.c
+++ b/arch/riscv/lib/stacktrace.c
@@ -22,9 +22,9 @@ struct stackframe {
static void dump_backtrace_entry(unsigned long where, unsigned long from)
{
#ifdef CONFIG_KALLSYMS
- printf("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
+ eprintf("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
#else
- printf("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
+ eprintf("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
#endif
}
@@ -60,7 +60,7 @@ void unwind_backtrace(const struct pt_regs *regs)
frame.ra = (unsigned long)unwind_backtrace;
}
- printf("Call trace:\n");
+ eprintf("Call trace:\n");
for (;;) {
unsigned long where = frame.ra;
int ret;
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread