mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
kasan: Add configurable kasan initialization variable location
This can avoid crashes caused by uninitialized accesses to initialized variables in non-chip memory. Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
8f541d2ef2
commit
6ac72fa7f1
@@ -25,6 +25,12 @@ if(CONFIG_MM_KASAN)
|
||||
list(APPEND FLAGS ${NO_LTO})
|
||||
list(APPEND FLAGS -fno-builtin)
|
||||
list(APPEND FLAGS -fno-sanitize=kernel-address)
|
||||
|
||||
if(NOT "${CONFIG_MM_KASAN_MARK_LOCATION}" STREQUAL "")
|
||||
target_compile_definitions(
|
||||
mm PRIVATE -DMM_KASAN_MARK_LOCATION="${CONFIG_MM_KASAN_MARK_LOCATION}")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
target_sources(mm PRIVATE ${SRCS})
|
||||
|
||||
@@ -57,6 +57,13 @@ config MM_KASAN_INSTRUMENT_ALL
|
||||
to check. Enabling this option will get image size increased
|
||||
and performance decreased significantly.
|
||||
|
||||
config MM_KASAN_MARK_LOCATION
|
||||
string "Kasan's mark storage location"
|
||||
---help---
|
||||
The section where KASan mark is located. It can prevent
|
||||
variables located in non-chip memory, and crashes
|
||||
caused by instrumentation access
|
||||
|
||||
if MM_KASAN_INSTRUMENT
|
||||
|
||||
config MM_KASAN_REGIONS
|
||||
|
||||
@@ -28,6 +28,10 @@ ifeq ($(CONFIG_MM_KASAN),y)
|
||||
CFLAGS += -fno-sanitize=kernel-address
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_MM_KASAN_MARK_LOCATION),"")
|
||||
CFLAGS += ${DEFINE_PREFIX}MM_KASAN_MARK_LOCATION=CONFIG_MM_KASAN_MARK_LOCATION
|
||||
endif
|
||||
|
||||
# Add the core heap directory to the build
|
||||
|
||||
DEPPATH += --dep-path kasan
|
||||
|
||||
@@ -120,7 +120,11 @@ static struct kasan_watchpoint_s g_watchpoint[MM_KASAN_WATCHPOINT];
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MM_KASAN
|
||||
# ifdef MM_KASAN_MARK_LOCATION
|
||||
static uint32_t g_region_init locate_data(MM_KASAN_MARK_LOCATION);
|
||||
# else
|
||||
static uint32_t g_region_init;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user