From ec9cdcd2bc71d3995be3679d2d21f39c2e17b03d Mon Sep 17 00:00:00 2001 From: Go Kudo Date: Sat, 17 Aug 2024 02:54:03 +0900 Subject: [PATCH] Fix MSan false-positive in zend_max_execution_timer (#15408) Explicitly mark memory regions as unpoisoned for zend_max_execution_timer on ZTS, as MemorySanitizer in clang >= 18 causes false positives. --- Zend/zend_max_execution_timer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index f9f9740fd8a..6ab2c0892c0 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -24,6 +24,10 @@ #include #include +#if __has_feature(memory_sanitizer) +# include +#endif + #include "zend.h" #include "zend_globals.h" @@ -47,6 +51,12 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ sev.sigev_signo = SIGRTMIN; sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid); +#if __has_feature(memory_sanitizer) + /* MSan does not intercept timer_create() */ + __msan_unpoison(&EG(max_execution_timer_timer), + sizeof(EG(max_execution_timer_timer))); +#endif + // Measure wall time instead of CPU time as originally planned now that it is possible https://github.com/php/php-src/pull/6504#issuecomment-1370303727 if (timer_create(CLOCK_BOOTTIME, &sev, &EG(max_execution_timer_timer)) != 0) { zend_strerror_noreturn(E_ERROR, errno, "Could not create timer");