From 29eef2ec6431ed5287c40f6aa9d04f74db762e04 Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Tue, 14 Jan 2025 21:09:44 +0800 Subject: [PATCH] mm: mm_malloc_size Switching using kasan_bypass_save Because it will be called in mm_lock and outside mm_unlock, it needs to keep the same state as before closing. Signed-off-by: wangmingrong1 --- arch/arm64/include/memtag.h | 8 ++++---- arch/arm64/src/common/arm64_mte.c | 10 +++++----- mm/mm_heap/mm_malloc_size.c | 12 ++++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/memtag.h b/arch/arm64/include/memtag.h index 189918687ee97..6aea645176baa 100644 --- a/arch/arm64/include/memtag.h +++ b/arch/arm64/include/memtag.h @@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass); /* Set memory tags for a given memory range */ -void up_memtag_set_tag(const void *addr, size_t size); +void up_memtag_set_tag(FAR const void *addr, size_t size); /* Get a random label based on the address through the mte register */ -uint8_t up_memtag_get_random_tag(const void *addr); +uint8_t up_memtag_get_random_tag(FAR const void *addr); /* Get the address without label */ -FAR void *up_memtag_get_untagged_addr(const void *addr); +FAR void *up_memtag_get_untagged_addr(FAR const void *addr); /* Get the address with label */ -FAR void *up_memtag_get_tagged_addr(const void *addr, uint8_t tag); +FAR void *up_memtag_get_tagged_addr(FAR const void *addr, uint8_t tag); #endif /* ___ARCH_ARM64_INCLUDE_MEMTAG_H */ diff --git a/arch/arm64/src/common/arm64_mte.c b/arch/arm64/src/common/arm64_mte.c index 7432adad1bc0f..840f04ed56563 100644 --- a/arch/arm64/src/common/arm64_mte.c +++ b/arch/arm64/src/common/arm64_mte.c @@ -59,7 +59,7 @@ static int mte_is_support(void) return supported != 0; } -static inline uint8_t mte_get_ptr_tag(const void *ptr) +static inline uint8_t mte_get_ptr_tag(FAR const void *ptr) { return 0xf0 | (uint8_t)(((uint64_t)(ptr)) >> MTE_TAG_SHIFT); } @@ -68,20 +68,20 @@ static inline uint8_t mte_get_ptr_tag(const void *ptr) * Public Functions ****************************************************************************/ -uint8_t up_memtag_get_random_tag(const void *addr) +uint8_t up_memtag_get_random_tag(FAR const void *addr) { asm("irg %0, %0" : "=r" (addr)); return mte_get_ptr_tag(addr); } -FAR void *up_memtag_get_untagged_addr(const void *addr) +FAR void *up_memtag_get_untagged_addr(FAR const void *addr) { return (FAR void *) (((uint64_t)(addr)) & ~((uint64_t)0xff << MTE_TAG_SHIFT)); } -FAR void *up_memtag_get_tagged_addr(const void *addr, uint8_t tag) +FAR void *up_memtag_get_tagged_addr(FAR const void *addr, uint8_t tag) { return (FAR void *) (((uint64_t)(addr)) | ((uint64_t)tag << MTE_TAG_SHIFT)); @@ -116,7 +116,7 @@ void up_memtag_bypass(bool bypass) /* Set memory tags for a given memory range */ -void up_memtag_set_tag(const void *addr, size_t size) +void up_memtag_set_tag(FAR const void *addr, size_t size) { size_t i; diff --git a/mm/mm_heap/mm_malloc_size.c b/mm/mm_heap/mm_malloc_size.c index bb8ed7dcf510f..0c463b3b99733 100644 --- a/mm/mm_heap/mm_malloc_size.c +++ b/mm/mm_heap/mm_malloc_size.c @@ -29,6 +29,7 @@ #include #include +#include #include #include "mm_heap/mm.h" @@ -40,10 +41,14 @@ size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem) { FAR struct mm_freenode_s *node; + size_t size; + bool mte; + + mte = kasan_bypass_save(); #ifdef CONFIG_MM_HEAP_MEMPOOL if (heap->mm_mpool) { - ssize_t size = mempool_multiple_alloc_size(heap->mm_mpool, mem); + size = mempool_multiple_alloc_size(heap->mm_mpool, mem); if (size >= 0) { return size; @@ -66,5 +71,8 @@ size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem) DEBUGASSERT(MM_NODE_IS_ALLOC(node)); - return MM_SIZEOF_NODE(node) - MM_ALLOCNODE_OVERHEAD; + size = MM_SIZEOF_NODE(node) - MM_ALLOCNODE_OVERHEAD; + + kasan_bypass_restore(mte); + return size; }