[packages/php/PHP_5_6] Rel 46. Fix FPM child reaping and user wrapper bailout bugs
arekm
arekm at pld-linux.org
Fri Nov 20 08:15:00 CET 2026
commit 85807534638d75bac00265ef9dee92bbe9869f0d
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Nov 19 22:41:07 2026 +0100
Rel 46. Fix FPM child reaping and user wrapper bailout bugs
FPM reaped children mid epoll batch; later events used freed memory.
SplFileObject freed a borrowed name after a bailout in a user wrapper.
User wrapper recursion guard outlived a bailout into the next request.
php-bug77185.patch | 66 ++++++++++++++++++++++++++++++++++++
php-spl-file-open-bailout.patch | 60 ++++++++++++++++++++++++++++++++
php-user-stream-filename-reset.patch | 24 +++++++++++++
php.spec | 9 ++++-
4 files changed, 158 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index 0bdb3b2..a0fc150 100644
--- a/php.spec
+++ b/php.spec
@@ -155,7 +155,7 @@ ERROR: You need to select at least one Apache SAPI to build shared modules.
%undefine with_filter
%endif
-%define rel 45
+%define rel 46
%define orgname php
%define ver_suffix 56
%define php_suffix %{!?with_default_php:%{ver_suffix}}
@@ -385,6 +385,10 @@ Patch445: php-cve-2026-129481.patch
Patch446: php-cve-2026-128090.patch
# PLD-only: openssl_sign() result read after efree() (5.x-only code)
Patch447: php-phar-openssl-sign-uaf.patch
+Patch448: php-bug77185.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch449: php-spl-file-open-bailout.patch
+Patch450: php-user-stream-filename-reset.patch
URL: https://www.php.net/
%{?with_interbase:%{!?with_interbase_inst:BuildRequires: Firebird-devel >= 1.0.2.908-2}}
%{?with_pspell:BuildRequires: aspell-devel >= 2:0.50.0}
@@ -2445,6 +2449,9 @@ exit 1
%patch -P445 -p1
%patch -P446 -p1
%patch -P447 -p1
+%patch -P448 -p1
+%patch -P449 -p1
+%patch -P450 -p1
sed -E -i -e '1s,#!\s*/usr/bin/env\s+(.*),#!%{__bindir}\1,' \
run-tests.php
diff --git a/php-bug77185.patch b/php-bug77185.patch
new file mode 100644
index 0000000..0f8ccb8
--- /dev/null
+++ b/php-bug77185.patch
@@ -0,0 +1,66 @@
+From bdf24f8d6d9d495ece354d6fd2dd6ed169198a2e Mon Sep 17 00:00:00 2001
+From: Maksim Nikulin <mnikulin at plesk.com>
+Date: Wed, 23 Jan 2019 12:19:29 +0700
+Subject: [PATCH] Prevent use after free in fpm_event_epoll_wait
+
+The master reaps children from the SIGCHLD event in the middle of an
+epoll batch, so later events of that batch still point at the reaped
+children's stdio events and read their closed descriptors (EBADF).
+Reap from a timer once the batch is done, as PHP 7.3.9+ does.
+
+The upstream test was removed later as unreliable (b59a9381b989) and
+is not included.
+
+Origin: upstream, https://github.com/php/php-src/commit/bdf24f8d6d9d495ece354d6fd2dd6ed169198a2e
+Bug: https://bugs.php.net/77185
+---
+ sapi/fpm/fpm/fpm_events.c | 15 ++++++++++++++-
+ 1 file changed, 14 insertions(+), 1 deletion(-)
+
+diff --git a/sapi/fpm/fpm/fpm_events.c b/sapi/fpm/fpm/fpm_events.c
+index ce5d543f..d45ae860 100644
+--- a/sapi/fpm/fpm/fpm_events.c
++++ b/sapi/fpm/fpm/fpm_events.c
+@@ -36,6 +36,7 @@
+ #define fpm_event_set_timeout(ev, now) timeradd(&(now), &(ev)->frequency, &(ev)->timeout);
+
+ static void fpm_event_cleanup(int which, void *arg);
++static void fpm_postponed_children_bury(struct fpm_event_s *ev, short which, void *arg);
+ static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg);
+ static struct fpm_event_s *fpm_event_queue_isset(struct fpm_event_queue_s *queue, struct fpm_event_s *ev);
+ static int fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_event_s *ev);
+@@ -45,6 +46,7 @@ static void fpm_event_queue_destroy(struct fpm_event_queue_s **queue);
+ static struct fpm_event_module_s *module;
+ static struct fpm_event_queue_s *fpm_event_queue_timer = NULL;
+ static struct fpm_event_queue_s *fpm_event_queue_fd = NULL;
++static struct fpm_event_s children_bury_timer;
+
+ static void fpm_event_cleanup(int which, void *arg) /* {{{ */
+ {
+@@ -53,6 +55,12 @@ static void fpm_event_cleanup(int which, void *arg) /* {{{ */
+ }
+ /* }}} */
+
++static void fpm_postponed_children_bury(struct fpm_event_s *ev, short which, void *arg) /* {{{ */
++{
++ fpm_children_bury();
++}
++/* }}} */
++
+ static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg) /* {{{ */
+ {
+ char c;
+@@ -74,7 +82,12 @@ static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg) /* {{
+ switch (c) {
+ case 'C' : /* SIGCHLD */
+ zlog(ZLOG_DEBUG, "received SIGCHLD");
+- fpm_children_bury();
++ /* epoll_wait() may report signal fd before read events for a finished child
++ * in the same bunch of events. Prevent immediate free of the child structure
++ * and so the fpm_event_s instance. Otherwise use after free happens during
++ * attemp to process following read event. */
++ fpm_event_set_timer(&children_bury_timer, 0, &fpm_postponed_children_bury, NULL);
++ fpm_event_add(&children_bury_timer, 0);
+ break;
+ case 'I' : /* SIGINT */
+ zlog(ZLOG_DEBUG, "received SIGINT");
diff --git a/php-spl-file-open-bailout.patch b/php-spl-file-open-bailout.patch
new file mode 100644
index 0000000..06b4c7a
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,60 @@
+Subject: [PATCH] spl: own the SplFileObject file name before opening it
+
+spl_filesystem_file_open() kept pointing at the caller's file name until the
+open succeeded. exit(), a fatal error or a timeout inside a user stream
+wrapper's url_stat or stream_open left it there, and the object's free then
+released an interned literal or another SplFileInfo's name (invalid or
+double free at shutdown).
+
+PLD-only: php-src (master too) still borrows the name until the open
+succeeds; shivammathur/php-src-backports, remicollet/php-src-security and
+Debian/Freexian php5 and php7.0 have no fix.
+---
+diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
+index 3a22357a..55b0a7ba 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -277,9 +277,16 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+
+ intern->type = SPL_FS_FILE;
+
++ /* both are borrowed from the caller; copy them before user wrapper code can
++ * bail out, as spl_filesystem_object_free_storage() frees file_name */
++ intern->file_name = estrndup(intern->file_name, intern->file_name_len);
++ intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
++
+ php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp TSRMLS_CC);
+ if (Z_LVAL(tmp)) {
++ efree(intern->u.file.open_mode);
+ intern->u.file.open_mode = NULL;
++ efree(intern->file_name);
+ intern->file_name = NULL;
+ zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Cannot use SplFileObject with directories");
+ return FAILURE;
+@@ -292,7 +299,9 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ if (!EG(exception)) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : "");
+ }
+- intern->file_name = NULL; /* until here it is not a copy */
++ efree(intern->file_name);
++ intern->file_name = NULL;
++ efree(intern->u.file.open_mode);
+ intern->u.file.open_mode = NULL;
+ return FAILURE;
+ }
+@@ -302,14 +311,11 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ }
+
+ if (intern->file_name_len > 1 && IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) {
+- intern->file_name_len--;
++ intern->file_name[--intern->file_name_len] = '\0';
+ }
+
+ intern->orig_path = estrndup(intern->u.file.stream->orig_path, strlen(intern->u.file.stream->orig_path));
+
+- intern->file_name = estrndup(intern->file_name, intern->file_name_len);
+- intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
+-
+ /* avoid reference counting in debug mode, thus do it manually */
+ ZVAL_RESOURCE(&intern->u.file.zresource, php_stream_get_resource_id(intern->u.file.stream));
+ Z_SET_REFCOUNT(intern->u.file.zresource, 1);
diff --git a/php-user-stream-filename-reset.patch b/php-user-stream-filename-reset.patch
new file mode 100644
index 0000000..ea5b2b2
--- /dev/null
+++ b/php-user-stream-filename-reset.patch
@@ -0,0 +1,24 @@
+From d0b3096ff0f6f6f491833858f126a80f18b81151 Mon Sep 17 00:00:00 2001
+From: Dmitry Stogov <dmitry at zend.com>
+Date: Mon, 12 Sep 2022 11:38:31 +0300
+Subject: [PATCH] Reset FG(user_stream_current_filename) at the end of request
+
+A bailout inside a user stream wrapper's stream_open or dir_opendir left
+the recursion guard pointing into the finished request, so a later request
+of the same process could read freed memory and fail with "infinite
+recursion prevented" when it opened the same URL.
+
+Origin: upstream, https://github.com/php/php-src/commit/d0b3096ff0f6f6f491833858f126a80f18b81151
+---
+diff --git a/main/streams/streams.c b/main/streams/streams.c
+index 4e00cd1b..40467d72 100644
+--- a/main/streams/streams.c
++++ b/main/streams/streams.c
+@@ -1628,6 +1628,7 @@ static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC
+
+ void php_shutdown_stream_hashes(TSRMLS_D)
+ {
++ FG(user_stream_current_filename) = NULL;
+ if (FG(stream_wrappers)) {
+ zend_hash_destroy(FG(stream_wrappers));
+ efree(FG(stream_wrappers));
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/85807534638d75bac00265ef9dee92bbe9869f0d
More information about the pld-cvs-commit
mailing list