From aa0aecbd80a2ce69ee33ced41b7677f8521acd43 Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Sat, 11 Jan 2025 11:40:42 +0800 Subject: [PATCH] mempool: addbacktrace should be before kasan_unpoison If thread 1 is executing kasan_unpoison but a scheduling occurs and the block is trampled upon, the displayed backtracking may still be from the previously allocated backtracking Signed-off-by: wangmingrong1 --- mm/mempool/mempool.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 624ce291cb..89b3f80e24 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -397,16 +397,17 @@ retry: pool->nalloc++; spin_unlock_irqrestore(&pool->lock, flags); - blk = kasan_unpoison(blk, pool->blocksize); -#ifdef CONFIG_MM_FILL_ALLOCATIONS - memset(blk, MM_ALLOC_MAGIC, pool->blocksize); -#endif #if CONFIG_MM_BACKTRACE >= 0 mempool_add_backtrace(pool, (FAR struct mempool_backtrace_s *) ((FAR char *)blk + pool->blocksize)); #endif + blk = kasan_unpoison(blk, pool->blocksize); +#ifdef CONFIG_MM_FILL_ALLOCATIONS + memset(blk, MM_ALLOC_MAGIC, pool->blocksize); +#endif + return blk; }