From e9c9fde3b766fd2c3904523a9be5e982ce56a825 Mon Sep 17 00:00:00 2001 From: ChiaHungDuan Date: Wed, 7 Aug 2024 15:42:11 -0700 Subject: [PATCH] [scudo] Avoid accessing inaccessible pages in unmap() in secondary (#102367) --- compiler-rt/lib/scudo/standalone/secondary.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h index a9a7c2c8ea8618..51721fab52cedf 100644 --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -823,7 +823,11 @@ void MapAllocator::deallocate(const Options &Options, void *Ptr) Cache.store(Options, H->CommitBase, H->CommitSize, reinterpret_cast(H + 1), H->MemMap); } else { - unmap(H->MemMap); + // Note that the `H->MemMap` is stored on the pages managed by itself. Take + // over the ownership before unmap() so that any operation along with + // unmap() won't touch inaccessible pages. + MemMapT MemMap = H->MemMap; + unmap(MemMap); } }