From 5d0ffdf44eb9b8d92eee17bf15abebd9d4bf588a Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Sat, 6 Jan 2024 21:03:39 +0800 Subject: [PATCH] mm: add disable kasan panic configuration In some cases we hope to be able to find errors without affecting the running of the program Signed-off-by: yinshengkai --- mm/Kconfig | 8 ++++++++ mm/kasan/kasan.c | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index 42af2c5330..cfb2a5e539 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -301,6 +301,14 @@ config MM_KASAN_GLOBAL KEEP ( *(. data. rel. local.. LASAN0)) }", used to extract data generated by the compiler +config MM_KASAN_DISABLE_PANIC + bool "Disable panic on kasan error" + depends on MM_KASAN + default n + ---help--- + This option disable panic on kasan error. It will print error info + and continue to run. + config MM_UBSAN bool "Undefined Behavior Sanitizer" default n diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c index 566e3edb7e..d29d549275 100644 --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -191,6 +192,9 @@ static void kasan_report(FAR const void *addr, size_t size, FAR void *return_address) { static int recursion; + irqstate_t flags; + + flags = enter_critical_section(); if (++recursion == 1) { @@ -200,10 +204,15 @@ static void kasan_report(FAR const void *addr, size_t size, addr, size, return_address); kasan_show_memory(addr, size, 80); +#ifndef CONFIG_MM_KASAN_DISABLE_PANIC PANIC(); +#else + dump_stack(); +#endif } --recursion; + leave_critical_section(flags); } static bool kasan_is_poisoned(FAR const void *addr, size_t size)