php2shell: Turning a forced out-of-memory into someone else's secrets
A deep teardown of CVE-2026-109618 and CVE-2026-109619: the PHP use-after-frees where one forced out-of-memory leaks freed worker memory through the PHPSESSID cookie, and how that becomes RCE.
php2shell is the nickname for two PHP core bugs disclosed in October 2026, CVE-2026-109618 and CVE-2026-109619, both rated CVSS v4.0 9.2. Neither is an injection bug you can grep out of your application. They live in the interpreter's own memory management, and they turn a mundane out-of-memory error into a cross-request data leak and, with work, remote code execution.
The TL;DR
- Two use-after-free bugs in PHP core, present in every release since 5.4.0 (shipped 2012).
- A remote attacker triggers them by forcing an out-of-memory error mid-request, which makes PHP skip cleanup and leave freed objects dangling in a reused worker.
- The upload-progress handler can serialize freed worker memory straight back to the client inside a
PHPSESSIDcookie, leaking other users' passwords, tokens, API keys, even TLS private keys. - Fixed in PHP 8.2.35, 8.3.36, 8.4.27 and 8.5.12. Exploited in the wild and added to CISA KEV.
This is a memory-safety bug, not input validation. The real fix is a runtime upgrade, not a code review.
The bug class: OOM, longjmp, and worker reuse
The common thread behind both CVEs is deceptively simple. A fatal error during a request, typically an out-of-memory error when a request crosses the configured memory_limit, interrupts native PHP code before it finishes cleaning up. PHP uses longjmp() to unwind out of the failed allocation, and that non-local jump skips the normal teardown path. Freed objects are left referenced.
Because PHP-FPM and mod_php keep long-lived worker processes and round-robin requests across them, that dangling state survives into the next request handled by the same worker. In a request-per-process model the freed memory would die with the process. Here it lingers, and that is the whole game.
CVE-2026-109618: upload-progress unserializer UAF
PHP has a feature called session upload progress. When a multipart/form-data request arrives with a specially named field, PHP tracks upload progress in session storage so a page can poll it. Crucially, this handler runs before your application code, and even when the application never calls session_start().
The handler unserializes and manipulates session state while the body is still streaming. If the request is shaped so that an allocation inside that path crosses memory_limit, the OOM handler longjmps out and leaves an upload-progress structure freed but still referenced. On the next request serviced by that worker, the stale pointer is used before re-initialization.
The nastiest part is the disclosure channel. The upload-progress handler can serialize worker memory back into the response as a PHPSESSID cookie. That freed region is never scrubbed, so it can contain whatever the previous request left behind.
CVE-2026-109619: fatal-error backtrace UAF and OPcache type confusion
The sibling bug reaches the same freed-state condition through a different door. When PHP builds a backtrace for a fatal error, request-owned internal state can survive after its backing memory has been freed. Combined with an OPcache type confusion, a later request on the same worker can use that stale state before normal initialization resets it, letting an attacker reinterpret one object type as another.
Type confusion is a powerful primitive because it hands you a fake object whose fields you partially control, which is the usual on-ramp from an information leak to a controlled write.
Why one OOM gives you someone else's secrets
The attack is not really about your request at all. You force a worker into a dirty state, then either read back what a different user's request left in that worker, or reclaim the freed object with data you control and pivot toward code execution. Leaked data can include passwords, session tokens, API keys and TLS private keys from unrelated requests, which is why a bug with no obvious injection point rates a 9.2.
Reproducing the memory leak
The disclosure variant is the easiest to demonstrate. You send multipart/form-data requests tuned to push the worker across its memory_limit during upload-progress handling, then read the Set-Cookie: PHPSESSID=... value out of the response.
# Repeatedly POST a multipart body sized to trip memory_limit during
# upload-progress handling, and watch the session cookie that comes back.
for i in $(seq 1 50); do
curl -sS -D - -o /dev/null https://target.example/upload.php \
-H 'Content-Type: multipart/form-data; boundary=x' \
--data-binary @big_multipart_body.bin \
| grep -i '^set-cookie: PHPSESSID'
doneAcross enough requests, the returned cookie value starts carrying bytes that were never yours. Public proof-of-concepts generally do not fire against a stock configuration, because reliable OOM shaping needs knowledge of the target's memory_limit, PHP version and allocator state. That is a reliability bar, not a security control.
Attack chain
Shape a multipart upload
Craft a multipart/form-data request sized to cross memory_limit mid-request.
Force an out-of-memory error
longjmp unwinds out of the failed allocation and skips PHP's cleanup.
A reused worker inherits the dangling state
The upload-progress object is freed but still referenced by the next request.
Leak stale memory via PHPSESSID
The response cookie hands back unscrubbed worker memory: tokens, keys, secrets.
Reclaim the freed object
Groom allocations so attacker data lands in the freed region.
Type confusion to code execution
A controlled fake object turns the read primitive into RCE.
The patch
The fix landed in php-src commit 3584a98bda0f, tellingly titled "Avoid state corruption via bailout" (Arnaud Le Blanc, with Ilija Tovilo, Jakub Zelenka, Nora Dossche and Nicolas Grekas). It has two halves: stop the dangerous unwind, and stop the early upload-progress code from ever running attacker objects.
Half one: kill the longjmp out of OOM
The root cause was that an out-of-memory error called zend_bailout() to longjmp() straight out of a running allocation, skipping cleanup and leaving worker globals pointing at freed or half-initialized memory. The patch removes that path in Zend/zend_alloc.c and replaces it with a deferred error the VM raises at the next safe point.
-/* before: bail out of the request mid-allocation */
-static void zend_mm_safe_error(zend_mm_heap *heap, const char *format, ...)
-{
- heap->overflow = 1;
- zend_error_noreturn(E_ERROR, format, /* ... */);
- zend_bailout(); /* longjmp() to the nearest zend_try */
-}
+/* after: queue the error, let the engine raise it between opcodes */
+static void zend_mm_delayed_verror(zend_mm_heap *heap, const char *format, va_list ap)
+{
+ EG(delayed_oom) = zend_oom_capture(format, ap); /* message, file, line */
+ EG(vm_interrupt) = 1; /* checked at safe points */
+}
+
+/* hard backstop: too far past the limit to unwind safely */
+static ZEND_NORETURN void zend_mm_hard_limit_error(void)
+{
+ _exit(137); /* no cleanup, no worker reuse */
+}A "soft" OOM is now deferred to the next VM safe point, where cleanup is well defined: zend_execute_scripts() checks EG(delayed_oom) after execution and zend_deactivate() frees it. A "hard" OOM past a higher threshold skips cleanup entirely and calls _exit(), so a corrupted worker never services another request.
Half two: never run user objects during upload progress
The disclosure channel was the session upload-progress handler unserializing data before RINIT, which could trigger __wakeup(), __unserialize() or autoloading on attacker input. The patch guards that path with a flag and decodes everything as an inert __PHP_Incomplete_Class.
PHPAPI void php_session_rfc1867_update(/* ... */)
{
+ PS(in_rfc1867_update) = 1; /* guard the early path */
+ php_var_unserialize_set_incomplete_classes_only(1);
php_session_decode(val); /* now yields inert objects only */
+ if (EG(exception)) { PS(in_rfc1867_update) = 0; return; }
}
PHPAPI void php_rinit_session_globals(void)
{
+ PS(in_rfc1867_update) = 0; /* reset per request */
/* ... */
}With no __wakeup() or autoload reachable before the request is initialized, and no longjmp leaving freed globals behind, both the information leak and the type-confusion write are closed. The two issues are tracked as GHSA-w8hw-w9fx-j79w (109618) and GHSA-6wmf-4rv5-p3rp (109619).
Am I affected?
Vulnerable: PHP 8.2 before 8.2.35, 8.3 before 8.3.36, 8.4 before 8.4.27, and 8.5 before 8.5.12. The underlying code exists back to 5.4.0, so older unsupported branches are affected too and will not get a fix. If you run PHP-FPM or mod_php and accept file uploads anywhere on the host, assume you are reachable.
Detection and threat hunting
Hunt the trigger and the leak together:
- Spikes of
multipart/form-dataPOSTs, especially many requests to one endpoint from a single source. - PHP OOM and
memory_limitfatal errors clustered in time, which is the signal of someone shaping the heap. - Anomalous
Set-Cookie: PHPSESSIDvalues with unusually high entropy or non-standard content.
Mitigation and patching
Patching is the real fix: upgrade PHP to 8.2.35, 8.3.36, 8.4.27 or 8.5.12. If you genuinely cannot patch immediately, the interim options are blunt:
# Reject multipart uploads at the edge until PHP is patched.
if ($content_type ~* "multipart/form-data") {
return 403;
}session.upload_progress.enabled = 0
; Removing the cap removes the OOM that longjmp mishandles.
; Only safe if the host cannot be pushed into true memory exhaustion.
memory_limit = -1These interim steps only narrow the known upload-progress vector. They do not remediate the underlying out-of-memory state corruption, so treat them as speed bumps, not a fix. Only the patched PHP releases actually close the bug.
Key takeaways
- The bug you cannot see in your code can still be the one that owns you. This lives in the interpreter, below your app.
- Worker reuse turns a transient memory bug into a cross-request oracle. php2shell leaks other users' secrets precisely because workers are long-lived.
- A PHP OOM cluster is a security event, not just reliability noise. Alert on it.
- Inventory beats cleverness. Know your PHP minor versions and you already know your exposure.
See the companion teardown of the JVM side in java4shell.
References
- PHP, php-src commit
3584a98bda0f"Avoid state corruption via bailout" - GitHub Advisory GHSA-w8hw-w9fx-j79w and GHSA-6wmf-4rv5-p3rp
- Corgea, How PHP's longjmp OOM path became pre-auth RCE
- Sansec, PHP2Shell research
- watchTowr, PHP CVE-2026-109618 FAQ
- Tenable, php2shell FAQ
- NCSC-NL, php2shell operational information