[packages/php/PHP_5_3] Rel 76. Fix FPM child reaping and user wrapper bailout bugs

arekm arekm at pld-linux.org
Fri Nov 20 08:15:15 CET 2026


commit 874fcac710d2d3f4bd04fe184e04752cd27a2b05
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Nov 19 22:41:08 2026 +0100

    Rel 76. 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 162c3e3..505daaa 100644
--- a/php.spec
+++ b/php.spec
@@ -143,7 +143,7 @@ ERROR: You need to select at least one Apache SAPI to build shared modules.
 %undefine	with_alternatives
 %endif
 
-%define		rel	75
+%define		rel	76
 %define		orgname	php
 %define		ver_suffix 53
 %define		php_suffix %{!?with_default_php:%{ver_suffix}}
@@ -284,6 +284,10 @@ Patch241:	php-5.3.29-CVE-2026-128064.patch
 Patch242:	php-5.3.29-CVE-2026-127960.patch
 Patch243:	php-5.3.29-CVE-2026-129481.patch
 Patch244:	php-phar-openssl-sign-uaf.patch
+Patch245:	php-bug77185.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch246:	php-spl-file-open-bailout.patch
+Patch247:	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}
@@ -2214,6 +2218,9 @@ gzip -dc %{SOURCE15} | tar xf - -C sapi/
 %patch -P242 -p1
 %patch -P243 -p1
 %patch -P244 -p1
+%patch -P245 -p1
+%patch -P246 -p1
+%patch -P247 -p1
 # the patches carry the regenerated scanners, keep make from rebuilding them
 touch ext/date/lib/parse_date.c ext/standard/var_unserializer.c Zend/zend_ini_parser.c
 
diff --git a/php-bug77185.patch b/php-bug77185.patch
new file mode 100644
index 0000000..f5151fc
--- /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 d5835f0..fb08a07 100644
+--- a/sapi/fpm/fpm/fpm_events.c
++++ b/sapi/fpm/fpm/fpm_events.c
+@@ -32,6 +32,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);
+@@ -41,6 +42,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) /* {{{ */
+ {
+@@ -49,6 +51,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;
+@@ -70,7 +78,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..a886feb
--- /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 5a308a5..aa91abd 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -275,9 +275,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;
+@@ -290,7 +297,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;
+ 	}
+@@ -300,14 +309,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..0c49c3a
--- /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 edc2591..f3e3a43 100644
+--- a/main/streams/streams.c
++++ b/main/streams/streams.c
+@@ -1554,6 +1554,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/874fcac710d2d3f4bd04fe184e04752cd27a2b05



More information about the pld-cvs-commit mailing list