Commit 36c6d1f500f for php
commit 36c6d1f500f7ec477f6eae0b0f5c46b041d82347
Author: pavimus <pavimus@gmail.com>
Date: Mon Nov 16 17:18:09 2026 +0300
Fix GH-8739: OPcache restart corrupts SHM in threaded SAPIs (#24276)
* Fix OPcache releasing other threads' SHM locks under ZTS
accel_unlock_all() runs at the end of every request and releases the
whole lock file with F_UNLCK (l_start = 0, l_len = 0). fcntl() record
locks are owned by the process, not by the thread, so under ZTS a
thread finishing its request also releases the SHM write lock (byte 0)
held by another thread of the same process inside
zend_shared_alloc_lock(), and the restart lock (byte 2).
With several multi-threaded processes sharing the cache (Apache
mod_php with the event or worker MPM) another process can then take
the write lock while the first one is still writing, and two processes
modify SHM at the same time. Children crash during warm-up even
without any OPcache restart (SIGSEGV in accel_find_interned_string()
and zend_hash_find_bucket()).
Bytes 0 and 2 are always released by the thread that took them
(zend_shared_alloc_unlock(), zend_shared_alloc_safe_unlock(),
accel_restart_leave()), so under ZTS only release the reader lock.
NTS is unchanged.
* Fix GH-8739: OPcache restart corrupts SHM in threaded SAPIs
Readers of the shared memory are tracked with an fcntl() read lock on
byte 1 of the lock file, and a restart only runs when no process holds
it. Record locks belong to the process, so under ZTS this does not see
threads: F_GETLK ignores the locks of the calling process, and the
restart (OOM, hash overflow, opcache_reset()) wipes SHM while other
threads of the same process still execute code from it. With several
multi-threaded processes (Apache event/worker MPM) any thread ending
its request also released the reader lock of the whole process.
Result: crashes ("zend_mm_heap corrupted", SIGSEGV) under FrankenPHP
and Apache mod_php ZTS.
Under ZTS on POSIX (NTS and Windows are unchanged):
- A thread becomes a reader only in RINIT, before the restart
generation is checked, and stays one until post_deactivate. The
threads of a process are counted in a process-local atomic counter;
the process holds the reader lock on byte 1 whenever the counter is
not zero. Only the 0 <-> 1 transitions take a mutex and call fcntl(),
other requests do a single compare-and-swap on enter and on leave.
- Lazy reader locks (accel_activate_add()) fail under ZTS, so a request
that was not admitted in RINIT never starts to use SHM later (e.g.
through the file cache or interned strings).
- A restart takes the mutex, requires a zero counter and a write lock
on byte 1, and holds both until it is finished. Threads of the
process cannot become readers meanwhile, and the kernel neither
grants the write lock while another process holds the reader lock
nor the reader lock while the write lock is held. This replaces the
F_GETLK probe, so there is no window between checking for readers
and starting the restart.
- Threads cannot be killed after opcache.force_restart_timeout: a
warning is logged once per timeout period instead. Other processes
are still killed by kill_all_lockers().
- A thread retired without its request cleanup releases its reference
in the globals destructor.
- Without real atomics (HAVE_NO_ATOMICS) every enter and leave takes
the mutex.
FrankenPHP worker threads stay readers for their whole life, so a
restart waits until the workers are restarted. Not covered: requests
that start while a restart is pending still run preloaded functions,
including their JIT code.
Co-authored-by: Yoan Arnaudov <1738437+nacholibre@users.noreply.github.com>
* Simplify the ZTS reader count, wait for restarts of other processes
- Enter and leave share one function, accel_zts_readers_add(): the
lock-free path changes a positive count that stays positive, the
0 <-> 1 transitions take the mutex and call fcntl().
- A thread that becomes the first reader of its process while another
process restarts the cache now waits for the restart (F_SETLKW)
instead of running its whole request uncached and resetting its PCRE
cache.
- Comments on opcache.force_restart_timeout under ZTS: the restart
waits for running requests of the own process, other processes are
killed with all their threads, as without ZTS.
- Test: opcache_reset() in the CLI server with two workers; the restart
must happen in the next request and the cache must work after it. A
reference that is never released makes it fail.
* Release the ZTS reader reference in accel_deactivate_sub()
- As on Windows, accel_deactivate_sub() releases the thread's reference
(ZCG(counted)) and accel_unlock_all() calls it instead of unlocking
the whole file.
- gh8739.phpt: use two CLI server workers only on Linux and FreeBSD.
Elsewhere the workers have no PDEATHSIG, outlive the server and keep
the test's output open, so run-tests waits forever (macOS CI).
* Reset ZCG(accelerator_enabled) in accel_post_deactivate()
The reference to SHM is released there, but the flag stayed set until the
next RINIT, so code running in between (e.g. the RINIT of an extension
started before OPcache) could still look up the cache without holding it.
diff --git a/NEWS b/NEWS
index b655a47a6f1..95e47d2b34a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,12 +1,20 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-?? ??? ????, PHP 8.4.29
-
-- CLI:
- . Fixed built-in server rejecting long request paths, or paths received in
- several pieces, as malformed. (Ilia Alshanetsky)
+?? ??? ????, PHP 8.4.28
- Core:
+ . Fixed bug GH-24184 (System ID not being reinitialized after an Apache
+ graceful restart, potentially causing incompatible OPcache file cache
+ entries to be reused). (Levi Morrison)
+ . Fixed memory leak when an exception already contains the pending exception
+ in its previous chain. (Edmond)
+ . Fixed bug GH-23979 (Nullsafe operator must not flush delayed oplines of an
+ enclosing function). (ndossche)
+ . Fixed memory manager keeping a block reallocated to exactly the size of
+ the next smaller bin in its larger bin, which efree_size() then freed
+ into the wrong one. (Marc Bennewitz)
+ . Fixed bug GH-24218 (Invalid opcode for count() of a literal array
+ without SCCP). (lazerg)
. Fixed AST printing of interface extends list as implements. (Jorg Sowa)
. Fixed AST printing dropping fully qualified and namespace-relative prefixes
of class names in implements, catch, and trait use lists. (Jorg Sowa)
@@ -26,123 +34,6 @@ PHP NEWS
. Fixed bug GH-25311 (Assertion ret == SUCCESS in array_map()/array_filter()
after delayed out-of-memory). (ndossche)
. Fixed AST export of by-reference property hooks. (Jorg Sowa)
-
-- Curl:
- . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
-
-- DBA:
- . Fixed dba_close() not closing a database opened with dba_popen().
- (Ilia Alshanetsky)
-
-- DOM:
- . Fixed bug GH-25268 (NULL php_libxml_ref_obj dereference in
- dom_objects_store_clone_obj when cloning Dom\Notation). (David Carlier)
- . Fixed bug GH-25306 (Assertion status == LXB_STATUS_OK in dom_parse_selector
- when lexbor allocation fails). (ndossche)
- . Fixed bug GH-25434 (C14NFile() on a Dom\XMLDocument leaves the document
- changed and leaks memory). (lazerg)
-
-- GD:
- . Fixed use-after-free when drawing with a brush or tile image that was
- released after imagesetbrush() or imagesettile(). (lacatoire)
- . Fixed the argument blamed by the imagepolygon(), imageopenpolygon() and
- imagefilledpolygon() too few points error. (lacatoire)
-
-- Filter:
- . Fixed stack overflow in filter_var() and filter_var_array() with deeply
- nested arrays. (Eyüp Can Akman)
-
-- MBString:
- . Fixed stack overflow in mb_check_encoding() and mb_convert_encoding() with
- deeply nested arrays. (Eyüp Can Akman)
-
-- Opcache:
- . Fixed bug GH-24801 (JIT: SIGFPE in ir_fold MUL_OV constant folding).
- (waroad)
- . Fixed bug GH-25165 (Tracing JIT loops forever once opcache.jit_buffer_size
- is exhausted while compiling side traces). (Ilia Alshanetsky)
- . Fixed bug GH-25164 (Function JIT loop calling a user function runs once
- or never terminates). (Ilia Alshanetsky)
- . Fixed memory leak in JIT ASSIGN_DIM when the assignment fails. (Jorg Sowa)
- . Fixed bug GH-16396 (Failed to invoke user error handler during index
- conversion in JIT). (Jorg Sowa)
- . Fixed bug GH-25037 (Function JIT ENTRY live var assertion).
- (Ilia Alshanetsky)
- . Fixed JIT ignoring leading-numeric string offsets in isset(), empty() and
- ??. (Jorg Sowa)
- . Fixed use-after-free in JIT when the error handler releases a string while
- an "Undefined variable" warning is raised for its offset in ?? or nested
- isset()/empty(). (Jorg Sowa)
- . Fixed tracing JIT reading the int result of ++/-- on a reference as a
- double. (ChrisAbner)
- . Fixed bug GH-25359 (Tracing JIT drops reference type of a named by-ref
- argument). (David Carlier)
-
-- PDO_Firebird:
- . Fixed stack buffer overflow with long connection user names, passwords,
- charsets, or roles. (Ilia Alshanetsky)
-
-- PCRE:
- . Fixed \C being allowed in patterns enabling UTF mode with (*UTF) instead
- of the u modifier. (Jorg Sowa)
-
-- SNMP:
- . Fixed use-after-free of the context name set by SNMP::setSecurity().
- (lacatoire)
-
-- SOAP:
- . Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key).
- (lazerg)
- . Fixed bug GH-25094 (NULL dereference in get_doc_function() with missing
- parts). (lazerg)
-
-- Readline:
- . Fixed incorrect handling of non-ASCII pending_input bytes in readline_info(),
- which could cause readline() to return false prematurely. (Weilin Du)
-
-- Reflection:
- . Fix trampoline leak when object construction fails for lazy object.
- (ndossche)
-
-- Session:
- . Fixed session upload progress to respect session.use_only_cookies.
- (jorgsowa)
-
-- Standard:
- . Fixed bug GH-25474 (version_compare() treats large numeric parts as equal
- on 64-bit Windows). (lazerg)
- . Fixed dns_get_record() returning partially built records for malformed
- DNS responses. (Marti2203)
- . Fixed bug GH-25387 (Uploaded files leak in request_parse_body()).
- (Kévin Dunglas)
- . Fixed bug GH-24743 (var_export() ignores exceptions from lazy object
- initialization). (lazerg)
-
-- Streams:
- . Fixed bug GH-22063 (Stream filter chain UAF on self-removal during
- callback). (Ilia Alshanetsky)
- . Fixed leaks and data loss when user filter leaves buckets on input
- brigade. (ndossche, Matthias Goergens, Jakub Zelenka)
- . Fixed bug GH-24175 (Use-after-free when pclose() closes a stream from its
- user filter). (Edmond)
- . Fixed bug GH-15701 (Build failure: incompatible funopen() seeker pointer
- type on 32-bit platforms). (Kamil Tekiela)
-
-19 Nov 2026, PHP 8.4.28
-
-- Core:
- . Fixed bug GH-24184 (System ID not being reinitialized after an Apache
- graceful restart, potentially causing incompatible OPcache file cache
- entries to be reused). (Levi Morrison)
- . Fixed memory leak when an exception already contains the pending exception
- in its previous chain. (Edmond)
- . Fixed bug GH-23979 (Nullsafe operator must not flush delayed oplines of an
- enclosing function). (ndossche)
- . Fixed memory manager keeping a block reallocated to exactly the size of
- the next smaller bin in its larger bin, which efree_size() then freed
- into the wrong one. (Marc Bennewitz)
- . Fixed bug GH-24218 (Invalid opcode for count() of a literal array
- without SCCP). (lazerg)
. Fix throwing behaviour with recursive arrays in VM. (ndossche)
. Fixed skipped catch block when switching fibers during exception unwinding
(Nicolas Grekas)
@@ -177,8 +68,16 @@ PHP NEWS
. Fixed bug GH-24480 (Finally block running a second time when a VM interrupt
throws as the finally block returns to a "return" in its try block).
(C. Scott Ananian)
+ . Fixed GHSA-w8hw-w9fx-j79w, GHSA-6wmf-4rv5-p3rp (Avoid state corruption via
+ bailout). (CVE-2026-109618, CVE-2026-109619) (Arnaud, ilutov, Jakub Zelenka,
+ ndossche, Nicolas Grekas)
+ . Fixed use-after-free when a Fiber callable resolves to $this of the method
+ creating the Fiber ([A::class, 'm'] or "A::m") and that object dies before
+ the Fiber runs. (Edmond Dantes)
- CLI:
+ . Fixed built-in server rejecting long request paths, or paths received in
+ several pieces, as malformed. (Ilia Alshanetsky)
. Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work).
(ndossche, devnexen)
. Fixed bug GH-9670 (List -C and -q in the CLI help). (Juan Versolato Lopes)
@@ -190,6 +89,7 @@ PHP NEWS
resolving an event source with no loaded typelib). (Ilia Alshanetsky)
- Curl:
+ . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
. Fix use-after-free of CURLOPT_STDERR stream on cloned curl handle.
(lacatoire)
. Fix UAF on clone due to callback data pointer mismatch. (ndossche)
@@ -201,14 +101,22 @@ PHP NEWS
in-process module restart). (Lazizbek Ergashev)
- DBA:
+ . Fixed dba_close() not closing a database opened with dba_popen().
+ (Ilia Alshanetsky)
. Fixed bug GH-24641 (ndbm backend never checks dbm_open() return value,
NULL deref on first use after a failed open). (Girgias)
- DOM:
- . Fixed a use-after-free when reflected attribute setters replace an
- attribute whose child still has a live wrapper. (Jakub Zelenka)
. Fixed bug GH-23352 (UAF reading an attribute value node retained across
DOMDocument::adoptNode()). (David Carlier)
+ . Fixed bug GH-25268 (NULL php_libxml_ref_obj dereference in
+ dom_objects_store_clone_obj when cloning Dom\Notation). (David Carlier)
+ . Fixed bug GH-25306 (Assertion status == LXB_STATUS_OK in dom_parse_selector
+ when lexbor allocation fails). (ndossche)
+ . Fixed bug GH-25434 (C14NFile() on a Dom\XMLDocument leaves the document
+ changed and leaks memory). (lazerg)
+ . Fixed a use-after-free when reflected attribute setters replace an
+ attribute whose child still has a live wrapper. (Jakub Zelenka)
. Fixed bug GH-24260 (querySelectorAll() returns duplicate elements for
selector lists). (fivefilters)
. Fixed bug GH-23334 (Use-after-free in php_dom_free_templated_content()).
@@ -226,6 +134,14 @@ PHP NEWS
. Fixed bug GH-24582 (Memory leaks in ext/ffi parser when finalize_type()
bails out). (matyapiro31, David Carlier)
+- Fileinfo:
+ . Fixed bug GH-24289 (finfo::file() reports the wrong argument number for
+ an invalid $filename). (Lazizbek Ergashev)
+
+- Filter:
+ . Fixed stack overflow in filter_var() and filter_var_array() with deeply
+ nested arrays. (Eyüp Can Akman)
+
- FPM:
. Fixed bug GH-24229 (fcgi_close() passes shutdown() a literal 1, which is
SHUT_RD in WASI). (Ryosuke Ishibashi)
@@ -242,14 +158,14 @@ PHP NEWS
. Fixed null pointer dereference in fpm_get_status() when the scoreboard
copy fails. (Marcel Hernandez)
-- Fileinfo:
- . Fixed bug GH-24289 (finfo::file() reports the wrong argument number for
- an invalid $filename). (Lazizbek Ergashev)
-
- FTP:
. Fix double free in ext/ftp data_accept() on accept failure. (alepacheco)
- GD:
+ . Fixed use-after-free when drawing with a brush or tile image that was
+ released after imagesetbrush() or imagesettile(). (lacatoire)
+ . Fixed the argument blamed by the imagepolygon(), imageopenpolygon() and
+ imagefilledpolygon() too few points error. (lacatoire)
. Fixed imagetruecolortopalette() error message. (Marc Bennewitz)
- Hash:
@@ -272,6 +188,8 @@ PHP NEWS
. Fix crash in ldap_exop_sync() when $response_data is omitted. (lacatoire)
- MBString:
+ . Fixed stack overflow in mb_check_encoding() and mb_convert_encoding() with
+ deeply nested arrays. (Eyüp Can Akman)
. Fixed bug GH-23958 (truncated encoding names resolving to full names). (Kamil Tekiela)
. Fixed out-of-bounds read in php_mb_rfc1867_getword() on a multibyte lead
byte at the end of a multipart field name. (Jorg Sowa)
@@ -291,11 +209,6 @@ PHP NEWS
cannot describe a parameter). (Ilia Alshanetsky)
- Opcache:
- . Fixed bug GH-24397 (Assertion failure when dumping JIT IR).
- (Ilia Alshanetsky)
- . Fixed tracing JIT returning a wrapped integer instead of a float on
- integer overflow after an integer was compared with a float or
- numeric-string literal. (Ilia Alshanetsky)
. Fixed bug GH-20890 (Segfault in zval_undefined_cv with non-simple property
hook with minimal tracing JIT). (ndossche)
. Fixed bug GH-17626 (JIT corrupts an opline handler when blacklisting a
@@ -306,6 +219,31 @@ PHP NEWS
. Fix OSS-Fuzz #568005340 (FETCH_DIM_FUNC_ARG partial conversion). (ndossche)
. Fixed bug GH-24218 (Invalid opcode for count() of a literal array when
SCCP is disabled). (Lazizbek Ergashev)
+ . Fixed bug GH-24801 (JIT: SIGFPE in ir_fold MUL_OV constant folding).
+ (waroad)
+ . Fixed bug GH-25165 (Tracing JIT loops forever once opcache.jit_buffer_size
+ is exhausted while compiling side traces). (Ilia Alshanetsky)
+ . Fixed bug GH-25164 (Function JIT loop calling a user function runs once
+ or never terminates). (Ilia Alshanetsky)
+ . Fixed memory leak in JIT ASSIGN_DIM when the assignment fails. (Jorg Sowa)
+ . Fixed bug GH-16396 (Failed to invoke user error handler during index
+ conversion in JIT). (Jorg Sowa)
+ . Fixed bug GH-25037 (Function JIT ENTRY live var assertion).
+ (Ilia Alshanetsky)
+ . Fixed JIT ignoring leading-numeric string offsets in isset(), empty() and
+ ??. (Jorg Sowa)
+ . Fixed use-after-free in JIT when the error handler releases a string while
+ an "Undefined variable" warning is raised for its offset in ?? or nested
+ isset()/empty(). (Jorg Sowa)
+ . Fixed tracing JIT reading the int result of ++/-- on a reference as a
+ double. (ChrisAbner)
+ . Fixed bug GH-25359 (Tracing JIT drops reference type of a named by-ref
+ argument). (David Carlier)
+ . Fixed bug GH-24397 (Assertion failure when dumping JIT IR).
+ (Ilia Alshanetsky)
+ . Fixed tracing JIT returning a wrapped integer instead of a float on
+ integer overflow after an integer was compared with a float or
+ numeric-string literal. (Ilia Alshanetsky)
. Fixed bug GH-24337 (JIT: segfault when decrementing a non-numeric string
property). (Lazizbek Ergashev)
. Fix SIGFPE on LONG_MIN % -1 with a constant divisor. (waroad)
@@ -360,6 +298,8 @@ PHP NEWS
. Fixed bug GH-24988 (Incorrect opcode range check causes bugs with exceptions in
function JIT). (ndossche, Jorg Sowa)
. Fix opcache phar check. (ndossche)
+ . Fixed bug GH-8739 (OPcache restart corrupts SHM in threaded SAPIs).
+ (pavimus)
- OpenSSL:
. Fixed build and test compatibility with OpenSSL 4.0 and 4.1.
@@ -367,6 +307,10 @@ PHP NEWS
. Fixed bug GH-24784 (openssl_pkcs7_read() and openssl_cms_read() overwrite
certificates with CRLs). (Alexander Danilov)
+- PCRE:
+ . Fixed \C being allowed in patterns enabling UTF mode with (*UTF) instead
+ of the u modifier. (Jorg Sowa)
+
- PDO:
. Fixed invalid ATTR_ORACLE_NULLS values being accepted and truncated.
(Ilia Alshanetsky)
@@ -374,6 +318,8 @@ PHP NEWS
persistent connection. (Ilia Alshanetsky)
- PDO_Firebird:
+ . Fixed stack buffer overflow with long connection user names, passwords,
+ charsets, or roles. (Ilia Alshanetsky)
. Fixed bug GH-25006 (getColumnMeta() reads out of bounds for an
out-of-range column index). (Ilia Alshanetsky)
@@ -405,7 +351,7 @@ PHP NEWS
. Fixed bug GH-24531 (Crash when modifying a zip-based phar whose file was
renamed). (Ilia Alshanetsky)
-- Phpdbg:
+- phpdbg:
. Fix wrong command names. (ndossche, Weilin Du)
. Fixed bug GH-22480 (Use-after-free when re-watching an already-watched
variable). (Ilia Alshanetsky)
@@ -413,18 +359,22 @@ PHP NEWS
. Fixed double free of watch element chains. (Arnaud)
- Readline:
+ . Fixed incorrect handling of non-ASCII pending_input bytes in readline_info(),
+ which could cause readline() to return false prematurely. (Weilin Du)
. Fixed a crash in readline_info() when completion_append_character
contains a non-ASCII byte. (Weilin Du)
+- Reflection:
+ . Fix trampoline leak when object construction fails for lazy object.
+ (ndossche)
+
- SAPI:
. Fixed infinite loop in sapi_header_op() for headers of 4 GiB or more.
(Martin Mirchev)
-- SOAP:
- . Fixed use of uninitialized func in do_request() on OOM bailout.
- (David Carlier)
-
- Session:
+ . Fixed session upload progress to respect session.use_only_cookies.
+ (jorgsowa)
. Validate whole session ID instead of stopping at the first NUL byte.
(Sjoerd Langkemper)
. Fixed session data loss in the files save handler when writing the session
@@ -434,15 +384,39 @@ PHP NEWS
. Fixed bug GH-24488 (GC double-frees the SimpleXMLElement properties
table). (evankford)
-- SPL:
- . Fixed bug GH-24264 (Unwind/GracefulExit discarded in spl_iterators.c).
- (Lazizbek Ergashev)
+- SNMP:
+ . Fixed use-after-free of the context name set by SNMP::setSecurity().
+ (lacatoire)
+
+- SOAP:
+ . Fixed use of uninitialized func in do_request() on OOM bailout.
+ (David Carlier)
+ . Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key).
+ (lazerg)
+ . Fixed bug GH-25094 (NULL dereference in get_doc_function() with missing
+ parts). (lazerg)
- Sockets:
. Fixed bug GH-24748 (socket_set_option() crashes with declared object
properties). (Lazizbek Ergashev)
+- SPL:
+ . Fixed bug GH-24264 (Unwind/GracefulExit discarded in spl_iterators.c).
+ (Lazizbek Ergashev)
+
- Standard:
+ . Fixed chown() and lchown() failing to resolve user names in ZTS builds
+ when getpwnam_r() needs a larger buffer. (Ilia Alshanetsky)
+ . Fixed password_get_info() and password_needs_rehash() accepting malformed
+ bcrypt costs. (Ilia Alshanetsky)
+ . Fixed bug GH-25474 (version_compare() treats large numeric parts as equal
+ on 64-bit Windows). (lazerg)
+ . Fixed dns_get_record() returning partially built records for malformed
+ DNS responses. (Marti2203)
+ . Fixed bug GH-25387 (Uploaded files leak in request_parse_body()).
+ (Kévin Dunglas)
+ . Fixed bug GH-24743 (var_export() ignores exceptions from lazy object
+ initialization). (lazerg)
. Fixed memory leaks in checkdnsrr() and dns_check_record() on Windows.
(Ilia Alshanetsky)
. Fixed __unserialize() and __wakeup() being called for objects with a missing
@@ -451,10 +425,6 @@ PHP NEWS
was not opened by PHP). (lazerg)
. Fixed bug GH-24399 (usleep() and time_nanosleep() ignore queued APCs on
Windows). (Nicolas Grekas)
- . Fixed chown() and lchown() failing to resolve user names in ZTS builds
- when getpwnam_r() needs a larger buffer. (Ilia Alshanetsky)
- . Fixed password_get_info() and password_needs_rehash() accepting malformed
- bcrypt costs. (Ilia Alshanetsky)
. Fixed proc_open() null descriptor not being inheritable on Windows.
(Jorg Sowa)
. Don't share the unserialize() context with enum autoloaders.
@@ -467,8 +437,18 @@ PHP NEWS
objects). (Labish Bardiya)
. Fix use-after-free in Randomizer::shuffleArray() when the engine throws.
(Marti2203)
+ . Fixed unserialize() of enums sharing its state with the unserialize()
+ calls made by autoloaders. (nicolas-grekas)
- Streams:
+ . Fixed bug GH-22063 (Stream filter chain UAF on self-removal during
+ callback). (Ilia Alshanetsky)
+ . Fixed leaks and data loss when user filter leaves buckets on input
+ brigade. (ndossche, Matthias Goergens, Jakub Zelenka)
+ . Fixed bug GH-24175 (Use-after-free when pclose() closes a stream from its
+ user filter). (Edmond)
+ . Fixed bug GH-15701 (Build failure: incompatible funopen() seeker pointer
+ type on 32-bit platforms). (Kamil Tekiela)
. Fixed bug GH-24508 (HTTP wrapper leaks the dechunk filter when header
parsing fails after Transfer-Encoding). (bercedev)
. Fixed bug GH-24509 (HTTP wrapper leaks Location buffer on empty
@@ -487,15 +467,15 @@ PHP NEWS
(Lazizbek Ergashev)
- Zip:
- . Reject broken libzip versions 1.3.1, 1.7.0 and 1.12.0 during Windows
- configuration. (Weilin Du)
- . Excluded libzip 1.12.0 due to a regression preventing additions and
- replacements in torrentzip archives. (Weilin Du)
. Fixed use-after-free when re-entering ZipArchive during destruction or
a close warning, and rejected opening streams while closing. (jvoisin)
. Fixed a use-after-free when a ZipArchive method that modifies the archive
is called from a progress or cancel callback during close().
(Ilia Alshanetsky)
+ . Reject broken libzip versions 1.3.1, 1.7.0 and 1.12.0 during Windows
+ configuration. (Weilin Du)
+ . Excluded libzip 1.12.0 due to a regression preventing additions and
+ replacements in torrentzip archives. (Weilin Du)
- Zlib:
. Fixed use-after-free when an error handler removes a failing zlib.inflate
@@ -505,10 +485,25 @@ PHP NEWS
22 Oct 2026, PHP 8.4.27
-- Core:
- . Fixed GHSA-w8hw-w9fx-j79w, GHSA-6wmf-4rv5-p3rp (Avoid state corruption via
- bailout). (CVE-2026-109618, CVE-2026-109619) (Arnaud, ilutov, Jakub Zelenka,
- ndossche, Nicolas Grekas)
+- BCMath:
+ . Fixed BcMath\Number results that truncate to zero keeping a negative sign
+ and comparing less than zero. (Ilia Alshanetsky)
+
+- BZ2:
+ . Fixed double close of the descriptor and use-after-free of the inner
+ stream when bzopen() is given a stream resource. (Jakub Zelenka)
+
+- CLI
+ . Fix GH-22567 (Windows ZTS CLI SAPI should refresh its TSRMLS cache during
+ request activation). (matyhtf)
+ . Fixed bug GH-23764 (Built-in server leaks a file descriptor on every HEAD
+ request for a static file). (jakubskopal)
+ . Fixed crash in the built-in server when a client is reset before being
+ accepted. (David Carlier)
+ . Fixed the built-in server truncating an error page and leaking its
+ unsent part after a partial socket write. (Ilia Alshanetsky)
+
+- Core
. Fix GH-21999: GC inconsistency with lazy object, var_dump(), and object
comparison. (Arnaud)
. Fixed OSS-Fuzz #536440507 (Immutable class incorrect assertion).
@@ -524,32 +519,11 @@ PHP NEWS
the end of their mapping. (Ilia Alshanetsky)
. Fixed bug GH-24050 (GC frees an object still held by a resurrected closure
when (object) and use share an array). (David Carlier)
- . Fixed use-after-free when a Fiber callable resolves to $this of the method
- creating the Fiber ([A::class, 'm'] or "A::m") and that object dies before
- the Fiber runs. (Edmond Dantes)
. Fixed exception thrown by destructor during GC in a Fiber not being rethrown
into the frame that triggered the GC. (Nicolas Grekas)
. Fixed bug GH-24139 (NULL pointer dereference in php_ini.c when
expand_filepath() fails). (lazerg)
-- BCMath:
- . Fixed BcMath\Number results that truncate to zero keeping a negative sign
- and comparing less than zero. (Ilia Alshanetsky)
-
-- BZ2:
- . Fixed double close of the descriptor and use-after-free of the inner
- stream when bzopen() is given a stream resource. (Jakub Zelenka)
-
-- CLI:
- . Fix GH-22567 (Windows ZTS CLI SAPI should refresh its TSRMLS cache during
- request activation). (matyhtf)
- . Fixed bug GH-23764 (Built-in server leaks a file descriptor on every HEAD
- request for a static file). (jakubskopal)
- . Fixed crash in the built-in server when a client is reset before being
- accepted. (David Carlier)
- . Fixed the built-in server truncating an error page and leaking its
- unsent part after a partial socket write. (Ilia Alshanetsky)
-
- DOM:
. Fixed use-after-free when re-constructing a DOMXPath whose php:function
registrations are freed while still reachable from the cycle collector.
@@ -742,8 +716,6 @@ PHP NEWS
(Nicolas Grekas)
. Fixed convert.quoted-printable-decode decoding lowercase hex digits to
the wrong byte. (Ilia Alshanetsky)
- . Fixed unserialize() of enums sharing its state with the unserialize()
- calls made by autoloaders. (nicolas-grekas)
- Tidy:
. Fixed a use-after-free when a tidyNode is used after its document is
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index e56904d7efb..a486fc4f9ce 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -333,6 +333,62 @@ static inline int accel_restart_is_active(void)
return 0;
}
+#if defined(ZTS) && !defined(ZEND_WIN32)
+/* fcntl() locks belong to the process, so under ZTS they cannot tell which threads
+ * use SHM (GH-8739). The threads of this process that use SHM are counted here, and
+ * the process holds the reader lock (byte 1) whenever the count is not zero, so other
+ * processes still see it. A restart needs a zero count and a write lock on byte 1.
+ * The 0 <-> 1 transitions and the restart are serialized by accel_zts_readers_mutex,
+ * other changes of the count are lock-free. */
+static MUTEX_T accel_zts_readers_mutex = NULL;
+static zend_atomic_int accel_zts_readers;
+static time_t accel_zts_next_warning;
+
+static bool accel_zts_lock_reader_byte(int cmd, int type)
+{
+ struct flock lock;
+
+ lock.l_type = type;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 1;
+ lock.l_len = 1;
+
+ return fcntl(lock_file, cmd, &lock) != -1;
+}
+
+/* Adds (+1, only from RINIT) or releases (-1) a reference of the calling thread.
+ * Does not use ZCG() as it is also called from accel_globals_dtor(). */
+static bool accel_zts_readers_add(int delta)
+{
+ int count;
+
+#ifndef HAVE_NO_ATOMICS
+ count = zend_atomic_int_load_ex(&accel_zts_readers);
+ while (count > 0 && count + delta > 0) {
+ if (zend_atomic_int_compare_exchange_ex(&accel_zts_readers, &count, count + delta)) {
+ return true;
+ }
+ }
+#endif
+
+ tsrm_mutex_lock(accel_zts_readers_mutex);
+ count = zend_atomic_int_load_ex(&accel_zts_readers);
+ /* waits while another process restarts the cache (it holds the write lock) */
+ if (count == 0 && !accel_zts_lock_reader_byte(F_SETLKW, F_RDLCK)) {
+ zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1): %s (%d)", strerror(errno), errno);
+ tsrm_mutex_unlock(accel_zts_readers_mutex);
+ return false;
+ }
+ while (!zend_atomic_int_compare_exchange_ex(&accel_zts_readers, &count, count + delta));
+ if (count + delta == 0) {
+ /* the last reader of this process; unlock before another thread may relock */
+ accel_zts_lock_reader_byte(F_SETLK, F_UNLCK);
+ }
+ tsrm_mutex_unlock(accel_zts_readers_mutex);
+ return true;
+}
+#endif
+
/* Creates a read lock for SHM access */
static inline zend_result accel_activate_add(void)
{
@@ -340,6 +396,10 @@ static inline zend_result accel_activate_add(void)
SHM_UNPROTECT();
INCREMENT(mem_usage);
SHM_PROTECT();
+#elif defined(ZTS)
+ /* A thread becomes a reader only in RINIT, see accel_zts_readers_add(). A request
+ * that was not admitted there must not start to use SHM later. */
+ return FAILURE;
#else
struct flock mem_usage_lock;
@@ -366,6 +426,12 @@ static inline void accel_deactivate_sub(void)
ZCG(counted) = false;
SHM_PROTECT();
}
+#elif defined(ZTS)
+ /* releases the reference taken in RINIT (accel_activate_add() never succeeds under ZTS) */
+ if (ZCG(counted)) {
+ accel_zts_readers_add(-1);
+ ZCG(counted) = false;
+ }
#else
struct flock mem_usage_unlock;
@@ -382,7 +448,9 @@ static inline void accel_deactivate_sub(void)
static inline void accel_unlock_all(void)
{
-#ifdef ZEND_WIN32
+#if defined(ZEND_WIN32) || defined(ZTS)
+ /* Under ZTS never unlock the whole file: fcntl() locks belong to the process, and the
+ * SHM write lock (byte 0) and the restart lock (byte 2) may be held by other threads. */
accel_deactivate_sub();
#else
if (lock_file == -1) {
@@ -958,6 +1026,48 @@ static inline bool accel_is_inactive(void)
return false;
}
+#if defined(ZTS) && !defined(ZEND_WIN32)
+/* Replaces accel_is_inactive() under ZTS; called under zend_shared_alloc_lock().
+ * On success the readers mutex and the write lock on byte 1 are held until
+ * accel_zts_restart_end(): no thread of this process can become a reader (the count is
+ * zero and may only grow from zero under the mutex), and other processes can neither
+ * hold the reader lock nor take it. */
+static bool accel_zts_restart_begin(void)
+{
+ int readers;
+ time_t now;
+
+ tsrm_mutex_lock(accel_zts_readers_mutex);
+ readers = zend_atomic_int_load_ex(&accel_zts_readers);
+ if (readers == 0 && accel_zts_lock_reader_byte(F_SETLK, F_WRLCK)) {
+ return true;
+ }
+ tsrm_mutex_unlock(accel_zts_readers_mutex);
+
+ now = time(NULL);
+ if (readers == 0) {
+ /* readers in other processes: as without ZTS, force_restart_timeout kills them,
+ * here with all their threads */
+ (void) accel_is_inactive();
+ } else if (ZCG(accel_directives).force_restart_timeout && ZCSG(force_restart_time)
+ && now >= ZCSG(force_restart_time) && now >= accel_zts_next_warning) {
+ /* Threads cannot be killed and this process must not kill itself: the restart
+ * waits for the running requests, new ones run uncached meanwhile */
+ zend_accel_error(ACCEL_LOG_WARNING, "Restart delayed for %ld seconds by %d threads of process %d still using the cache",
+ (long)(now - ZCSG(force_restart_time) + ZCG(accel_directives).force_restart_timeout), readers, getpid());
+ accel_zts_next_warning = now + ZCG(accel_directives).force_restart_timeout;
+ }
+ return false;
+}
+
+static void accel_zts_restart_end(void)
+{
+ accel_zts_lock_reader_byte(F_SETLK, F_UNLCK);
+ accel_zts_next_warning = 0;
+ tsrm_mutex_unlock(accel_zts_readers_mutex);
+}
+#endif
+
static int zend_get_stream_timestamp(const char *filename, zend_stat_t *statbuf)
{
php_stream_wrapper *wrapper;
@@ -2727,7 +2837,11 @@ ZEND_RINIT_FUNCTION(zend_accelerator)
if (ZCSG(restart_pending)) {
zend_shared_alloc_lock();
if (ZCSG(restart_pending)) { /* check again, to ensure that the cache wasn't already cleaned by another process */
+#if defined(ZTS) && !defined(ZEND_WIN32)
+ if (accel_zts_restart_begin()) {
+#else
if (accel_is_inactive()) {
+#endif
zend_accel_error(ACCEL_LOG_DEBUG, "Restarting!");
ZCSG(restart_pending) = false;
switch ZCSG(restart_reason) {
@@ -2767,6 +2881,9 @@ ZEND_RINIT_FUNCTION(zend_accelerator)
ZCSG(last_restart_time)++;
}
accel_restart_leave();
+#if defined(ZTS) && !defined(ZEND_WIN32)
+ accel_zts_restart_end();
+#endif
}
}
zend_shared_alloc_unlock();
@@ -2774,6 +2891,19 @@ ZEND_RINIT_FUNCTION(zend_accelerator)
ZCG(accelerator_enabled) = ZCSG(accelerator_enabled);
+#if defined(ZTS) && !defined(ZEND_WIN32)
+ /* Under ZTS this is the only place where a request starts to use SHM */
+ if (ZCG(accelerator_enabled)) {
+ if (accel_zts_readers_add(1)) {
+ ZCG(counted) = true;
+ /* SHM-backed keys may be added to the PCRE cache again */
+ ZCG(pcre_reseted) = false;
+ } else {
+ ZCG(accelerator_enabled) = false;
+ }
+ }
+#endif
+
SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS();
@@ -2827,6 +2957,8 @@ zend_result accel_post_deactivate(void)
zend_shared_alloc_safe_unlock(); /* be sure we didn't leave cache locked */
accel_unlock_all();
ZCG(counted) = false;
+ /* the reference is released: do not use SHM until the next RINIT */
+ ZCG(accelerator_enabled) = false;
return SUCCESS;
}
@@ -3001,6 +3133,16 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
static void accel_globals_dtor(zend_accel_globals *accel_globals)
{
+#if defined(ZTS) && !defined(ZEND_WIN32)
+ /* The thread is retired without its request cleanup (e.g. another extension
+ * bailed out in post_deactivate): release its reference, otherwise restarts would
+ * wait for it forever. Uses only the given globals: ts_free_id() calls this for
+ * all threads from the current one. */
+ if (accel_globals->counted && accel_zts_readers_mutex) {
+ accel_globals->counted = false;
+ accel_zts_readers_add(-1);
+ }
+#endif
zend_string_free(accel_globals->key);
if (accel_globals->preloaded_internal_run_time_cache) {
pefree(accel_globals->preloaded_internal_run_time_cache, 1);
@@ -3326,6 +3468,13 @@ static zend_result accel_post_startup(void)
/* from this point further, shared memory is supposed to be OK */
+#if defined(ZTS) && !defined(ZEND_WIN32)
+ /* before preloading runs its request and before SAPIs fork their children */
+ accel_zts_readers_mutex = tsrm_mutex_alloc();
+ ZEND_ATOMIC_INT_INIT(&accel_zts_readers, 0);
+ accel_zts_next_warning = 0;
+#endif
+
/* remember the last restart time in the process memory */
ZCG(last_restart_time) = ZCSG(last_restart_time);
@@ -3435,6 +3584,12 @@ static void accel_post_shutdown(void)
}
zend_shared_alloc_shutdown();
+#if defined(ZTS) && !defined(ZEND_WIN32)
+ if (accel_zts_readers_mutex) {
+ tsrm_mutex_free(accel_zts_readers_mutex);
+ accel_zts_readers_mutex = NULL;
+ }
+#endif
}
void accel_shutdown(void)
diff --git a/ext/opcache/tests/gh8739.phpt b/ext/opcache/tests/gh8739.phpt
new file mode 100644
index 00000000000..4e43e8583d0
--- /dev/null
+++ b/ext/opcache/tests/gh8739.phpt
@@ -0,0 +1,56 @@
+--TEST--
+GH-8739: OPcache restart in a server with several workers
+--DESCRIPTION--
+A scheduled restart happens in the next request once no request uses the cache, and the cache
+works after it. Under ZTS this checks the per-process reader count and the reader lock shared by
+the worker processes: a reference that is never released would delay the restart forever.
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+--CONFLICTS--
+server
+--FILE--
+<?php
+$dir = __DIR__ . '/gh8739';
+@mkdir($dir);
+file_put_contents("$dir/status.php", <<<'PHP'
+<?php
+$status = opcache_get_status(false);
+echo $status['opcache_enabled'] ? 'enabled' : 'disabled',
+ ', restarts: ', $status['opcache_statistics']['manual_restarts'],
+ ', ', opcache_is_script_cached(__FILE__) ? 'cached' : 'not cached', "\n";
+PHP);
+file_put_contents("$dir/reset.php", "<?php\nvar_dump(opcache_reset());\n");
+
+include __DIR__ . '/php_cli_server.inc';
+
+/* elsewhere the workers outlive the server without PDEATHSIG, see php_cli_server_pdeathsig.phpt */
+if (PHP_OS === 'Linux' || PHP_OS === 'FreeBSD') {
+ putenv('PHP_CLI_SERVER_WORKERS=2');
+}
+$ini = '-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.file_update_protection=0';
+$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);
+
+$base = 'http://' . PHP_CLI_SERVER_ADDRESS . '/gh8739/';
+foreach (['status', 'reset', 'status', 'status'] as $script) {
+ echo @file_get_contents($base . $script . '.php') ?: "no response\n";
+}
+?>
+--CLEAN--
+<?php
+$dir = __DIR__ . '/gh8739';
+@unlink("$dir/status.php");
+@unlink("$dir/reset.php");
+@rmdir($dir);
+?>
+--EXPECT--
+enabled, restarts: 0, cached
+bool(true)
+enabled, restarts: 1, cached
+enabled, restarts: 1, cached