CVE-2026-129291
Patch Available.
This Vulnerability has been fixed in the Never-Ending Support (NES) version offered by HeroDevs.
Overview
PHP is a general-purpose scripting language used mostly for web development. It runs behind web servers through server APIs such as Apache mod_php and PHP-FPM, and powers content management systems and frameworks such as WordPress, Drupal, Moodle and Laravel. PHP-FPM runs a master process, commonly as root, that manages pools of unprivileged worker processes. With catch_workers_output enabled, the master reads each worker's stdout and stderr through pipes that it watches in its event loop.
A Use After Free vulnerability (CVE-2026-129291) has been identified in how the PHP-FPM master closes the output pipes of an exiting worker, which allows an attacker who can already run PHP code in an unprivileged FPM worker to make the master dispatch an epoll event that points into a freed worker record, and through it execute commands with the privileges of the FPM master. The PHP project tracks this issue as GHSA-jm4m-qfqx-967m.
Per MITRE CWE-416: The product reuses or references memory after it has been freed.
This issue affects PHP 8.1 from 8.1.20 through its final release (8.1.34), PHP 8.2 from 8.2.7 before 8.2.36, PHP 8.3 before 8.3.37, PHP 8.4 before 8.4.28 and PHP 8.5 before 8.5.13. PHP 8.0 and earlier, and PHP 8.1 before 8.1.20, do not contain the affected delayed cleanup code.
Details
Module Info
- Product: PHP
- Affected packages: php-src (sapi/fpm)
- Affected versions: >=8.1.20 <8.2.0, >=8.2.7 <8.2.36, >=8.3.0 <8.3.37, >=8.4.0 <8.4.28, >=8.5.0 <8.5.13
- GitHub repository: https://github.com/php/php-src
- Published packages: https://www.php.net/downloads
- Package manager: N/A
- Fixed in:
- OSS PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13
- NES for PHP
Vulnerability Info
This High-severity vulnerability is found in PHP-FPM in PHP 8.1 from 8.1.20 through its final release (8.1.34), PHP 8.2 from 8.2.7 before 8.2.36, PHP 8.3 before 8.3.37, PHP 8.4 before 8.4.28 and PHP 8.5 before 8.5.13. The PHP project scores it 8.8 under CVSS 4.0 (CVSS:4.0/AV:L/AC:H/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H).
The epoll registrations for a worker's output pipes store pointers to event structures embedded in that worker's record. When a worker exits, fpm_child_close() tries to drain the pipes and then closes them. In PHP 8.2.35, the code reads:
if (child->fd_stdout != -1) {
if (in_event_loop) {
child->postponed_free = true;
fpm_event_fire(&child->ev_stdout);
}
if (child->fd_stdout != -1) {
close(child->fd_stdout);
}
}
If another process still holds the write end of a pipe, the read can return EAGAIN and never reach end of file. The master then closes its read descriptor without removing the event or clearing the descriptor number stored in the worker record, and defers freeing the record by one second. By the time the delayed cleanup runs, the descriptor number may have been reused, so the cleanup can remove the wrong watch, or fail to remove the original one, before the record is freed. A later write to the old pipe makes epoll return a pointer into the freed record, and the master calls the callback stored there.
Exploitation needs local code execution in an FPM worker, a pool with catch_workers_output enabled, the epoll event backend, and the ability to manipulate worker lifetimes and keep inherited pipe descriptors open. The reporter reproduced root command execution from a www-data worker against unmodified PHP 8.5.12 Docker images on Linux arm64 and x86-64. The exploit depends on memory layout and process timing.
If the master runs as an unprivileged user, the gain is limited to that user's privileges. In a container, the result is the master's container privileges, which is not a container escape by itself. The same descriptor lifetime error can also close another worker's reused descriptor, disrupt logging or request handling, or crash the master. The official PHP-FPM Docker images enable worker output capture; the default elsewhere is catch_workers_output = no.
The advisory states that the delayed cleanup path was introduced in PHP 8.1.20 and 8.2.7. PHP 8.1 reached End-of-Life without a fix, and its final release, 8.1.34, contains the same code.
The fix removes each output event while its descriptor is still valid, closes the descriptor and sets the stored number to -1, so the delayed cleanup can't act on it again:
if (child->fd_stdout != -1) {
if (in_event_loop) {
child->postponed_free = true;
fpm_event_fire(&child->ev_stdout);
}
if (child->fd_stdout != -1) {
if (in_event_loop) {
fpm_event_del(&child->ev_stdout);
}
close(child->fd_stdout);
child->fd_stdout = -1;
}
}
Mitigation
The PHP project publishes security fixes only for its supported release lines. PHP 8.1 is End-of-Life and will not receive any public updates to address this issue.
Until an upgrade is possible, disable catch_workers_output in affected pools. Running the FPM master without root limits what an attacker can gain, but it does not correct the use after free.
Users of the affected components should apply one of the following mitigations:
- Upgrade to PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13, or later.
- Leverage a commercial support partner like HeroDevs (NES for PHP) for post-EOL security support.
Credits
- Thomas Chauchefoin (finder)
- Ian P. Christian (remediation)