diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index 9984ec6dcb2..c032782c75f 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -311,9 +311,10 @@ static int rptun_init_carveout(FAR struct rptun_priv_s *priv, } memset(&config, 0, sizeof(config)); - config.name = shmname; - config.start = shmbase; - config.size = shmlen; + config.name = shmname; + config.start = shmbase; + config.size = shmlen; + config.nokasan = true; carveout->base = shmbase; carveout->size = shmlen; diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 9fac9e663e6..1daf86c892c 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -195,6 +195,7 @@ struct mm_heap_config_s FAR const char *name; FAR void *start; size_t size; + bool nokasan; }; struct mempool_init_s diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index cff60de8d16..e56e334a3fa 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -270,6 +270,10 @@ struct mm_heap_s #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) struct procfs_meminfo_entry_s mm_procfs; #endif + + /* Kasan is disable or enable for this heap */ + + bool mm_nokasan; }; /* This describes the callback for mm_foreach */ diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index eefee684c09..2df6570df0e 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -156,7 +156,10 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, * address alignment. */ - kasan_register((void *)heapbase, &heapsize); + if (!heap->mm_nokasan) + { + kasan_register((void *)heapbase, &heapsize); + } heapend = MM_ALIGN_DOWN((uintptr_t)heapbase + (uintptr_t)heapsize); heapsize = heapend - heapbase; @@ -266,6 +269,7 @@ mm_initialize_heap(FAR const struct mm_heap_config_s *config) /* Set up global variables */ memset(heap, 0, sizeof(struct mm_heap_s)); + heap->mm_nokasan = config->nokasan; /* Initialize the node array */ @@ -385,7 +389,11 @@ void mm_uninitialize(FAR struct mm_heap_s *heap) for (i = 0; i < CONFIG_MM_REGIONS; i++) { - kasan_unregister(heap->mm_heapstart[i]); + if (!heap->mm_nokasan) + { + kasan_unregister(heap->mm_heapstart[i]); + } + sched_note_heap(NOTE_HEAP_REMOVE, heap, heap->mm_heapstart[i], (uintptr_t)heap->mm_heapend[i] - (uintptr_t)heap->mm_heapstart[i], heap->mm_curused); diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index debadf256db..784ffb5a3e1 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -112,6 +112,10 @@ struct mm_heap_s #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) struct procfs_meminfo_entry_s mm_procfs; #endif + + /* Kasan is disable or enable for this heap */ + + bool mm_nokasan; }; #if CONFIG_MM_BACKTRACE >= 0 @@ -730,7 +734,10 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, /* Register to KASan for access check */ - kasan_register(heapstart, &heapsize); + if (!heap->mm_nokasan) + { + kasan_register(heapstart, &heapsize); + } DEBUGVERIFY(mm_lock(heap)); @@ -1035,6 +1042,7 @@ mm_initialize_heap(FAR const struct mm_heap_config_s *config) } memset(heap, 0, sizeof(struct mm_heap_s)); + heap->mm_nokasan = config->nokasan; /* Allocate and create TLSF context */ @@ -1674,7 +1682,11 @@ void mm_uninitialize(FAR struct mm_heap_s *heap) for (i = 0; i < CONFIG_MM_REGIONS; i++) { - kasan_unregister(heap->mm_heapstart[i]); + if (!heap->mm_nokasan) + { + kasan_unregister(heap->mm_heapstart[i]); + } + sched_note_heap(NOTE_HEAP_REMOVE, heap, heap->mm_heapstart[i], (uintptr_t)heap->mm_heapend[i] - (uintptr_t)heap->mm_heapstart[i], heap->mm_curused);