PHP2Shell in one paragraph
PHP2Shell is the nickname for two vulnerabilities in the PHP interpreter, CVE-2026-109618 and CVE-2026-109619, disclosed on 21 October 2026. Both come from the same place: when PHP hits its memory limit mid-request, it historically used a long jump (internally a "bailout") to abandon whatever it was doing and report the error. The problem is that the abandoned operation can leave the interpreter in a broken state, with a data structure half-built or a global pointer still aimed at memory that has been freed. A later step then uses that broken state. One CVE covers the half-built structure path, the other covers the stale-pointer path, and chained together they can give an unauthenticated attacker code execution as the web server user. No login and no vulnerable application code are required; this PHP vulnerability pair lives in the interpreter itself, so it affects servers regardless of what they run.
CVE-2026-109618: a half-built hash table
PHP stores request data ($_POST, $_FILES) in hash tables. When it adds an entry, it increases the element counters first and then allocates the key:
/* Zend/zend_hash.c, _zend_hash_str_add_or_update_i() (excerpt) */
idx = ht->nNumUsed++;
ht->nNumOfElements++; /* counted as present... */
p = ht->arData + idx;
p->key = key = zend_string_init(str, len, ...); /* ...but allocated here */If that zend_string_init() is the allocation that exceeds the memory limit, the bailout fires and leaves a bucket that is counted as a live element but was never filled in. When the request ends, PHP walks its superglobals to clean them up, reaches that empty bucket, treats it as a real value, and runs a destructor on leftover heap contents. That is the memory-corruption primitive. In practice this path has been demonstrated on Apache with mod_php, because there the shutdown cleanup still runs even after startup failed.
CVE-2026-109619: stale state reused by the next request
PHP worker processes handle many requests in a row and keep some state between them. Several global pointers, for error handling, sessions, and the deserializer, can be left pointing into a request's memory after that memory is freed, if a fatal error interrupted the code that should have reset them. The next request on the same worker then uses the freed memory before normal initialization runs. This is a classic use-after-free, split across two requests.
PHP confirmed two concrete paths. One is the PHP 8.5 fatal-error backtrace feature, where leftover backtrace state is read by an early configuration warning in the next request. The other is session upload progress, where interrupted session or deserializer bookkeeping is reused; this one affects both mod_php and PHP-FPM. The session path is why this bug is also an insecure deserialization issue: the stale state feeds PHP's unserializer, one of the most dangerous functions to point at attacker-adjacent data.
PHPSESSID response cookie, leaking a chunk of worker memory to the attacker, even on an app that never calls session_start(). That leak is how an attacker defeats address randomization before attempting corruption. It is also an easy thing to watch for: an unexpectedly long or binary Set-Cookie: PHPSESSID=.How the pieces combine (at a high level)
We will not publish a working chain, and the researchers who found these bugs deliberately withheld the memory-grooming detail, the offsets and the combined script. What is public is the shape:
- A leak (the PHPSESSID memory disclosure) to learn where things are in memory.
- A corruption primitive (the half-built bucket, or the stale pointer the next request trusts).
- From there, command execution as the web server user, for example the Apache worker running as
www-data.
For the use-after-free path the attacker needs the setup request and the follow-up request to land on the same worker, which is why single-worker and low-worker servers are easier to hit, and why researchers observed attackers opening many stalled uploads to occupy other workers. This matches the broader pattern we describe in our explainer on zero-day vulnerabilities: a leak plus a corruption bug, combined.
What the fix changed
PHP's fix, titled "Avoid state corruption via bailout", stops the dangerous long jump. Out-of-memory errors are now recorded and raised at a safe point instead of abandoning the current operation, and a second, higher "hard limit" cleanly ends the process if memory keeps climbing.
/* Zend/zend_execute_API.c, reset globals before anything can read them (excerpt) */
+ /* may be used by zend_error_zstr_at before init_executor */
+ ZVAL_UNDEF(&EG(last_fatal_error_backtrace));
+ EG(record_errors) = false;
+ EG(num_errors) = 0;
+ EG(errors) = NULL;
+ EG(exception) = NULL;Alongside that, the fix clears session and deserializer state early in each request, limits the per-part headers that let an attacker amplify memory use, and stops reading a body once it exceeds post_max_size. A new memory_hard_limit_percent setting controls the hard limit. One operational note: on patched servers you may now see the process exit when memory is truly exhausted, which is expected behavior, not a new problem.
Which servers are most at risk
| Setup | Risk | Why |
|---|---|---|
| Apache + mod_php | Highest | Shutdown cleanup runs even after a failed startup, which reaches the corrupted structure. PHP names this the top-risk setup |
| Single-worker or low-worker servers | Higher | The two-request use-after-free needs both requests on one worker, which is easier with few workers |
| PHP 8.5 with fatal-error backtraces on | Higher | Enables the confirmed backtrace reuse path |
| PHP-FPM | Conditional | Susceptible by analysis; the session upload-progress path is validated. Startup-failure kills the worker, which blocks the simplest variant |
| End-of-life PHP (7.x, 8.0, 8.1) | Unpatched | Only source-level backport branches exist, no binary release. Move to a supported version |
This hits classic shared hosting and older LAMP stacks hardest. It also reaches PHP embedded in appliances: a suspected state-linked actor was reported chaining PHP2Shell with a Linux kernel bug to compromise internet-exposed PAN-OS firewall management interfaces, so this is not only a website problem.
Detection
Several vendors shipped rules on disclosure day. The strongest signal is in the error log.
- The memory-exhaustion line.
PHP Fatal error: Allowed memory size of N bytes exhausted (tried to allocate M bytes) in Unknown on line 0. "Unknown on line 0" means the failure happened during body parsing, before any script ran. A burst of two to four on one worker can be the setup step even without a crash. - Apache segfaults.
AH00052: child pid ... exit signal Segmentation fault (11)after those errors suggests failed exploitation attempts. - Suspicious request shapes. Multipart POSTs with hundreds of parts and many empty file controls in a small body, machine-generated nested field names, chunked multipart bodies, or an urlencoded POST with one very large field name. Also POSTs carrying
PHP_SESSION_UPLOAD_PROGRESSorPHPSESSIDwhere the app does not use them. - The leak in responses. An unusually long, percent-encoded or binary
Set-Cookie: PHPSESSID=. - Follow-on behavior. A PHP worker (
php-fpm,apache2,httpd) spawning a shell or interpreter, reading.envor cloud metadata, or writing a new.phpfile into the web root.
Published rules you can adapt include Elastic's "Potential PHP2Shell Exploitation Attempt" (which keys on the error-log line above), Datadog's web-shell and session-exhaustion rules, Cloudflare's managed WAF rules for these CVEs, and community Sigma and ModSecurity rules. Note that a successful attack can return a normal HTTP 200 and leave the worker running, so status codes alone are unreliable.
What to do
- Update PHP to 8.5.12, 8.4.27, 8.3.36 or 8.2.35 (or your distro's backport). PHP is explicit: "There are no complete mitigations, updating is the only safe choice."
- If you cannot patch immediately, turn off session upload progress (
session.upload_progress.enabled=0) where the app does not use it, and on PHP 8.5 setfatal_error_backtraces=0. These close specific paths, not the whole class. - Tighten body limits at the proxy, including on chunked and lengthless requests, since those bypass PHP's own size check on older builds.
- Prefer PHP-FPM over mod_php where you can, and avoid single-worker configurations on internet-facing servers.
- Move off end-of-life PHP. 7.x, 8.0 and 8.1 get no binary fix.
If you run PHP applications and want to know which of your hosts are exposed and how they would hold up, an application security test can check your real configuration rather than a version string.
Sources

Need a hand with this?
Talk to a senior consultant. We reply within one business day with clear next steps and a scoped quote.
Prefer to just ask? Contact us and a consultant will reply.
Written by
Vince AntonioSecurity writer and consultant, NextGarrison
Vince writes NextGarrison's security news, technical vulnerability write-ups and guides. He covers actively exploited flaws, penetration testing, SOC monitoring and getting ready for SOC 2, ISO 27001 and PCI DSS, in plain English with sources for every claim.
Want the next alert like this one?
New vulnerability alerts as soon as we publish them. Free, no sign-up, works in Feedly, Outlook, Slack and Teams.
