From be86b03794da3f1212a7033f670ef4d954a11bb4 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Tue, 14 May 2024 15:58:32 +0800 Subject: [PATCH] mm/kasan: support Disable Kasan read Panic Signed-off-by: yinshengkai --- mm/Kconfig | 15 ++++++++++++--- mm/kasan/hook.c | 27 ++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index a817a29673..591be2ae8e 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -320,14 +320,23 @@ 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" +config MM_KASAN_DISABLE_READ_PANIC + bool "Disable panic on kasan read error" + default n + ---help--- + This option disable panic on kasan read error. It will print error info + and continue to run. + +config MM_KASAN_DISABLE_WRITE_PANIC + bool "Disable panic on kasan write error" depends on MM_KASAN default n ---help--- - This option disable panic on kasan error. It will print error info + This option disable panic on kasan write error. It will print error info and continue to run. +endif # MM_KASAN + config MM_UBSAN bool "Undefined Behavior Sanitizer" default n diff --git a/mm/kasan/hook.c b/mm/kasan/hook.c index ff782a6152..f8fa9e653a 100644 --- a/mm/kasan/hook.c +++ b/mm/kasan/hook.c @@ -71,6 +71,18 @@ kasan_check_report(addr, size, true, return_address(0)); \ } +#ifdef CONFIG_MM_KASAN_DISABLE_READ_PANIC +# define MM_KASAN_DISABLE_READ_PANIC 1 +#else +# define MM_KASAN_DISABLE_READ_PANIC 0 +#endif + +#ifdef CONFIG_MM_KASAN_DISABLE_WRITE_PANIC +# define MM_KASAN_DISABLE_WRITE_PANIC 1 +#else +# define MM_KASAN_DISABLE_WRITE_PANIC 0 +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -130,11 +142,16 @@ 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 + + if ((is_write && MM_KASAN_DISABLE_WRITE_PANIC) || + (!is_write && MM_KASAN_DISABLE_READ_PANIC)) + { + dump_stack(); + } + else + { + PANIC(); + } leave_critical_section(flags); }