[php-src] PHP-8.2: Fix GH-13903: ASAN false positive underflow when executing copy()

From: Date: Mon, 08 Apr 2024 19:05:01 +0000
Subject: [php-src] PHP-8.2: Fix GH-13903: ASAN false positive underflow when executing copy()
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-127993@lists.php.net to get a copy of this message
Author: Niels Dossche (nielsdos) Date: 2024-04-08T21:03:42+02:00 Commit: https://github.com/php/php-src/commit/ea0268264bd315d6081cbfe065ea4134cc445a93 Raw diff: https://github.com/php/php-src/commit/ea0268264bd315d6081cbfe065ea4134cc445a93.diff Fix GH-13903: ASAN false positive underflow when executing copy() Closes GH-13917. Changed paths: M NEWS M Zend/zend_fibers.c Diff: diff --git a/NEWS b/NEWS index 47b3f5efb3a58..14dae5531dcde 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ PHP NEWS . Fixed bug GH-13772 (Invalid execute_data->opline pointers in observer fcall handlers when JIT is enabled). (Bob) +- Fibers: + . Fixed bug GH-13903 (ASAN false positive underflow when executing copy()). + (nielsdos) + - FPM: . Fixed bug GH-13563 (Setting bool values via env in FPM config fails). (Jakub Zelenka) diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c index ea91219a43a07..81e6e8832a064 100644 --- a/Zend/zend_fibers.c +++ b/Zend/zend_fibers.c @@ -62,6 +62,7 @@ #endif #ifdef __SANITIZE_ADDRESS__ +# include <sanitizer/asan_interface.h> # include <sanitizer/common_interface_defs.h> #endif @@ -257,6 +258,12 @@ static void zend_fiber_stack_free(zend_fiber_stack *stack) void *pointer = (void *) ((uintptr_t) stack->pointer - ZEND_FIBER_GUARD_PAGES * page_size); +#ifdef __SANITIZE_ADDRESS__ + /* If another mmap happens after unmapping, it may trigger the stale stack red zones + * so we have to unpoison it before unmapping. */ + ASAN_UNPOISON_MEMORY_REGION(pointer, stack->size + ZEND_FIBER_GUARD_PAGES * page_size); +#endif + #ifdef ZEND_WIN32 VirtualFree(pointer, 0, MEM_RELEASE); #else

« previous php.cvs (#127993) next »