PHP2Shell (CVE-2026-109618/109619): Analysis, Detection, Fix
PHP2Shell: two memory corruption bugs in the PHP core allow unauthenticated RCE. The longjmp and stale-global mechanics, how to detect them and what to do.
Zyberum Security Team · Published · 15 min read
PHP2Shell is a pair of memory corruption bugs in the PHP engine itself, not in an application or a framework. Both come from the same weakness: a fatal error tears down a request while the engine still holds half-built or already freed state. An attacker who can send HTTP requests to a PHP site can turn that into code execution, without logging in and without a single line of vulnerable application code.
The fixes shipped on 21 October 2026. Attack traffic was seen hours before the public disclosure. This guide covers the mechanics, the detection and the actions. It is part of our series on the 2Shell vulnerabilities.
The facts in one table
| CVE-2026-109618 | CVE-2026-109619 | |
|---|---|---|
| Title of the advisory | RCE via OOM corruption | RCE via stale global state |
| Class | Invalid state after longjmp(), CWE-416 | Use after free across two requests, CWE-416 |
| Score | CVSS 4.0: 9.2, AV:N/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H | The same |
| Fixed in | 8.2.35, 8.3.36, 8.4.27, 8.5.12 | 8.2.35, 8.3.36, 8.4.27, 8.5.12, completed in 8.5.13 |
| Trigger | Memory limit reached while a structure is half built | Fatal error leaves a pointer in a worker global |
| Needs | One request | Two requests handled by the same worker |
| Authentication | None | None |
Other scorers disagree on the older scale: Red Hat rates 8.1 on CVSS 3.1, Ubuntu 9.8. The AC:H in the vector is honest: a working exploit has to match the exact build. The code path goes back to PHP 5.4 according to the researchers; only 8.2 to 8.5 receive upstream fixes. Both entries are in the CISA KEV catalogue since 26 October 2026.
A warning about the names: the Wiz write-up assigns the two CVE numbers the other way round than the PHP advisories. We follow the PHP project, which issued them.
How does CVE-2026-109618 work?
PHP used longjmp() to leave the current code when memory ran out. That jump skips everything between the failing allocation and the request shutdown, including the code that would have completed or undone a half-finished operation. Shutdown then walks over a structure that is not what its bookkeeping says.
The researchers at Calif name one concrete place: in _zend_hash_str_add_or_update_i the element counter of a hash table is incremented before the memory for the new key is allocated. If exactly that allocation hits the memory limit, the table claims one element more than it owns. The teardown treats the missing element as real.
- Step 1/5A request makes PHP build a large structure. Multipart parsing happens before any application code, so the attacker controls how much memory is used and when it runs out.
- Step 2/5The memory limit is reached in the middle of an operation. PHP raises a fatal error.
- Step 3/5
longjmp()jumps straight to the bailout handler. The code that would have finished or rolled back the operation never runs. - Step 4/5Request shutdown frees everything the bookkeeping lists, including an element that was counted but never created. This is the corruption.
- Step 5/5The fix removes the jump. Out of memory is now handled at the next safe point of the virtual machine, and a hard limit ends the process with
_exit()if needed.
How does an unauthenticated request get PHP to the memory limit at a chosen moment? The advisory lists the levers: a multipart body without a usable length passes the first post_max_size check while it is still streaming, an unlimited number of headers per part consumes memory below post_max_size, and empty file fields allocate metadata without counting towards max_file_uploads.
How does CVE-2026-109619 work?
A PHP worker serves many requests in a row. Each request gets a fresh heap that is freed at the end, but the worker’s global variables live on. If a fatal error interrupts an operation before it resets its global, the next request on that worker finds a pointer into memory that no longer belongs to it.
- Step 1/6Request A is a multipart upload with an upload progress field. PHP handles it before the request is fully started and stores pointers to session data in worker globals.
- Step 2/6A fatal error ends request A, for example the memory limit or a timeout. The reset of the globals is skipped.
- Step 3/6The request heap is freed as always. The globals still point into it.
- Step 4/6Request B must reach the same worker. With mod_php a keep-alive connection is enough; with PHP-FPM the session cookie can pin the worker.
- Step 5/6Before request B is initialised, PHP touches the old global. It reads and frees memory that now holds data from the attacker.
- Step 6/6With a leaked code address and a matching build, the corrupted structure redirects execution. Code runs as the PHP user.
The advisory names the producers and consumers of such state:
session.upload_progress(enabled by default): upload progress reaches session and decoder state before normal initialisation. This path was validated against PHP-FPM.fatal_error_backtraces(PHP 8.5): the backtrace of a fatal error is request memory, and its reset was missed. This is the confirmed producer for code execution on 8.5.- Early INI consumers: diagnostics from settings applied before request startup, among them
memory_limit,date.timezone,mbstring.*,iconv.*,filter.defaultandopen_basedir. With mod_php,.htaccessandphp_valuesettings are applied early, which is one reason why mod_php is the most exposed.
What happens in memory:
- Step 1/4Request A allocates session data on its request heap. A worker global points to it.
- Step 2/4The fatal error ends the request. The heap is released, the global is not reset: it now points to freed memory.
- Step 3/4Request B brings many form fields of the right size. The allocator hands out the freed block again, now filled with data from the attacker.
- Step 4/4PHP follows the old pointer and treats the attacker data as its own structure. Reading leaks memory, freeing or writing corrupts it.
Why one exploit does not fit all
Turning the corruption into code execution needs addresses and offsets that differ per build. Tenable shows that the heap layout changes with every patch release, distribution package and set of extensions. The attack also needs the second request on the same worker: pm.max_requests recycling breaks the chain, and it produces false negatives in scanners for the same reason.
The exception are appliances and container images that ship one identical PHP build to thousands of installations. There the calibration is paid once.
What the patch changed
- 109618:
longjmp()for out of memory is gone. PHP now raises a soft out-of-memory condition at the next safe point of the virtual machine, and a second, higher threshold ends the process through_exit(). - 109619: request-owned global and extension state is reset so that it cannot survive into the early phase of the next request.
- 8.5.13 (19 November 2026) completes the fix: the 8.5.12 change cleared the fatal backtrace but later shutdown work could fill it again (CVE-2026-129182). The same release fixes further session issues, among them CVE-2026-115560, CVE-2026-129481 and CVE-2026-126714.
How to identify PHP2Shell
Find every PHP runtime, including the ones nobody thinks of as PHP, then compare versions per distribution and check the logs since mid October 2026.
1. Find every runtime and its version
The command line binary is often not the one that serves the web. Check each SAPI:
php -v; php-fpm -v 2>/dev/null; php-cgi -v 2>/dev/null
apachectl -M 2>/dev/null | grep -i php # mod_php loaded?
ps -eo user,pid,cmd | grep -E 'php-fpm|php-cgi|frankenphp|lsphp' | grep -v grep
# Packages: compare with the advisory of your distribution
dpkg -l 'php*' | awk '/^ii/{print $2, $3}'
rpm -qa 'php*'
# Containers and Kubernetes
docker ps --format '{{.Names}}' | xargs -I{} sh -c 'echo {}; docker exec {} php -v 2>/dev/null | head -1'
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{range .spec.containers[*]}{.image}{" "}{end}{"\n"}{end}' | grep -i -E 'php|wordpress|drupal|nextcloud|laravel'
| Branch | Fixed upstream | Examples of fixed packages |
|---|---|---|
| 8.5 | 8.5.12, better 8.5.13 | Ubuntu 26.04: 8.5.4-0ubuntu1.5 |
| 8.4 | 8.4.27 | Debian 13: DSA-6574-1 |
| 8.3 | 8.3.36 | Ubuntu 24.04: 8.3.6-0ubuntu0.24.04.13 |
| 8.2 | 8.2.35 | Debian 12: DLA-4848-1 |
| 8.1 and older | No upstream fix | Ubuntu 22.04: 8.1.2-1ubuntu2.28; older releases only with ESM |
PHP 8.2 reaches its end of life on 31 December 2026. After that date it receives no further security fixes upstream.
Do not stop at servers you administer as “PHP servers”. The runtime is bundled in appliances, management interfaces, NAS systems, ticket systems and monitoring tools. For those, the version that counts is the vendor’s firmware or build number.
2. Check the settings that open or close paths
php -i | grep -E 'session.upload_progress.enabled|memory_limit|fatal_error_backtraces|post_max_size|max_input_nesting_level'
grep -R -n -E 'php_(admin_)?value|php_(admin_)?flag' /etc/apache2 /etc/httpd /var/www --include='*.conf' --include='.htaccess' 2>/dev/null
grep -R -n -E 'pm.max_requests|php_admin_value|php_value' /etc/php*/ 2>/dev/null
Run php -i for the SAPI in question or read phpinfo() through the web server: FPM pools and .htaccess files override php.ini.
3. Look for attack traces
The attack is noisy on the server, because failed attempts crash workers:
# Memory limit fatals and crashed workers
grep -E 'Allowed memory size of [0-9]+ bytes exhausted' /var/log/php*-fpm.log /var/log/apache2/error.log 2>/dev/null | tail
grep -E 'exited on signal (11|6)|SIGSEGV|segfault' /var/log/php*-fpm.log /var/log/apache2/error.log 2>/dev/null | tail
dmesg -T | grep -i -E 'segfault.*(php|apache2|httpd)'
journalctl -k --since '2026-10-15' | grep -i -E 'php.*segfault|httpd.*segfault'
# Bursts of 500 answers to multipart POSTs
awk '$6 ~ /POST/ && $9 == 500' /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head
| Where | Indicator |
|---|---|
| PHP and web server error log | Series of “Allowed memory size exhausted” errors that correlate with multipart POSTs |
| Access log | Bursts of HTTP 500, multipart POSTs to pages that have no upload form |
| Process supervision | PHP workers that crash and respawn, segmentation faults in dmesg |
| Requests | PHP_SESSION_UPLOAD_PROGRESS field together with a file part and many repeated array fields, a deliberate pause of more than a second in the body, large bodies without a usable Content-Length |
| Responses | Unusually long or malformed PHPSESSID cookies: one variant leaks process memory this way |
| After a successful attack | A PHP or web server process that starts a shell |
Cloudflare observed attack traffic from 21 October 2026, 03:02 UTC, about nine hours before the disclosure, with payloads that were changed to get past filters. Honeypots recorded successful shell executions on 24 October. Detailed persistence artefacts have not been published, so hunt for the generic ones: new cron jobs, new files in web roots and temp directories, outbound connections of PHP processes.
Scanner results need care. Tenable describes a direct check that combines an allocation size difference with a crash and recover pattern, and states that it misses some vulnerable systems and flags some patched ones. Version checks give false positives on patched distribution packages. Use both, and trust neither alone.
What to do
Update and restart every worker. The PHP project is unambiguous: there are no complete mitigations.
- Update PHP to 8.2.35, 8.3.36, 8.4.27 or 8.5.13, or to the fixed package of your distribution. On 8.5, go to 8.5.13, not 8.5.12.
- Restart all workers:
systemctl restart php8.3-fpm, a full restart of Apache with mod_php, new containers. Long-running workers keep the old code in memory. - Order by exposure: internet-facing management interfaces and appliances first, then end-of-life branches, then the rest. Ask appliance vendors for a statement if none is published.
- Rebuild images. A tag like
php:8.3-apacheis only fixed after a pull and rebuild. Check the digest that is running. - Review logs back to mid October 2026 with the indicators above. Where you find crash series or shells, treat the host as compromised: isolate, rotate credentials the PHP process could read, rebuild from a known state.
If you cannot update today
These settings close single paths. The advisories state that they do not make an installation safe.
| Setting | Effect | Limit |
|---|---|---|
session.upload_progress.enabled=0 | Closes the session path of 109619 | Backtrace and INI paths and 109618 remain |
fatal_error_backtraces=0 (8.5 only) | Removes the confirmed producer on 8.5 | Not relevant on 8.4 and older |
memory_limit=-1, enforced by the administrator | Removes the usual trigger of 109618 | longjmp() still fires if the system itself runs out; opens the door to memory exhaustion |
Conservative post_max_size, max_input_nesting_level, part and header limits | Makes the memory limit harder to reach | Raises the effort only |
pm.max_requests=1 (PHP-FPM) | Breaks the two-request chain | Noticeable performance cost |
| WAF rules | Blocks known request shapes | Attackers changed payloads within hours |
Do not use RLIMIT_AS or RLIMIT_DATA as a brake: the advisory warns that they can make things worse. All settings need a restart of the workers.
Hardening that limits the damage
None of this prevents the memory corruption. It decides what the attacker can do afterwards:
- One FPM pool per application, each with its own low-privilege user, so that one compromised site does not read the others.
disable_functionsforsystem,exec,shell_exec,passthru,proc_open,popenwhere the application does not need them, and a tightopen_basedir.- Egress filtering for PHP hosts and containers.
- Read-only root filesystem in containers, with a writable temp directory only where needed and no write access to the web root.
- Management interfaces off the internet. Most of the appliances hit by this did not need to be reachable.
What it means for a penetration test
PHP2Shell is a reminder that the runtime is part of the attack surface. In a web application penetration test the application can be flawless and the server still falls. That is why we look at the stack below the application as well: which runtime in which build, which SAPI, which settings, what a compromised worker can reach. We verify exposure through versions, configuration and safe checks, and we do not crash production workers to prove a point.
FAQ
Frequently asked questions
Is my application affected if it does not use sessions or file uploads?
Yes, it can be. The multipart parser and the upload progress handling run before any application code, and session.upload_progress is enabled by default. According to the researchers, no session_start() call and no upload form are needed. What decides the risk is the PHP version, the SAPI and the configuration, not the application.
Which setup is most at risk?
Apache with mod_php. The PHP project validated complete remote code execution there with default limits. PHP-FPM is susceptible under more conditions: the session path was validated against a normal dynamic pool, other paths need a matching configuration. Network appliances with a bundled PHP are a special case, because one firmware build is the same on every device.
Are the workarounds enough?
No. The PHP project states that there is no complete mitigation and that updating is the only safe choice. Disabling upload progress or backtraces closes single paths and leaves others open.
We run a distribution package with an old version number. Are we vulnerable?
Not necessarily. Debian, Ubuntu and Red Hat backport the fix into their own package versions, for example 8.3.6-0ubuntu0.24.04.13 on Ubuntu 24.04. Compare the package version with the advisory of your distribution, not with the upstream number.