GHSA-jm4m-qfqx-967m / CVE-2026-129291: PHP-FPM epoll use-after-free can lead to local privilege escalation
- Published:
- Fetched:
- Updated:
- Affects:
- php sapi-fpm
https://github.com/php/php-src/security/advisories/GHSA-jm4m-qfqx-967m ↗
PHP-FPM epoll use-after-free can lead to local privilege escalation ### Summary PHP-FPM can dispatch an epoll event that refers to a freed worker record when worker output capture is enabled. An attacker who can execute PHP code in an unprivileged FPM worker can exploit this use-after-free to execute commands with the privileges of the FPM master, which commonly runs as root. ### Details When `catch_workers_output` is enabled, the FPM master monitors pipes connected to worker stdout and stderr. The epoll registrations store pointers to event structures embedded in the corresponding worker record. When a worker exits, `fpm_child_close()` attempts to drain its output pipes. If a helper process still holds a pipe's write end open, the read can return `EAGAIN` instead of reaching EOF. In this case, the master closes the pipe's read descriptor without first removing its event or invalidating the descriptor number stored in the worker record. Cleanup of that record is deferred for one second. An attacker can stop a newly forked sibling after it drops to the pool user but before it closes inherited descriptors. The stopped sibling retains the original pipe readers and epoll descriptor, keeping the original watch alive after the master closes its own descriptors. The delayed cleanup can then use a descriptor number that has already been reused, removing the wrong watch or failing to remove the original one before freeing the worker record. A subsequent write to the old pipe makes epoll return a pointer into the freed record. The master passes that pointer to `fpm_event_fire()`, which reads and calls the event callback. The demonstrated exploit uses the stale output callback to write through a freed logging buffer, corrupt the allocator's free list, and replace the callback with a function that executes a command. Root command execution was reproduced from a `www-data` worker against unmodified PHP 8.5.12 Docker images on Linux arm64 and x86-64. The exploit is dependent on memory layout and process timing. Curl and OPcache were used to obtain memory addresses for the demonstrated chain; they are not required to trigger the underlying epoll use-after-free. The affected delayed-cleanup path was introduced in PHP 8.1.20 and 8.2.7. The fix unregisters each stdio event while its original descriptor is still valid, closes the descriptor, and sets the stored descriptor to `-1` so that delayed cleanup cannot act on it again. ### Impact Exploitation requires local code execution in an FPM worker, an affected pool with `catch_workers_output` enabled, the epoll event backend, and the ability to manipulate worker lifetimes and retain inherited pipe descriptors. A root FPM master permits escalation from the pool user to root. If the master runs as an unprivileged user, successful exploitation is limited to that user's privileges. In a container, this grants the master's container privileges and does not by itself establish a container escape. The underlying descriptor-lifetime error can also close another Affected packages: php:sapi-fpm Patched: sapi-fpm None, sapi-fpm 8.2.36, sapi-fpm 8.3.37, sapi-fpm 8.4.28, sapi-fpm 8.5.13