From 0a4e0f6d35471580231f25334a8e2ff80283d0b3 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Tue, 4 Dec 2012 23:30:00 +0000 Subject: [PATCH] Fix a use-after-unmap bug in /proc/self/maps caching. The cached buffer was occasionally deleted in the MemoryMappingLayout destructor. llvm-svn: 169335 --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 58f0ce958c6e..071620ff82c3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -236,7 +236,11 @@ MemoryMappingLayout::MemoryMappingLayout() { } MemoryMappingLayout::~MemoryMappingLayout() { - UnmapOrDie(proc_self_maps_.data, proc_self_maps_.mmaped_size); + // Only unmap the buffer if it is different from the cached one. Otherwise + // it will be unmapped when the cache is refreshed. + if (proc_self_maps_.data != cached_proc_self_maps_.data) { + UnmapOrDie(proc_self_maps_.data, proc_self_maps_.mmaped_size); + } } void MemoryMappingLayout::Reset() {