PHP2Shell: Turning upload progress into pre-auth RCE
Updated ResearchCVE-2026-109618 · CVE-2026-109619
TL;DR: PHP parses a multipart POST before the requested script runs. On a tested PHP 8.5.11 Apache build, a six-request HTTP chain exploited stale session state (CVE-2026-109619) and returned uid=33(www-data). A separate core trace placed the native command call beneath PHP's multipart parser. I also reproduced an unfinished-HashTable failure associated with out-of-memory handling (CVE-2026-109618), but did not capture that specific bucket failure in the successful six-request chain.
I wanted to answer a narrower question than “can multipart crash PHP?” A crash could be a bad pointer, an allocator check, or a memory-limit exit. To call this RCE, I needed a chain from bytes I sent, through a specific native consumer, to command output that the page itself could not produce. The first local runs found that chain one link at a time. The final HTTP-only run supplied the addresses it needed from the target's own responses.
PHP's OOM advisory and stale-state advisory credit lcfr-hax, sagitzadik-wiz, tomash-areion, and amyb-oai as reporters. This post follows the source and reproduces one exploit chain.
What the six requests accomplished
The saved compact attempt reached an ordinary WordPress 7.1.3 login route backed by the official PHP 8.5.11 Apache module. The page had no command handler. The client obtained the heap and module addresses for its final request from HTTP responses; the application did not supply an execution gadget.
| Pair | Producer request | What the next request observed |
|---|---|---|
| A1 → B1 | Multipart parsing reached the PHP memory limit. | A 64-byte decoded session cookie disclosed a heap pointer. |
| A2 → B2 | A second multipart OOM prepared different memory reuse. | A 16-byte decoded cookie disclosed a PHP module pointer. |
| A3 → B3 | A third OOM left session state for the next request. | The HTTP body contained the operating-system account output shown below. |
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Here, A means a request that leaves state behind and B means the next request that consumes it. All six compact stages returned HTTP 200, including the three whose bodies contained PHP memory-limit errors. A post-run health read-back also returned an ordinary HTTP 200 page. The saved compact result proves one HTTP-only RCE outcome on this deployment; it does not include backend PID logs for every stage. An earlier, larger run supplied the private-origin core discussed below and showed the native command routine running before application code. Its Apache child segfaulted after producing command output. The two runs are separate evidence, not one reconstructed transcript.
The demonstrated chain depends on a reused worker, visible response cookies, and offsets for the exact libphp.so build. I follow that chain first, then return to the separate OOM diagnostic.
Contents
- The upload is parsed before the page runs
- The boundary between one request and the next
- The demonstrated chain: state outlives its request
- Getting the two addresses the payload needs
- Turning the stale session reference into a call
- What the successful core dump actually shows
- Measured sizes in the compact six-stage run
- Where application code fits
- Separate diagnostic: an unfinished HashTable entry
- What each piece of evidence proves
- What changed in the fixed PHP source
- What fixes it
- Source and evidence
The upload is parsed before the page runs
PHP decodes a multipart POST before the requested script receives control. The session extension registers an RFC 1867 upload callback. With the default session.upload_progress.enabled=1, a request containing the configured progress field and session ID reaches that callback; file parts trigger its progress updates. The page need not implement an upload handler or call session_start().
HTTP multipart body
|
v
PHP request startup -> multipart parser -> session progress callback
| (before requested PHP script)
v
application script
The order is visible in PHP 8.5.11's request startup: php_hash_environment() runs before module activation. The session extension registers the callback, and the multipart parser invokes it while building POST data. This explains the entry point. It does not mean every page accepting a multipart body is exploitable.
Three C terms matter here. A zval is PHP's tagged value. A HashTable backs arrays such as $_POST and stores those values in buckets. ZendMM is PHP's request allocator. An Apache prefork child keeps serving requests after ZendMM releases one request's allocations. If a worker global still points into that released memory, the next request can reuse the same address for different bytes.
The upload callback is a state machine
The multipart parser does not hand one finished form to the session extension. It calls the extension as it moves through the body. The callback's event switch is the shortest way to understand why field order and file parts matter:
| Event | What PHP records | Why it matters here |
|---|---|---|
| START | Allocate a fresh progress structure. | Replaces the old progress-structure slot. |
| FORMDATA | Recognize the multipart session ID and progress marker. | These are PHP-recognized names, not application fields. |
| FILE_START | Create progress arrays, set the session ID, and cache counter zval pointers. | The A requests publish session state before later allocations fail. |
| FILE_DATA | Write processed-byte counts through the cached pointers. | This was the original same-upload UAF hypothesis. |
| END | Run session cleanup when the ID and marker were seen. | A B request can reach session code without carrying a real file. |
This ordering explains an otherwise odd feature of the six-stage client. A1 has a real file part; A3 has many empty file controls; B1, B2, and B3 use the session ID and progress marker but need no file data. The END event still reaches php_session_rfc1867_cleanup() when those two fields were recognized. The application script has not yet run in any of those cases.
The boundary between one request and the next
An Apache prefork child loads libphp.so and can handle many HTTP requests over its lifetime. PHP uses ZendMM for much of one request's temporary data, then discards that memory at shutdown. The session extension also has PS(...) globals associated with the worker. Those globals are only safe across the boundary when their request-owned contents have been reset before ZendMM frees the backing allocations.
In php_request_startup(), the crucial ordering is php_hash_environment(), then zend_activate_modules(), then PG(modules_activated)=1. The multipart body is decoded in the first step. If parsing hits PHP's memory limit there, Zend's bailout jumps to the startup failure handler before the activated flag is set. Apache's handler still runs request shutdown.
request startup:
php_hash_environment() <-- multipart and session progress run here
zend_activate_modules()
PG(modules_activated) = 1
request shutdown after early bailout:
if (PG(modules_activated)) zend_deactivate_modules()
destroy request superglobals
release request allocator memory
The condition on module RSHUTDOWN explains why session-owned fields can miss their normal reset, while the later superglobal and allocator cleanup explains why their old targets no longer belong to that request. The same ordering also explains how the current request's partially initialized HashTables can be visited during shutdown. It is possible to observe both symptoms around one OOM without proving they share one exact corrupting instruction.
The demonstrated chain: state outlives its request
The upload-progress callback creates a php_session_rfc1867_progress structure in request memory. Its two zval * fields cache progress counters, which initially looked like the obvious dangling pointers. Source inspection changed that hypothesis. In the update path, PHP increments the progress array's refcount before placing it in the session:
Z_TRY_ADDREF(progress->data);
zend_hash_update(Z_ARRVAL_P(sess_var), progress->key.s, &progress->data);
Replacing a value in $_SESSION therefore does not, by itself, prove that the progress structure's own array and its buckets were freed. A new multipart START also replaces PS(rfc1867_progress). I could not justify the proposed same-upload “old tree replaced by new tree” story from those ownership rules. The cross-request pointers below have direct diagnostic support.
The suggested one-second pause is another clue that points to a different path. session.upload_progress.min_freq throttles periodic calls to php_session_rfc1867_update(); it does not guard the END cleanup that the no-file B requests use. The verified compact chain sent sequential requests without pausing a file stream for a second FILE_DATA event. That distinction matters because timing claims can sound precise while identifying the wrong consumer.
The stronger finding was across requests. Session module globals include PS(id), a zend_string *, and PS(http_session_vars), a zval containing a reference to the session array. A normal session reset releases both. But a memory-limit bailout during early POST parsing occurs before the usual module activation has finished. Apache still enters PHP request shutdown; module RSHUTDOWN runs only if modules were activated. ZendMM then releases request memory while those worker-global pointers can still name it.
request A same worker, request B
--------- ----------------------
publish PS(id), PS(http_session_vars)
OOM before normal reset
free A's ZendMM allocations -> allocate new form values there
parse upload before userland
read or destroy stale state
GDB trace excerpt — the same addresses after a new request. A separate, controlled two-request run stopped inside php_session_track_init() both times. These lines are from the saved trace with the high address digits shortened:
TRACK_INIT_HIT 1 ID_PTR=0x...6230 REF_PTR=(nil)
SESSION_FLUSH REF_PTR=0x...5140
TRACK_INIT_HIT 2 ID_PTR=0x...6230 REF_PTR=0x...5140
first ID string: b733...43f1
second ID string: 041a...3415
The pointer addresses persisted while the bytes at those addresses changed with the next request. A no-progress producer control did not produce the same session-file behavior. This is direct evidence of stale session pointers on a reused worker, although this particular diagnostic did not execute a command.
The next request can consume the stale reference surprisingly early. A progress-bearing multipart body reaches its END callback, which calls php_session_initialize(). That reaches php_session_track_init(). Before installing a new session reference, it calls zval_ptr_dtor(&PS(http_session_vars)) on the old one. If that old pointer now names attacker-arranged bytes, a perfectly ordinary “replace the session” operation becomes the consumer.
This cross-request producer/consumer pattern is CVE-2026-109619. Its defining feature is the lifetime mismatch: one request owns the allocation, but a persistent worker global still names it when the next request starts.
Getting the two addresses the payload needs
At this point I had a same-worker stale-pointer primitive and controlled allocations, but no portable native call. Address-space randomization moves both the ZendMM heap and libphp.so. Hard-coding the addresses that GDB displayed would make a convincing local demonstration and a useless remote client. The next two request pairs turned the stale session ID into an HTTP-visible disclosure.
A1 → B1: a 64-byte session cookie reveals a heap pointer
A1 submits ordinary form fields, a NUL-leading multipart PHPSESSID, the upload-progress field, a real file part, and then the short-header amplifier. PHP's max_input_vars warning at the 1,001st ordinary field does not prevent the progress callback from seeing the later fields. The NUL-leading ID makes the session path generate a replacement ID. A separate GDB calibration caught an OOM while URL-encoding that ID for Set-Cookie, before the usual state reset. The compact A1 response proves OOM; I did not capture that exact compact request's failing allocation in GDB.
B1 sends a valid multipart session ID and 841 small fields before a 79-byte value shaped like a zend_string header. In the tested layout, the value reclaims memory reached through stale PS(id). Its length word is set to 64. PHP's cookie encoder then serializes a 64-byte window as Set-Cookie: PHPSESSID=..., rather than just the expected session ID. This is why the exploit does not need an existing PHPSESSID cookie from the target: the leak is in the response header.
There is no magic in the cookie format. On this x86-64 build, zend_string stores a GC header, a cached hash, its length at offset +0x10, then its bytes at +0x18. php_session_send_cookie() passes ZSTR_VAL(PS(id)) and ZSTR_LEN(PS(id)) to php_url_encode(). If PS(id) names reclaimed memory with a forged length, encoding reads that many bytes. URL encoding changes their wire representation, so the client decodes the cookie before checking byte offsets.
A related local producer calibration showed where one way of preserving this state occurs. The following GDB lines came from that separate test, not the compact A1 request:
URL_ENCODE hit=1 len=32 send_cookie=1
URL_HEAP real_size=134217728 limit=134217728 free_slot128=(nil)
OOM hit=1 url_hits=1 send_cookie=1
BEFORE_MM_RESET url_hits=1 oom_hits=1 send_cookie=1
That trace says the normal 32-byte session ID reached cookie encoding with the allocator already at 128 MiB, and the bailout left send_cookie set until the request heap reset. The compact A1 result confirms an OOM and B1's abnormal cookie, but it does not supply a matching breakpoint at the compact producer's exact allocation failure. The source and calibration explain a viable path; the HTTP result proves the paired disclosure on the tested binary.
URL-decoded B1 PHPSESSID value: 64 bytes
offset 0x00 ... 0x37 controlled / reclaimed string bytes
offset 0x38 pointer into ZendMM's main 2 MiB chunk
heap base = pointer & ~0x1fffff
checked on this binary: pointer - heap base == 0xa70a0
The 2 MiB alignment comes from this ZendMM layout, and 0xa70a0 is a measured offset for the pinned image. The client rejects a cookie that is not exactly 64 decoded bytes or whose pointer fails that profile. The cookie is an information leak, not proof of code execution by itself.
A2 → B2: repeat the producer, then leak a native function pointer
A2 uses the same OOM construction with a different form-value length. That changes allocator placement before B2. B2 then sends 983 nested array field names, with one field expanding to 16 children. The resulting PHPSESSID cookie decodes to 16 bytes. The second eight-byte word points to zval_ptr_dtor in the loaded PHP module. On this exact binary, subtracting its known relative offset yields the libphp.so base:
URL-decoded B2 PHPSESSID value: 16 bytes
offset 0x08: leaked zval_ptr_dtor pointer
libphp base = leaked pointer - 0x7b47a0
zif_system = libphp base + 0x5996e0
The client checks the decoded length and expected module alignment before using the result. The second formula is build-specific: zif_system is PHP's internal implementation of the system() function, not libc's system. A version banner cannot establish these offsets. The two cookie disclosures make the final payload independent of fixed process addresses while remaining tied to this particular libphp.so build.
For this offset profile, I verified the local official image digest and the SHA-256 of its Apache PHP module:
image: php:8.5.11-apache@sha256:47e6d8849049375e0d19e81f1b391ed88828d4653e0d1b00822185b66b564e8b
libphp.so: sha256:2c80ca2a245ca1ccca9946f30ebeca210b9689bc24f2bd07eda717d70108ee5d
The origin operator reported the same module hash; I did not retrieve and hash that origin binary myself. These identifiers describe the tested binary profile, not every installation showing PHP 8.5.11.
I did not label the second eight-byte word a code pointer just because its high bits looked like an address. In a separate local validation series using the same stock PHP module and an earlier, larger producer, five fresh Apache master starts returned a 16-byte decoded cookie. Subtracting 0x7b47a0 from its second word matched the actual libphp.so mapping in /proc/1/maps after each request. That map check was diagnostic read-back, never an input to the HTTP-only client. It supports the symbol interpretation for this build; it does not tell us which native allocation supplied those eight bytes in the compact B2 layout.
Turning the stale session reference into a call
The conceptual chain is short even though its byte layout is not: a stale session global names a freed reference slot; B3's form values reclaim that slot with a reference to a forged array; destroying the array uses its forged destructor pointer. The two earlier cookie leaks supply the heap and module addresses required to construct those values for the running process. The field numbers and offsets below belong to the pinned x86-64 build.
The third producer, A3, takes a different route to the 128 MiB limit. It has 880 empty-filename file controls with 62 nested [a] components in each name. An empty filename avoids real file data, but the parser still builds $_FILES metadata arrays; FILE_START runs before the empty-file decision. A local GDB calibration found that this OOM left PS(http_session_vars) pointing at a 32-byte reference slot at main heap base +0x7a720. The saved compact A3 request returned the expected memory-limit error. Its exact failure instruction was not separately traced.
Measuring where the B3 values land
B3 does not simply “spray a fake function.” Its 995 fixed-size form values have two measured jobs. In the local layout, value 33 lands where the stale session reference will be destroyed. That 32-byte region is shaped as a zend_reference whose inner zval says “array” and whose pointer names a forged HashTable. Value 994 lands on the old PS(id) allocation; it sets a bounded length of 32 so session ID handling can continue instead of trying an enormous allocation. A separate ht field supplies the 384-byte forged HashTable at main heap base +0xf5398. These carrier positions were measured with tagged fields in GDB, then used by the HTTP-only client after B1 supplied the actual heap base.
To find those positions, I first gave each candidate reference a different numeric tag. A GDB stop at multipart END showed tag 0x21 at the stale session-reference address and tag 0x3e2 at the stale SID address. In decimal, those are fields 33 and 994. The same trace found the ht bytes at two positions, including main chunk +0xf5398. This is placement evidence, rather than an assumption that a large spray will eventually hit the right object:
B2_REF at A2 stale reference address:
tagged word = 0x...0021 --> form value 33
B2_SID at old session ID address:
tagged word = 0x...03e2 --> form value 994
HT_MARKER_LOCATIONS:
main chunk + 0xf5398
main chunk + 0xf5558
Each of the 995 values is 384 bytes and carries eleven copies of a 32-byte reference-shaped pattern at different offsets. The real PS(http_session_vars) global is not itself overwritten: it still holds its old pointer. The allocation at that pointer is what B3 reuses. Field 33 sets the forged reference count to one so the next destruction reaches zero and destroys its inner array; a count of two would only decrement. Field 994 repairs a second problem discovered in the tagged run. Its marker was interpreted as a huge zend_string.len in stale PS(id), causing another OOM inside php_session_reset_id() before the desired destructor. Setting that word to 32 preserved the same placement while allowing session cleanup to continue.
stale PS(http_session_vars) --> reclaimed reference (field 33)
inner zval: array
array pointer: heap base + 0xf5398
stale PS(id) --> reclaimed string header (field 994)
bounded length: 32
forged HashTable --> pDestructor: libphp base + 0x5996e0
first bucket overlaps a PHP call frame
argument string: "id"
A HashTable that also looks like a call frame
The separate ht value is not only a table with a changed callback. Its 384 bytes serve two purposes at once. zend_array expects a bucket pointer, counts, and a destructor. PHP's internal call frame expects a different arrangement of pointers and argument zvals. The payload overlaps the first bucket with enough of that second arrangement to survive entry into zif_system:
Offset in ht | Role in this measured build |
|---|---|
+0x00 | Refcounted array header. |
+0x10 | arData points back to ht+0x20. |
+0x18 | One used bucket and one element. |
+0x20 | First bucket value, also interpreted as the start of a call frame. |
+0x30 | pDestructor points to zif_system. |
+0x70 | Inline string zval points to a zend_string at ht+0x80. |
+0x90 | Length of the embedded command string. |
+0x98 | Bytes of id. |
zend_hash_destroy() invokes ht->pDestructor(&p->val). The forged table makes that callback land at zif_system. There is an intentional C-signature mismatch: a HashTable destructor receives one zval *, while a PHP internal function expects a zend_execute_data * and a return-value pointer. The overlapped bucket makes the first argument look enough like an execution frame to reach the inline id string. This is not a normal, clean PHP function call or a direct call to libc system. The observed command output followed by a native SIGSEGV is consistent with that partial call context.
GDB trace excerpt — the local native dispatch. This separate diagnostic used GDB-supplied absolute addresses to verify the execution stage before the HTTP cookie leaks were integrated. It stopped first at session replacement, then at the chosen internal function:
TRACK_INIT: stale reference -> forged HashTable bytes
HIT_ZIF_SYSTEM
#0 zif_system()
#1 zend_hash_destroy()
#2 zend_array_destroy()
#3 zend_reference_destroy()
#4 php_session_track_init()
#5 php_session_initialize()
#6 php_session_rfc1867_callback()
#7 rfc1867_post_handler()
That stack identifies the native consumer precisely: php_session_track_init() destroys the old session reference, which reaches the forged table's destructor. The local diagnostic alone was not a remote ASLR bypass. The later HTTP-only six-stage run used B1 and B2 instead of debugger addresses.
What the successful core dump actually shows
An earlier HTTP run on the same tested PHP build produced a private-origin core. GDB trace excerpt — private-origin core. The operator kept the 233 MB core on the origin and shared a sanitized backtrace. This is saved debugger output, not a reconstructed call stack. It came from a larger version of the six-stage request sequence, separate from the compact result below:
Signal: SIGSEGV (11) PC: php_exec + 556
#0 php_exec()
#1 php_exec_ex()
#2 zend_hash_destroy()
#3 zend_array_destroy()
#4 zend_reference_destroy()
[frames 5-7 optimized out]
#8 rfc1867_post_handler()
#9 sapi_handle_post()
#10 php_default_treat_data()
#11 php_auto_globals_create_post()
#12 zend_activate_auto_globals()
#13 php_hash_environment()
#14 php_request_startup()
Read that stack from the bottom upward. PHP was still starting the request and parsing its multipart body. It had not reached application code. A reference was being destroyed, then an array, then a HashTable; the native call landed in php_exec(). In this PHP source, zif_system enters through php_exec_ex(), which calls php_exec(). The client received the matching output before the Apache child segfaulted:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
The saved response from this earlier run began HTTP/1.1 200 OK and contained the complete 54-byte id output shown above, including its trailing newline. The core agrees with the local HIT_ZIF_SYSTEM trace and the HTTP command output: destruction of a session reference reached PHP's internal command routine during body parsing. It does not show the first corrupting write or the complete forged heap layout. The local trace excerpts explain measured transitions; the saved HTTP response records the final effect on this build.
Measured sizes in the compact six-stage run
One compact client attempt sent six sequential multipart POSTs to the owner-controlled login route. The result file preserves each body size and hash, each response status and hash, and whether the expected OOM text appeared. This is the shorter HTTP-only attempt; it used no debugger address as an input.
| Stage | Body | Observed result |
|---|---|---|
| A1 | 2,639,230 B | PHP memory-limit error |
| B1 | 93,685 B | 64-byte decoded cookie; heap pointer check passed |
| A2 | 2,677,268 B | PHP memory-limit error |
| B2 | 83,032 B | 16-byte decoded cookie; code pointer check passed |
| A3 | 279,369 B | PHP memory-limit error |
| B3 | 451,384 B | uid=33(www-data) in the HTTP response |
All six returned complete HTTP 200 responses on the same client connection. HTTP 200 did not mean the A stages were healthy; their bodies contained the memory-limit error. In the earlier run, Apache logs showed that one child handled the request sequence and returned the id output before crashing. That run supplied the private core above. The compact result has no backend PID log attached. Same-worker reuse is load-bearing because stale module pointers live in a process, not in a browser session.
The final payload also depends on visible, parseable Set-Cookie responses and offsets from the exact x86-64 libphp.so build. The stock 128 MiB memory limit, 8 MiB POST limit, enabled upload progress, and Apache mod_php lifecycle were present in the tested image. A different binary, response path, or worker schedule can change placement or prevent the chain. The result establishes RCE on the tested PHP 8.5.11 route; it does not establish a single reliable payload for every PHP build, endpoint, or server mode.
Where application code fits
The core stack places the native command call under php_request_startup(), inside multipart parsing and before the requested PHP script. The application provided an ordinary route, not the command-execution sink. No application command parameter, plugin gadget, or upload handler was needed in the recorded run.
Application behavior can still affect whether the cookie disclosures and final output reach the client: a page may change headers, redirect, emit output, or fail after PHP has parsed the body. Worker assignment matters too. The producer and consumer requests must reach the same persistent PHP worker; one client connection does not prove that a reverse proxy reused one backend connection. The earlier origin logs recorded one Apache child serving the successful sequence. The compact run recorded one client socket but did not capture backend PIDs.
Separate diagnostic: an unfinished HashTable entry
The following experiment isolates one failure mode of CVE-2026-109618. It shows how an OOM can leave a published HashTable bucket unfinished and how shutdown can interpret that bucket. It was not a recording of the first failed allocation in the successful six-request chain above. That distinction matters: an A-stage memory-limit error alone cannot identify which internal allocation failed.
How a small request reaches the memory limit
A 128 MiB PHP memory limit does not require a 128 MiB upload. PHP allocates arrays, strings, and file metadata while decoding multipart parts. The first two producer requests in the saved run each carried 1,001 ordinary fields and a part with hundreds of thousands of short header lines. Their multipart bodies were about 2.64 and 2.68 MB, yet each triggered PHP's 128 MiB memory-limit error. The third producer used 880 empty file controls with deeply nested field names and was about 279 KB. PHP's advisory identifies both the unrestricted per-part header work and nested empty-file metadata as amplification paths.
Those requests used HTTP chunked transfer. The initial post_max_size test compares the configured limit with PHP's declared content length; an unusable length matters for larger variants. All three compact producer bodies were already below the tested build's 8 MiB POST limit. Their ability to reach 128 MiB came from PHP's allocation work while decoding them, not from crossing the initial size gate.
The stock limits in the tested binary govern different things. Treating them as one “maximum upload size” obscures the bug:
| Setting | Stock value | What the compact run showed |
|---|---|---|
post_max_size | 8 MiB | Every producer body fit below it. |
memory_limit | 128 MiB | Multipart decoding still exhausted it. |
max_input_vars | 1,000 | Field 1,001 raised a warning, but the progress callback still saw later fields. |
max_file_uploads | 20 | Empty-filename controls did not consume upload slots, yet generated nested file metadata. |
The short-header part is particularly instructive. In multipart_buffer_headers(), PHP repeatedly copies and stores header lines while parsing a single part. The A1/A2 bodies contain 427,784 repetitions of a tiny X: x line. Each line costs far more than its handful of transmitted bytes once PHP has represented it in strings and list nodes. For A3, FILE_START arrives before the empty filename is checked; the later $_FILES registration still walks the deep field names. Those are two different ways to spend request memory without sending a giant file.
The max_input_vars branch has another sharp edge. At the 1,001st ordinary field, PHP warns and stops registering more values in $_POST, but that branch still invokes the RFC 1867 callback for later form fields. The later session ID and progress marker can therefore affect the session extension even when they are absent from the script's eventual $_POST array.
The table publishes a slot before building it
PHP stores POST fields in HashTables. In the 8.5.11 insertion path, the table's used-entry count increases before the new bucket's key is allocated and its value is initialized. The relevant sequence in Zend/zend_hash.c is:
idx = ht->nNumUsed++;
ht->nNumOfElements++;
p = ht->arData + idx;
p->key = key = zend_string_init(...); // can allocate
...
ZVAL_COPY_VALUE(&p->val, pData); // bucket value comes later
If zend_string_init() hits PHP's memory limit, ZendMM calls zend_bailout(). That is a longjmp: execution leaves the current C stack without returning through the remaining insertion statements. The table can now advertise a slot whose value was never completed. This is a timing problem inside native code, not a malformed PHP array deliberately created by the script.
normal: count slot -> allocate key -> initialize value -> cleanup later
OOM: count slot -> allocation fails -> longjmp
shutdown: walk slots up to the count -> visit unfinished value
Apache's PHP handler still enters request shutdown after a startup failure. Shutdown destroys request arrays, and zend_hash_destroy() walks entries up to nNumUsed and calls the table's normal destructor on their values. The form field does not directly choose that destructor. The danger is that cleanup can interpret an unfinished value as a real PHP value. This illustrates one concrete hazard within the broader OOM issue described by CVE-2026-109618.
nNumUsed is a high-water mark for buckets that destruction will inspect. Incrementing it is not the same as finishing the corresponding bucket. After the bailout, the table's own accounting says “there are two slots” while only the first may have a valid zval and key. The destructor loop trusts that accounting:
arData[0] initialized key + initialized value
arData[1] count already incremented
key allocation or value initialization unfinished
zend_hash_destroy():
end = arData + nNumUsed
for each bucket before end:
ht->pDestructor(&bucket.val)
That final call is a normal part of array destruction. The abnormal part is the value it receives. A zval contains both a type tag and data; if unfinished memory happens to look like a refcounted array, reference, or object, cleanup can follow the apparent pointer. If it is zeroed or marked undefined, cleanup may skip it instead. This is why allocator placement and the exact moment of OOM matter more than the HTTP request's raw size.
GDB trace excerpt — the unfinished bucket. A local PHP 8.5.11 diagnostic stopped at the allocation failure inside zend_hash_str_update_ind(), then at cleanup of the newest bucket. I have omitted only process-specific addresses:
OOM: zend_mm_safe_error
-> zend_mm_alloc_large
-> zend_hash_str_update_ind
-> php_register_variable_ex
-> rfc1867_post_handler
HASH_TABLE ... newest_bucket ...
SECOND_BUCKET_DTOR before: type_info=0x307 referent refcount=1
SECOND_BUCKET_DTOR after: referent refcount=0
The refcount transition is the important observation: shutdown actually treated that unfinished slot as a live value and destroyed what it pointed to. In another deliberately controlled run, the newest bucket contained 0x4242424242424242; shutdown reached zend_array_destroy() with rdi=0x4242424242424242 and faulted. That proves input-shaped bytes could reach native cleanup in the local diagnostic. It is still a controlled crash, not command execution.
There is a useful negative control here. A different file-metadata OOM left a zeroed bucket that cleanup skipped safely. The bug is the possible mismatch between published count and initialized contents; an arbitrary OOM is not automatically exploitable. Also, these debugger runs isolate the HashTable hazard. They do not prove that the compact A1/A2 requests below failed at precisely this allocation site.
From “controlled crash” to “controlled call”
I used a deliberately recognizable 0x42 pattern to answer a narrow question: was PHP reading bytes placed in the unfinished slot, or had it merely crashed somewhere after an OOM? The saved register value rdi=0x4242424242424242 at zend_array_destroy() answered that. A second local experiment placed a forged object and selected a harmless internal destroy handler. GDB recorded zend_objects_store_del() → zend_empty_destroy() during request shutdown. That showed an indirect native call could be influenced in the controlled lab.
Neither experiment was the final remote proof. The controlled object experiment used absolute addresses observed in GDB, and the selected handler did not execute a command. It established a path from poisoned value to native dispatch. The later six-stage HTTP client had to solve two separate problems before RCE: disclose the process's actual addresses and put a call-compatible forged structure at the place PHP would later destroy. Treating the 0x42 crash as proof of either step would have skipped the hard part of the exploit.
What each piece of evidence proves
These records came from separate experiments. Each supports a different part of the conclusion:
| Observation | Supported conclusion | Remaining limit |
|---|---|---|
| Source calls the session callback during multipart parsing. | Attacker-controlled body fields can reach native session code before the page. | Reachability alone proves no memory corruption. |
| Local OOM trace shows an unfinished HashTable bucket; a controlled filler causes a destructor crash. | The bailout can expose partially initialized native state to cleanup. | This is not the captured first failing allocation in the compact run. |
| Two-request local trace shows session pointers surviving one failed request. | The Apache child can retain request-owned pointers across the boundary. | A different worker would not inherit those pointer values. |
| Cookie bytes disclose heap and code addresses in saved runs. | The tested build exposed data needed to address its randomized process. | A cookie anomaly is not, by itself, command execution. |
GDB-assisted trace enters zif_system; the private core enters php_exec under multipart cleanup. | The destructor path can reach the native command routine before userland. | The diagnostic trace and private core are separate runs. |
HTTP-only compact run returns uid=33(www-data). | Remote command execution occurred on that pinned PHP 8.5.11 deployment. | One saved success does not establish a universal reliability rate. |
What changed in the fixed PHP source
There is a tempting one-line fix for the unfinished bucket: move nNumUsed++ below zend_string_init(). That is not what the 8.5.12 source does. The insertion order still increments the count before allocating the key. The repair changes when an out-of-memory error can interrupt that sequence.
In the fixed allocator, crossing the ordinary memory limit can queue a delayed, soft OOM while an infallible allocation finishes. PHP handles the pending error at a later safe point; sapi_handle_post() checks it after the POST handler returns. If the separate hard limit is reached, the worker exits instead of unwinding through half-built state. This does not mean PHP removed every longjmp. It means the dangerous interruption is moved away from the middle of these internal updates.
The session repair addresses the other side of the boundary. At multipart START, before the later FORMDATA and END events, 8.5.12 calls php_rinit_session_globals() to clear request-owned session pointers early. It also refuses to run this upload-progress callback after module activation for the explicit request_parse_body() path. That placement is important: resetting the state only after parsing would be too late for the early consumer shown in the GDB stack.
8.5.11: allocate during parser -> immediate OOM bailout
stale session global may be consumed before RINIT
8.5.12: complete internal allocation -> handle queued OOM later
clear session globals at multipart START
This is a source comparison of the two tags, not a claim that the compact six-request payload was rerun against every fixed package or downstream backport. The stable way to determine a distribution's patch status is its actual build and vendor advisory, not the presence or absence of a PHP version banner.
What fixes it
PHP fixed both issues in upstream releases 8.5.12, 8.4.27, 8.3.36, and 8.2.35. Check distribution backports rather than treating a version banner as a complete patch inventory. Updating to a build containing both fixes is the complete remedy described in PHP's advisories.
While updating, setting session.upload_progress.enabled=0 administratively and restarting workers blocks the demonstrated upload-progress route for CVE-2026-109619. Other stale-state producer and consumer paths exist, so this is not a general fix. PHP also lists an administratively enforced memory_limit=-1 as a partial mitigation for the predictable PHP-limit OOM path in CVE-2026-109618. Removing PHP's per-request memory bound has an availability cost; independent request and process limits remain necessary, and an underlying allocation failure can still reach the vulnerable path. FPM exits a child after failed request startup, so this exact pre-script sequence does not persist there. The advisory still treats FPM as susceptible to application-dependent paths after normal startup.
Source and evidence
The debugger excerpts above come from separate saved runs: an unfinished-bucket OOM trace, a two-request stale-session trace, a GDB-assisted native-dispatch trace, and an operator-supplied core summary from an earlier HTTP run. The compact six-stage result returned command output in-band but has no attached GDB trace. The original request streams, cookies, debugger logs, and core remain private; the excerpts here show the observations needed to explain the result and their limits.