From 43698852e514ecd0d02c1243402d0a4b5e719efd Mon Sep 17 00:00:00 2001 From: Go Kudo Date: Thu, 15 Aug 2024 00:40:55 +0900 Subject: [PATCH 1/3] zend_max_execution_timers: fix uninitialized memory access --- Zend/zend.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Zend/zend.c b/Zend/zend.c index fc092b66b9e2a..3783de8ed034f 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -802,6 +802,8 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{ executor_globals->num_errors = 0; executor_globals->errors = NULL; #ifdef ZEND_MAX_EXECUTION_TIMERS + memset(&executor_globals->max_execution_timer_timer, 0, + sizeof(executor_globals->max_execution_timer_timer)); executor_globals->pid = 0; executor_globals->oldact = (struct sigaction){0}; #endif From 03a8c95902ee68702ed9850112777b6cfa8041d4 Mon Sep 17 00:00:00 2001 From: Go Kudo Date: Sat, 17 Aug 2024 02:04:00 +0900 Subject: [PATCH 2/3] Revert "zend_max_execution_timers: fix uninitialized memory access" This reverts commit 43698852e514ecd0d02c1243402d0a4b5e719efd. --- Zend/zend.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Zend/zend.c b/Zend/zend.c index 3783de8ed034f..fc092b66b9e2a 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -802,8 +802,6 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{ executor_globals->num_errors = 0; executor_globals->errors = NULL; #ifdef ZEND_MAX_EXECUTION_TIMERS - memset(&executor_globals->max_execution_timer_timer, 0, - sizeof(executor_globals->max_execution_timer_timer)); executor_globals->pid = 0; executor_globals->oldact = (struct sigaction){0}; #endif From 615b5e29a04799bd0449f42e75a4e92b269ddf96 Mon Sep 17 00:00:00 2001 From: Go Kudo Date: Sat, 17 Aug 2024 02:08:32 +0900 Subject: [PATCH 3/3] zend_max_execution_timer: workaround for msan false-positive --- 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 f9f9740fd8a00..6ab2c0892c038 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");