kasan/hook.c: prevent recursive report overflow

Stop the report handler from re-entering KASAN by halting checks when printing.
Reuse the dump_only flag so read/write panic toggles only emit stack traces.
Retain stack dumps for panic-disabled paths without risking another overflow.

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
This commit is contained in:
anpeiyun
2025-11-12 14:42:55 +08:00
committed by Xiang Xiao
parent c9e5b52f33
commit 3c1712c66d
+11 -2
View File
@@ -180,6 +180,16 @@ static void kasan_report(FAR const void *addr, size_t size,
irqstate_t flags;
flags = enter_critical_section();
bool dump_only = (is_write && MM_KASAN_DISABLE_WRITE_PANIC) ||
(!is_write && MM_KASAN_DISABLE_READ_PANIC);
#ifdef CONFIG_MM_KASAN
if (!dump_only)
{
kasan_stop();
}
#endif
_alert("kasan detected a %s access error, address at %p,"
"size is %zu, return address: %p\n",
is_write ? "write" : "read",
@@ -187,8 +197,7 @@ static void kasan_report(FAR const void *addr, size_t size,
kasan_show_memory(addr, size, 80);
if ((is_write && MM_KASAN_DISABLE_WRITE_PANIC) ||
(!is_write && MM_KASAN_DISABLE_READ_PANIC))
if (dump_only)
{
dump_stack();
}