Fix MSan false-positive in zend_max_execution_timer#15408
Fix MSan false-positive in zend_max_execution_timer#15408zeriyoshi merged 3 commits intophp:PHP-8.2from
Conversation
ab0af58 to
4369885
Compare
|
I believe that it's a false positive. The issue seems to be that MSAN does not intercept the Adding --- a/Zend/zend_max_execution_timer.c
+++ b/Zend/zend_max_execution_timer.c
@@ -24,6 +24,10 @@
#include <sys/syscall.h>
#include <sys/types.h>
+#if __has_feature(memory_sanitizer)
+# include <sanitizer/msan_interface.h>
+#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"); |
|
@arnaud-lb It seems that this issue doesn't occur with the version of clang currently used with PHP (Ubuntu 22.04 / clang14). However, it does appear to happen on Ubuntu 24.04 / clang18. Should we include a workaround? |
|
No problem :) Yes, I think we should include a workaround similar to the one above |
|
I see some errors occurring now, see https://app.circleci.com/pipelines/github/php/php-src/8842/workflows/8cdabb98-f0cb-4864-a572-878798126d82/jobs/8745 and https://github.com/php/php-src/actions/runs/10424615881/job/28873779000?pr=15446. Not exactly sure what the problem is. |
|
@cmb69 |
ZEND_MAX_EXECUTION_TIMER is always enabled in PHP 8.3 and later ZTS builds, but accesses uninitialized memory.
Detected at clang-20 with MSan.