[php-src] PHP-8.3: Fix GHSA-g3vh-838c-65v7: Zero PS(session_started_filename) early

From: Date: Thu, 19 Nov 2026 15:26:34 +0000
Subject: [php-src] PHP-8.3: Fix GHSA-g3vh-838c-65v7: Zero PS(session_started_filename) early
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143916@lists.php.net to get a copy of this message
Author: Arnaud Le Blanc (arnaud-lb) Committer: Jakub Zelenka (bukka) Date: 2026-11-19T16:09:18+01:00 Commit: https://github.com/php/php-src/commit/e5f75febc8e5e843e298c254be11ba85d5109efe Raw diff: https://github.com/php/php-src/commit/e5f75febc8e5e843e298c254be11ba85d5109efe.diff Fix GHSA-g3vh-838c-65v7: Zero PS(session_started_filename) early Also do not continue after an interrupted RSHUTDOWN() Co-authored-by: Jakub Zelenka <bukka@php.net> Changed paths: A sapi/fpm/tests/ghsa-g3vh-838c-65v7.phpt M Zend/zend_API.c M ext/session/session.c Diff: diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 161ccf017a6a..4230235316e6 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3262,6 +3262,9 @@ ZEND_API void zend_deactivate_modules(void) /* {{{ */ if (module->request_shutdown_func) { zend_try { module->request_shutdown_func(module->type, module->module_number); + } zend_catch { + /* module shutdown is incomplete */ + _exit(1); } zend_end_try(); } } ZEND_HASH_FOREACH_END(); @@ -3272,6 +3275,9 @@ ZEND_API void zend_deactivate_modules(void) /* {{{ */ zend_module_entry *module = *p; zend_try { module->request_shutdown_func(module->type, module->module_number); + } zend_catch { + /* module shutdown is incomplete */ + _exit(1); } zend_end_try(); p++; } diff --git a/ext/session/session.c b/ext/session/session.c index 1b35bf46e7ea..45d533666290 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -119,6 +119,8 @@ static inline void php_rinit_session_globals(void) /* {{{ */ PS(module_number) = my_module_number; PS(in_rfc1867_update) = false; ZVAL_UNDEF(&PS(http_session_vars)); + PS(session_started_filename) = NULL; + PS(session_started_lineno) = 0; } /* }}} */ diff --git a/sapi/fpm/tests/ghsa-g3vh-838c-65v7.phpt b/sapi/fpm/tests/ghsa-g3vh-838c-65v7.phpt new file mode 100644 index 000000000000..cca31023418f --- /dev/null +++ b/sapi/fpm/tests/ghsa-g3vh-838c-65v7.phpt @@ -0,0 +1,94 @@ +--TEST-- +FPM: GHSA-g3vh-838c-65v7 terminates a worker after interrupted session shutdown +--EXTENSIONS-- +session +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php +require_once "tester.inc"; + +$sessionDir = __DIR__ . '/ghsa-g3vh-838c-65v7.sessions'; +mkdir($sessionDir, 0700); + +$cfg = <<<EOT +[global] +error_log = {{FILE:LOG}} +log_level = notice +[unconfined] +listen = {{ADDR:UDS}} +pm = static +pm.max_children = 1 +php_admin_value[session.save_path] = $sessionDir +php_admin_flag[opcache.enable] = off +php_admin_flag[display_errors] = off +php_admin_flag[log_errors] = off +EOT; + +$code = <<<'PHP' +<?php +if ($_SERVER['QUERY_STRING'] !== 'producer') { + echo getmypid(); + return; +} + +class ShutdownStream { + public $context; + private $fp; + + public function stream_open($path, $mode, $options, &$openedPath) { + $this->fp = fopen('/dev/null', 'w'); + return true; + } + + public function stream_write($data) { + return strlen($data); + } + + public function stream_close() { + trigger_error('session shutdown bailout', E_USER_ERROR); + } +} + +stream_wrapper_register('shutdown-test', ShutdownStream::class); +session_id('g3vh' . getmypid()); +session_start(); +$_SESSION['stream'] = fopen('shutdown-test://session', 'w'); +unset($_SESSION); + +// Finish the response before the fatal RSHUTDOWN callback runs. +echo 'producer'; +fastcgi_finish_request(); +PHP; + +$tester = new FPM\Tester($cfg, $code); +$tester->start(extensions: ['session']); +$tester->expectLogStartNotices(); +$pid = (int) $tester->request(address: '{{ADDR:UDS}}')->getBody(); +$tester->request(query: 'producer', address: '{{ADDR:UDS}}')->expectBody('producer'); +$tester->expectLogWarning( + 'child ' . $pid . ' exited with code 1 after \\d+\\.\\d+ seconds from start', + 'unconfined', + timeoutSeconds: 5 +); +$tester->expectLogNotice('child \\d+ started', 'unconfined'); +$replacement = (int) $tester->request(address: '{{ADDR:UDS}}')->getBody(); +var_dump($pid > 0 && $replacement > 0 && $replacement !== $pid); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); +?> +Done +--EXPECT-- +bool(true) +Done +--CLEAN-- +<?php +require_once "tester.inc"; +FPM\Tester::clean(); +$sessionDir = __DIR__ . '/ghsa-g3vh-838c-65v7.sessions'; +foreach (glob($sessionDir . '/sess_*') as $file) { + unlink($file); +} +@rmdir($sessionDir); +?>

« previous php.cvs (#143916) next »