From 016c3861d770ef18245639cc5a2de75fef6c9fce Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 1 Dec 2023 16:01:40 +0100 Subject: [PATCH] Fix asan false positive for mmap For some reason, mmap regions which are repeatedly munmapped are not correctly unpoisoned. See https://github.com/google/sanitizers/issues/1705. Fixes GH-12756 Closes GH-12848 --- Zend/zend_alloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index caa2a6ad669..d76c4da023e 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -79,6 +79,9 @@ #include #include #include +#ifdef __SANITIZE_ADDRESS__ +# include +#endif #ifndef _WIN32 # include @@ -724,6 +727,9 @@ static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment) if (zend_mm_use_huge_pages) { zend_mm_hugepage(ptr, size); } +#ifdef __SANITIZE_ADDRESS__ + ASAN_UNPOISON_MEMORY_REGION(ptr, size); +#endif return ptr; } else { size_t offset; @@ -763,6 +769,9 @@ static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment) if (zend_mm_use_huge_pages) { zend_mm_hugepage(ptr, size); } +# ifdef __SANITIZE_ADDRESS__ + ASAN_UNPOISON_MEMORY_REGION(ptr, size); +# endif #endif return ptr; }