Commit 5c9e3e818df for php
commit 5c9e3e818dfa2e901194e0f3617ccc58a1b8082e
Author: Daniel Scherzer <daniel.e.scherzer+phpf@gmail.com>
Date: Mon Sep 28 14:39:00 2026 -0700
Opcache: abort process when `mprotect()` or `VirtualProtect()` calls fail (#23855)
If the protection call fails, the memory is likely going to have the wrong
permissions and result in a later segmentation fault when trying to use it;
replace the `stderr` log messages with `zend_accel_error_noreturn()` calls that
abort the process.
diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c
index d778beb96e5..895e4f0eec9 100644
--- a/ext/opcache/jit/zend_jit.c
+++ b/ext/opcache/jit/zend_jit.c
@@ -3558,7 +3558,7 @@ void zend_jit_unprotect(void)
opts |= PROT_EXEC;
# endif
if (mprotect(dasm_buf, dasm_size, opts) != 0) {
- fprintf(stderr, "mprotect() failed [%d] %s\n", errno, strerror(errno));
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "mprotect() failed [%d] %s\n", errno, strerror(errno));
}
}
#elif defined(_WIN32)
@@ -3572,8 +3572,7 @@ void zend_jit_unprotect(void)
if (!VirtualProtect(dasm_buf, dasm_size, new, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
- fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
- php_win32_error_msg_free(msg);
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "VirtualProtect() failed [%lu] %s\n", err, msg);
}
}
#endif
@@ -3586,7 +3585,7 @@ void zend_jit_protect(void)
#elif defined(HAVE_MPROTECT)
if (!(JIT_G(debug) & (ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_PERF_DUMP))) {
if (mprotect(dasm_buf, dasm_size, PROT_READ | PROT_EXEC) != 0) {
- fprintf(stderr, "mprotect() failed [%d] %s\n", errno, strerror(errno));
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "mprotect() failed [%d] %s\n", errno, strerror(errno));
}
}
#elif defined(_WIN32)
@@ -3596,8 +3595,7 @@ void zend_jit_protect(void)
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READ, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
- fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
- php_win32_error_msg_free(msg);
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "VirtualProtect() failed [%lu] %s\n", err, msg);
}
}
#endif
@@ -3843,11 +3841,11 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
#elif defined(HAVE_MPROTECT)
if (JIT_G(debug) & (ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_PERF_DUMP)) {
if (mprotect(dasm_buf, dasm_size, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) {
- fprintf(stderr, "mprotect() failed [%d] %s\n", errno, strerror(errno));
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "mprotect() failed [%d] %s\n", errno, strerror(errno));
}
} else {
if (mprotect(dasm_buf, dasm_size, PROT_READ | PROT_EXEC) != 0) {
- fprintf(stderr, "mprotect() failed [%d] %s\n", errno, strerror(errno));
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "mprotect() failed [%d] %s\n", errno, strerror(errno));
}
}
#elif defined(_WIN32)
@@ -3857,8 +3855,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READWRITE, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
- fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
- php_win32_error_msg_free(msg);
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "VirtualProtect() failed [%lu] %s\n", err, msg);
}
} else {
DWORD old;
@@ -3866,8 +3863,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READ, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
- fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
- php_win32_error_msg_free(msg);
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "VirtualProtect() failed [%lu] %s\n", err, msg);
}
}
#endif