mm/heap: memory alignment before executing kasan_register
The unaligned address is used in kasan_register, but the aligned address is used in kasan_unregister. The mismatch between the addr value and mm_heapstart will result in a crash due to the inability to unregister correctly. Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
ed71aa810e
commit
c158ed2c32
|
@ -141,10 +141,6 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
|||
memset(heapstart, MM_INIT_MAGIC, heapsize);
|
||||
#endif
|
||||
|
||||
/* Register to KASan for access check */
|
||||
|
||||
kasan_register(heapstart, &heapsize);
|
||||
|
||||
/* Adjust the provided heap start and size.
|
||||
*
|
||||
* Note: (uintptr_t)node + MM_SIZEOF_ALLOCNODE is what's actually
|
||||
|
@ -154,7 +150,15 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
|||
|
||||
heapbase = MM_ALIGN_UP((uintptr_t)heapstart + 2 * MM_SIZEOF_ALLOCNODE) -
|
||||
2 * MM_SIZEOF_ALLOCNODE;
|
||||
heapend = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize);
|
||||
heapsize = heapsize - (heapbase - (uintptr_t)heapstart);
|
||||
|
||||
/* Register KASan for access rights check. We need to register after
|
||||
* address alignment.
|
||||
*/
|
||||
|
||||
kasan_register((void *)heapbase, &heapsize);
|
||||
|
||||
heapend = MM_ALIGN_DOWN((uintptr_t)heapbase + (uintptr_t)heapsize);
|
||||
heapsize = heapend - heapbase;
|
||||
|
||||
#if defined(CONFIG_FS_PROCFS) && \
|
||||
|
|
Loading…
Reference in New Issue