[php-src] PHP-8.6: Opcache: abort process when `mprotect()` or `VirtualProtect()` calls fail (#23855)
| From: | Daniel Scherzer via GitHub | Date: | Mon, 28 Sep 2026 21:39:04 +0000 |
| Subject: | [php-src] PHP-8.6: Opcache: abort process when `mprotect()` or `VirtualProtect()` calls fail (#23855) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141646@lists.php.net to get a copy of this message | ||
Author: Daniel Scherzer (DanielEScherzer)
Committer: GitHub (web-flow)
Pusher: DanielEScherzer
Date: 2026-09-28T14:39:00-07:00
Commit: https://github.com/php/php-src/commit/5c9e3e818dfa2e901194e0f3617ccc58a1b8082e
Raw diff: https://github.com/php/php-src/commit/5c9e3e818dfa2e901194e0f3617ccc58a1b8082e.diff
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.
Changed paths:
M ext/opcache/jit/zend_jit.c
Diff:
diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c
index d778beb96e58..895e4f0eec91 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