Commit ab0ecedf0d4 for php
commit ab0ecedf0d4e86e54cb1cd8167d22fd6722e86cc
Author: David Carlier <devnexen@gmail.com>
Date: Thu Dec 3 17:14:42 2026 +0000
ext/opcache: zend_jit_config() disables JIT process-wide on runtime change
Fix GH-25926
A runtime "disable" or invalid value cleared JIT_G(enabled), so the restore
was refused and JIT_G(options) left dangling. Only clear it at startup.
Close GH-26007
diff --git a/NEWS b/NEWS
index 804773c6417..02cd2da67a0 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,11 @@ PHP NEWS
. Fixed stale or missing global error code and message in MessageFormatter
and IntlDateFormatter::formatObject(). (ChrisAbner)
+- Opcache:
+ . Fixed bug GH-25926 (Cross-request UAF read in opcache_get_configuration()
+ via dangling JIT_G(options) after runtime ini_set('opcache.jit')).
+ (David Carlier)
+
- Standard:
. Fixed bug GH-25959 ("consumed" stream filter loses or repeats data).
(Artem Ukrainskiy)
diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c
index 15fe3d74881..73bc8fb48d9 100644
--- a/ext/opcache/jit/zend_jit.c
+++ b/ext/opcache/jit/zend_jit.c
@@ -3554,22 +3554,25 @@ static int zend_jit_parse_config_num(zend_long jit)
if (jit < 0) return FAILURE;
if (jit % 10 == 0 || jit % 10 > 5) return FAILURE;
- JIT_G(opt_level) = jit % 10;
+ uint8_t opt_level = jit % 10;
jit /= 10;
if (jit % 10 > 5 || jit % 10 == 4) return FAILURE;
- JIT_G(trigger) = jit % 10;
+ uint8_t trigger = jit % 10;
jit /= 10;
if (jit % 10 > 2) return FAILURE;
- JIT_G(opt_flags) = jit % 10;
+ uint32_t opt_flags = jit % 10;
jit /= 10;
if (jit % 10 > 1) return FAILURE;
- JIT_G(opt_flags) |= ((jit % 10) ? ZEND_JIT_CPU_AVX : 0);
+ opt_flags |= ((jit % 10) ? ZEND_JIT_CPU_AVX : 0);
if (jit / 10 != 0) return FAILURE;
+ JIT_G(opt_level) = opt_level;
+ JIT_G(trigger) = trigger;
+ JIT_G(opt_flags) = opt_flags;
JIT_G(on) = 1;
return SUCCESS;
@@ -3585,7 +3588,9 @@ int zend_jit_config(zend_string *jit, int stage)
}
if (zend_string_equals_literal_ci(jit, "disable")) {
- JIT_G(enabled) = 0;
+ if (stage == ZEND_INI_STAGE_STARTUP) {
+ JIT_G(enabled) = 0;
+ }
JIT_G(on) = 0;
return SUCCESS;
} else if (ZSTR_LEN(jit) == 0
@@ -3626,8 +3631,10 @@ int zend_jit_config(zend_string *jit, int stage)
failure:
zend_error(E_WARNING, "Invalid \"opcache.jit\" setting. Should be \"disable\", \"on\", \"off\", \"tracing\", \"function\" or 4-digit number");
- JIT_G(enabled) = 0;
- JIT_G(on) = 0;
+ if (stage == ZEND_INI_STAGE_STARTUP) {
+ JIT_G(enabled) = 0;
+ JIT_G(on) = 0;
+ }
return FAILURE;
}
diff --git a/ext/opcache/tests/jit/gh25926.phpt b/ext/opcache/tests/jit/gh25926.phpt
new file mode 100644
index 00000000000..1bf535734e1
--- /dev/null
+++ b/ext/opcache/tests/jit/gh25926.phpt
@@ -0,0 +1,45 @@
+--TEST--
+GH-25926 (Runtime opcache.jit change leaves JIT disabled and options dangling for later requests)
+--EXTENSIONS--
+opcache
+--SKIPIF--
+<?php
+if (ini_get('opcache.jit') === false) die('skip PHP is compiled without JIT');
+?>
+--CONFLICTS--
+server
+--FILE--
+<?php
+include __DIR__ . '/../php_cli_server.inc';
+$ini = getenv('TEST_PHP_EXTRA_ARGS') . ' -d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M';
+$ext = ini_get('extension_dir');
+if (file_exists($ext . DIRECTORY_SEPARATOR . (PHP_OS_FAMILY === 'Windows' ? 'php_opcache.dll' : 'opcache.so'))) {
+ $ini .= ' -d extension_dir=' . $ext . ' -d zend_extension=opcache';
+}
+php_cli_server_start($ini);
+
+$url = 'http://' . PHP_CLI_SERVER_ADDRESS . '/jit/gh25926_server.php';
+foreach (['disable', 'garbage', '1265'] as $value) {
+ echo file_get_contents($url . '?jit=' . $value);
+ echo file_get_contents($url);
+}
+?>
+--EXPECT--
+string(7) "tracing"
+string(7) "tracing"
+bool(true)
+bool(true)
+int(5)
+int(4)
+bool(false)
+string(7) "tracing"
+bool(true)
+bool(true)
+int(5)
+int(4)
+bool(false)
+string(7) "tracing"
+bool(true)
+bool(true)
+int(5)
+int(4)
diff --git a/ext/opcache/tests/jit/gh25926_server.php b/ext/opcache/tests/jit/gh25926_server.php
new file mode 100644
index 00000000000..8c4dc8a1fc5
--- /dev/null
+++ b/ext/opcache/tests/jit/gh25926_server.php
@@ -0,0 +1,13 @@
+<?php
+if (isset($_GET['jit'])) {
+ var_dump(@ini_set('opcache.jit', $_GET['jit']));
+} else {
+ $jit = opcache_get_status(false)['jit'];
+ var_dump(
+ opcache_get_configuration()['directives']['opcache.jit'],
+ $jit['enabled'],
+ $jit['on'],
+ $jit['kind'],
+ $jit['opt_level'],
+ );
+}