From 2d8b582ce62118be3de062c4d057746a2eea2fb4 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Tue, 14 May 2024 10:58:25 +0800 Subject: [PATCH] kasan:add kasan_start/stop api to control kasan check Signed-off-by: anjiahao --- include/nuttx/mm/kasan.h | 27 +++++++++++++++++++++++---- mm/kasan/generic.c | 7 ++++++- mm/kasan/sw_tags.c | 7 ++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/nuttx/mm/kasan.h b/include/nuttx/mm/kasan.h index 9406bf238c..d856daebde 100644 --- a/include/nuttx/mm/kasan.h +++ b/include/nuttx/mm/kasan.h @@ -34,14 +34,17 @@ * Pre-processor Definitions ****************************************************************************/ +#define kasan_init_early() kasan_stop() + #ifndef CONFIG_MM_KASAN # define kasan_is_poisoned(addr, size) false # define kasan_poison(addr, size) # define kasan_unpoison(addr, size) addr # define kasan_register(addr, size) # define kasan_unregister(addr) -# define kasan_init_early() +# define kasan_stop() # define kasan_reset_tag(addr) addr +# define kasan_start() #else /**************************************************************************** @@ -144,10 +147,26 @@ void kasan_register(FAR void *addr, FAR size_t *size); void kasan_unregister(FAR void *addr); /**************************************************************************** - * Name: kasan_init_early + * Name: kasan_start * * Description: - * Initialize the kasan early, setup g_region_init variable. + * Let kasan start check. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void kasan_start(void); + +/**************************************************************************** + * Name: kasan_stop + * + * Description: + * Stop kasan check, setup g_region_init variable. * This used for some platfroms clear bss late, and error use kasan before * called kasan_register(). * @@ -159,7 +178,7 @@ void kasan_unregister(FAR void *addr); * ****************************************************************************/ -void kasan_init_early(void); +void kasan_stop(void); /**************************************************************************** * Name: kasan_reset_tag diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index cd326ca827..f79edad850 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -303,7 +303,12 @@ void kasan_unregister(FAR void *addr) spin_unlock_irqrestore(&g_lock, flags); } -void kasan_init_early(void) +void kasan_start(void) +{ + g_region_init = KASAN_INIT_VALUE; +} + +void kasan_stop(void) { g_region_init = 0; } diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index 9bda40aa19..4c1158f48d 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -192,7 +192,12 @@ void kasan_register(FAR void *addr, FAR size_t *size) *size -= KASAN_REGION_SIZE(*size); } -void kasan_init_early(void) +void kasan_start(void) +{ + g_region_init = KASAN_INIT_VALUE; +} + +void kasan_stop(void) { g_region_init = 0; }