diff --git a/include/nuttx/mm/kasan.h b/include/nuttx/mm/kasan.h index 4b1654c53e..9406bf238c 100644 --- a/include/nuttx/mm/kasan.h +++ b/include/nuttx/mm/kasan.h @@ -39,6 +39,7 @@ # 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_reset_tag(addr) addr #else @@ -126,6 +127,22 @@ FAR void *kasan_unpoison(FAR const void *addr, size_t size); void kasan_register(FAR void *addr, FAR size_t *size); +/**************************************************************************** + * Name: kasan_unregister + * + * Description: + * Stop monitoring the memory range + * + * Input Parameters: + * addr - range start address + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void kasan_unregister(FAR void *addr); + /**************************************************************************** * Name: kasan_init_early * diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 513279fae1..cd326ca827 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -274,6 +274,35 @@ void kasan_register(FAR void *addr, FAR size_t *size) *size -= KASAN_REGION_SIZE(*size); } +void kasan_unregister(FAR void *addr) +{ + FAR struct kasan_region_s *prev = NULL; + FAR struct kasan_region_s *region; + irqstate_t flags; + + flags = spin_lock_irqsave(&g_lock); + for (region = g_region; region != NULL; region = region->next) + { + if (region->begin == (uintptr_t)addr) + { + if (region == g_region) + { + g_region = region->next; + } + else + { + prev->next = region->next; + } + + break; + } + + prev = region; + } + + spin_unlock_irqrestore(&g_lock, flags); +} + void kasan_init_early(void) { g_region_init = 0; diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index ef2329dc0d..6852b439ad 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -357,10 +357,17 @@ mm_initialize_pool(FAR const char *name, void mm_uninitialize(FAR struct mm_heap_s *heap) { + int i; + #ifdef CONFIG_MM_HEAP_MEMPOOL mempool_multiple_deinit(heap->mm_mpool); #endif + for (i = 0; i < CONFIG_MM_REGIONS; i++) + { + kasan_unregister(heap->mm_heapstart[i]); + } + #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) # if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) procfs_unregister_meminfo(&heap->mm_procfs); diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index d6241a4c5d..4c60f419bf 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -1416,10 +1416,17 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, void mm_uninitialize(FAR struct mm_heap_s *heap) { + int i; + #ifdef CONFIG_MM_HEAP_MEMPOOL mempool_multiple_deinit(heap->mm_mpool); #endif + for (i = 0; i < CONFIG_MM_REGIONS; i++) + { + kasan_unregister(heap->mm_heapstart[i]); + } + #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) # if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) procfs_unregister_meminfo(&heap->mm_procfs);