Skip to content
Use our free scanner to check your security!
R&D

Technical analysis of php2shell, CVE-2026-109618, CVE-2026-109619

An in-depth technical analysis of the php2shell exploit, conducted by the AssistSec R&D team. This write-up deconstructs the vulnerability, explains the mechanics behind the web shell injection, and provides actionable remediation strategies to secure your infrastructure.

AssistSec Team

Key takeaways

  • Patch now. Upgrade to PHP 8.5.12. PHP 8.1 is EOL.
  • The attack can run before your application does. php.net cites a demonstrated exploit against Apache mod_php in which an unauthenticated request can trigger the attack before any application code runs. Validation, authentication and WAF rules inside the application never see it.
  • mod_php is most at risk. In php.net's words: "We consider the risk highest for mod_php". PHP-FPM is affected too: remote code execution through the stale-state bug was validated against FPM.
  • Configuration workarounds reduce exposure but fix neither bug. memory_limit=-1, session.upload_progress.enabled=0 and, on PHP 8.5, fatal_error_backtraces=0 each close a demonstrated path, not the vulnerability.
  • PHP 8.1 and older get no upstream release, but the PHP security team published minimal source backports for 7.4, 8.0 and 8.1.
  • Patching does not undo a compromise. Unit 42 says it "has seen proof of concept of these vulnerabilities". If a server was exposed, investigate it as well as patching it.

Vulnerabilities

Advisory CVE Title Severity
GHSA-w8hw-w9fx-j79w CVE-2026-109618 RCE via OOM corruption Critical, CVSS v4.0 9.2
GHSA-6wmf-4rv5-p3rp CVE-2026-109619 RCE via stale global state Critical, CVSS v4.0 9.2

Both share the CVSS vector: CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

The impact is unauthenticated remote code execution with the web users privileges. A web user can usually read the application's files, secrets and database credentials. php.net gives the scope: "all PHP installations serving web requests, including PHP-FPM, Apache with mod_php, php-cgi, FrankenPHP and LiteSpeed."

The advisories (GHSA) credit lcfr-hax, sagitzadik-wiz, tomash-areion and amyb-oai with reporting both vulnerabilities, and Arnaud Le Blanc, Ilija Tovilo, Jakub Zelenka and Nora Dossche with the fix. Nicolas Grekas is also a co-author of the fix commit.

Timeline

  • October 18: the fix is committed to the branches the four releases are later tagged from.
  • October 20: php.net pre-announces a security release for Wednesday, October 21 at 14:00 UTC. The project reserves the right to release earlier "should details of either vulnerability become public, or should evidence of active exploitation appear in the wild."
  • October 21: the advisories are published on GitHub at 13:34 UTC. The same change reaches the public PHP 8.2 branch as 3584a98 (commit time 14:06 UTC) and is merged into the 8.3, 8.4 and 8.5 branches between 14:12 and 14:30 UTC, then into the 8.6 branch at 14:33 UTC. php.net announces PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35. CERT-EU publishes Security Advisory 2026-018, and Unit 42 a threat brief stating that it "has seen proof of concept of these vulnerabilities" and that "at least one European government has taken its website offline as a precaution."

Affected versions

Branch Affected Fixed in
PHP 8.5 < 8.5.12 8.5.12
PHP 8.4 < 8.4.27 8.4.27
PHP 8.3 < 8.3.36 8.3.36
PHP 8.2 < 8.2.35 8.2.35

The same versions apply to both CVEs. PHP 8.2 reaches end of life on December 31, 2026.

PHP 8.6 is not released yet. Its release candidates up to RC3 predate the fix; 8.6.0RC4, tagged on October 21 after the fix reached the 8.6 branch, is the first to include it. GitHub's page for the fix commit lists the branches and tags that contain it, which is why it shows php-8.6.0RC4 although the commit was written for 8.2.

According to php.net, Linux distributions and LTS vendors received the patches in advance, so check your vendor for updated packages. Distributions often backport fixes without changing the upstream version number, so a version string alone does not tell you whether you are patched. The upstream changelog records the fix as "Fixed GHSA-w8hw-w9fx-j79w, GHSA-6wmf-4rv5-p3rp (Avoid state corruption via bailout)". Search your vendor's changelog or security bulletin for those advisory IDs, the CVE numbers, or that commit title. (The changelog dates the four versions October 22; php.net announced them on October 21.)

PHP 8.1 and older

The PHP project no longer releases 8.1 and older, and CERT-EU lists these end-of-life branches among the affected products. Given the severity, the PHP security team published minimal source backports for PHP 7.4, PHP 8.0 and PHP 8.1 "to help people building from source or without access to an LTS vendor."

For a legacy runtime, check whether your OS or LTS vendor ships a package with these fixes, and confirm it in the package's changelog. If none exists, build from the backport branch or migrate. Until then, consider taking the service off the public internet.

About the code in this post

Both CVEs are fixed by one change, "Avoid state corruption via bailout", by Arnaud Le Blanc. Each release carries its own commit of it, adapted to its branch: 01a40e89fb in 8.2.35, 3c832b523e in 8.3.36, 506e87fa7d in 8.4.27 and 31c0ea7d7f in 8.5.12. On the public PHP 8.2 branch it is 3584a98, the same patch as in 8.2.35, with Ilija Tovilo, Jakub Zelenka, Nora Dossche and Nicolas Grekas as co-authors. It touches 389 files (+10,759 / −988): 96 in the Zend Engine, 246 in extensions, 7 in main/, and the rest mostly tests. Its message names its two halves: "Replace bailout on OOM with UnwindExit" and "Properly reset various globals that may be accessed during startup".

Most snippets come from the PHP 8.2 branch: "before" is the commit's parent, 512c04e, and "after" is 3584a98, so the "after" code is what PHP 8.2.35 ships. Two snippets come from PHP 8.5, which has a feature the older branches lack; they are marked. Snippets are shortened where you see /* ... */. Comments that begin with /* ... are ours and say what was left out; every other comment is php-src's own. Each snippet links to the lines it comes from.

How does PHP starts and ends a request?

To follow either bug, you need two things: the order in which PHP sets up a request, and how it aborts one.

This is the heart of php_request_startup() before the fix (main/main.c):

zend_try {
    PG(in_error_log) = 0;
    PG(during_request_startup) = 1;

    php_output_activate();

    /* initialize global variables */
    PG(modules_activated) = 0;
    /* ... */

    zend_activate();
    sapi_activate();
    /* ... timeouts, the X-Powered-By header, output buffering ... */

    php_hash_environment();
    zend_activate_modules();
    PG(modules_activated)=1;
} zend_catch {
    retval = FAILURE;
} zend_end_try();

Two calls matter here. php_hash_environment() builds the request's superglobals, and that includes parsing the request body into $_POST and $_FILES, multipart uploads included. zend_activate_modules() then runs every extension's per-request initialization, its RINIT. So the request body is parsed during startup, before any application code runs and before any extension has initialized itself for this request. The first bug depends on the parsing happening during startup; session upload progress, in the second, also depends on it happening before RINIT.

zend_try, zend_catch and zend_bailout() are PHP's error-escape mechanism, built on C's setjmp() and longjmp(). zend_try records a point to come back to, and zend_bailout() jumps straight back to the innermost one, from however deep in the call stack. Nothing in between gets to finish: no cleanup runs, no return value is checked, and whatever a function was halfway through building stays halfway built. Fatal errors use it: a fatal error is reported, then bails out.

At the end of every request, php_request_shutdown() tears it down in order: shutdown functions, destructors, output, each extension's RSHUTDOWN, the superglobals, the engine. Then it frees the request's memory.

CVE-2026-109618: RCE via OOM corruption

The cause: running out of memory was a longjmp()

The advisory's first sentence names it: "PHP uses longjmp() for out-of-memory (OOM) errors to exit the current context and abort handling of the request."

PHP's memory manager, in Zend/zend_alloc.c, enforces memory_limit. Before the fix, this is what happened when the heap needed a new chunk of memory from the operating system and that would cross the limit (Zend/zend_alloc.c):

#if ZEND_MM_LIMIT
                if (UNEXPECTED(ZEND_MM_CHUNK_SIZE > heap->limit - heap->real_size)) {
                    if (zend_mm_gc(heap)) {
                        goto get_chunk;
                    } else if (heap->overflow == 0) {
                        /* ... */
                        zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", heap->limit, ZEND_MM_PAGE_SIZE * pages_count);
                        /* ... */
                        return NULL;
                    }

It first asks the allocator to release memory it has cached (zend_mm_gc(), not PHP's cycle collector). If that frees nothing, it calls zend_mm_safe_error() (Zend/zend_alloc.c):

static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error(zend_mm_heap *heap,
    const char *format,
    size_t limit,
    /* ... */
    size_t size)
{

    heap->overflow = 1;
    zend_try {
        zend_error_noreturn(E_ERROR,
            format,
            limit,
            /* ... */
            size);
    } zend_catch {
    }  zend_end_try();
    heap->overflow = 0;
    zend_bailout();
    exit(1);
}

This raises the familiar fatal error, "Allowed memory size of … bytes exhausted". Then comes zend_bailout(), so the function never returns (hence ZEND_NORETURN): the return NULL in its caller never runs, and nothing that called emalloc() learns the allocation failed. Control leaves the allocator and lands at the nearest zend_try, wherever that is.

So any allocation of request memory could jump out of its caller. Most code copes, because the request is about to be thrown away anyway. The advisory describes where it does not: "In some contexts, request memory is temporarily reachable before it is fully initialized. If any allocation fails at that point, PHP does not properly account for the early exit and leaves the request memory in an invalid state." And: "The request shutdown procedure may then read or branch on it." The failed allocation need not be related to the memory left invalid; it only has to happen at the wrong moment.

Neither the advisory nor the commit message names the structure left half-built, and the core of the fix does not depend on it: it takes the jump out of the allocator, which covers every such site at once. Much of the rest of the commit adapts code to the new soft limit, and some of it repairs individual places a bailout could leave inconsistent, such as one in opcache.

Why mod_php is the worst case

The advisory: "Apache mod_php unconditionally invokes the request shutdown procedure, even when request startup has failed." Here it is in the Apache handler (sapi/apache2handler/sapi_apache2.c):

static int php_apache_request_ctor(request_rec *r, php_struct *ctx)
{
    /* ... */
    return php_request_startup();
}

static void php_apache_request_dtor(request_rec *r)
{
    php_request_shutdown(NULL);
    /* ... */
}

And in php_handler(), which serves each request (sapi/apache2handler/sapi_apache2.c):

zend_first_try {

    if (ctx == NULL) {
        /* ... */
        if (php_apache_request_ctor(r, ctx)!=SUCCESS) {
            zend_bailout();
        }
    } else {
        /* ... */
    }
    /* ... */
        if (!parent_req) {
            php_execute_script(&zfd);
        }
    /* ... */
} zend_end_try();

    if (!parent_req) {
        php_apache_request_dtor(r);
        /* ... */

Follow an out-of-memory error during body parsing. The allocator bails out to the zend_try in php_request_startup(), which returns FAILURE. The handler then bails out itself, which skips the script and lands after zend_end_try(). Then php_apache_request_dtor() runs php_request_shutdown() on whatever the failed startup left behind. Because the body is parsed during startup, all of this happens, in the advisory's words, "entirely before any application-specific code begins execution." Complete RCE was validated over HTTP against mod_php with default PHP input and memory limits and normal prefork configurations with multiple workers.

PHP-FPM handles the same failure differently (sapi/fpm/fpm/fpm_main.c):

if (UNEXPECTED(php_request_startup() == FAILURE)) {
    fcgi_finish_request(request, 1);
    SG(server_context) = NULL;
    php_module_shutdown();
    return FPM_EXIT_SOFTWARE;
}

The worker exits and the master replaces it, so request shutdown never runs on the invalid state. FPM is still affected: after a normal startup, an out-of-memory error can still hit a context that does not account for the early exit. But, in the advisory's words, "no complete FPM exploit has been demonstrated for this SAPI."

The advisory's verdict on two more SAPIs:

  • FrankenPHP, by source analysis, calls request shutdown unconditionally, like mod_php, "making it likely susceptible to application-independent attacks."
  • LSAPI behaves like FPM, "with application-specific exploits being likely but unvalidated."

The fix changes neither the Apache handler nor FPM's request loop. It makes the state consistent instead.

How does memory run out at the wrong moment? The advisory lists several multipart parsing problems that "can let a request reach OOM while remaining within its apparent PHP limits". For example, a part's headers can take substantially more memory inside PHP than on the wire. OOM can also be reached in application-specific ways, wherever input leads to large or repeated allocations.

The fix, part 1: a soft limit that does not jump

The advisory sums up the fix: the longjmp() is replaced with "a delayed, graceful soft OOM triggered at the next VM safe point, and an immediate hard OOM using _exit() if memory consumption reaches a second, higher threshold." Here is what that looks like in the code.

The allocator's limit checks now go through one function, zend_mm_check_limit() (Zend/zend_alloc.c):

/* Returns FAILURE if allocation should fail (in case the heap is fallible).
 * When the soft limit is to be exceeded, a delayed OOM error is queued.
 * When the hard limit is to be exceeded, the function does not return.
 */
static zend_always_inline zend_result zend_mm_check_limit(zend_mm_heap *heap, size_t add_size, bool gc, bool *did_gc ZEND_FILE_LINE_DC)
{
#if ZEND_MM_LIMIT
    /* Is the soft limit exceeded or going to be exceeded? */
    if (UNEXPECTED(heap->limit < heap->real_size || add_size > heap->limit - heap->real_size)) {
        if (gc && zend_mm_gc(heap)) {
            /* ... */
        }
        /* ... */
        if (!heap->fallible && add_size > heap->hard_limit - heap->real_size) {
            zend_mm_hard_limit_error(heap, add_size ZEND_FILE_LINE_RELAY_CC);
        }
        /* Check soft limit again as gc may have reduced memory usage */
        if (!gc || (heap->limit < heap->real_size || add_size > heap->limit - heap->real_size)) {
            if (!ZEND_HAS_OOM()) {
                zend_mm_delayed_error(
                        /* ... */
                        "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)",
                        /* ... */
                        heap->limit
                        ZEND_FILE_LINE_RELAY_CC,
                        add_size);
            }

            return heap->fallible ? FAILURE : SUCCESS;
        }
    }
#endif /* ZEND_MM_LIMIT */

    return SUCCESS;
}

memory_limit is now the soft limit. Look at the last return: for an ordinary allocation, crossing the soft limit returns SUCCESS, and the allocation goes ahead. The caller gets its memory and finishes what it was doing, so nothing is left half-built. The error is only queued, by zend_mm_delayed_verror() (Zend/zend_alloc.c):

EG(delayed_oom).message = zend_string_init(buf, strlen(buf), /* persistent */ true);
GC_MAKE_PERSISTENT_LOCAL(EG(delayed_oom).message);
zend_string_addref(script_filename);
EG(delayed_oom).filename = script_filename;
EG(delayed_oom).lineno = script_lineno;
EG(delayed_oom).state = ZEND_OOM_STATE_PENDING;

zend_atomic_bool_store_ex(&EG(vm_interrupt), true);

The message, file and line go into a new executor global, EG(delayed_oom), with the state "pending". The message is allocated persistently, outside the request heap. Then the function sets EG(vm_interrupt), the flag the virtual machine already uses to stop for timeouts. Any code can check whether an error is waiting with a new macro (Zend/zend_alloc.h):

#define ZEND_HAS_OOM() (UNEXPECTED(EG(delayed_oom).state != ZEND_OOM_STATE_NONE))

The virtual machine raises the queued error at its next safe point (Zend/zend_vm_def.h):

if (zend_atomic_bool_load_ex(&EG(timed_out))) {
    zend_timeout();
} else if (ZEND_HAS_OOM()) {
    zend_handle_delayed_oom();
    HANDLE_EXCEPTION();
} else if (zend_interrupt_function) {

C code that returns to a known point checks as well. zend_execute_scripts() checks after a script runs, and zend_call_function() checks before it calls anything, with the comment "Callers expect SUCCESS || EG(exception), so let's throw right now". sapi_handle_post() checks once the body parser has returned (main/SAPI.c):

SAPI_API void sapi_handle_post(void *arg)
{
    if (SG(request_info).post_entry && SG(request_info).content_type_dup) {
        SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg);
        efree(SG(request_info).content_type_dup);
        SG(request_info).content_type_dup = NULL;

        if (ZEND_HAS_OOM()) {
            zend_handle_delayed_oom();
        }
    }
}

All of them hand over to zend_handle_delayed_oom() (Zend/zend_alloc.c):

ZEND_API void ZEND_FASTCALL zend_handle_delayed_oom(void)
{
    zend_oom_info *info = &EG(delayed_oom);
    zend_execute_data *execute_data = EG(current_execute_data);

    if (info->state != ZEND_OOM_STATE_PENDING) {
        return;
    }
    info->state = ZEND_OOM_STATE_HANDLING;
    /* ... */

    if (execute_data) {
        /* An exception may already be in flight, and zend_throw_unwind_exit()
         * does not allow that */
        EG(exception) = NULL;

        /* Object allocation should succeed unless it trips the hard limit */
        zend_throw_unwind_exit();
    }

    zend_try {
        zend_error_zstr_at(E_ERROR, info->filename, info->lineno, info->message);
    } zend_catch {
    } zend_end_try();
    /* ... */
    info->state = ZEND_OOM_STATE_HANDLED;

    /* No userland frame to unwind: there is nothing to restore afterwards
     * and no exception to throw, so catching the bailout here would just
     * let the request carry on past a fatal error. Let it propagate and
     * abort the request, the way an immediate OOM does. */
    if (!execute_data) {
        zend_bailout();
    }
}

There are two cases:

  • A PHP frame is executing (execute_data is set). The handler throws UnwindExit, the internal exception that exit() also uses, and reports the fatal error. The stack then unwinds as it does for an exception, through code written to expect one.
  • No PHP frame is executing, as during request startup. The handler reports the error and still bails out. The difference is where: the jump now starts from a safe point, such as sapi_handle_post() after the parser has returned, not from inside an allocation in the middle of the parser.

A request that crosses memory_limit still fails with the same fatal error; in the advisory's words, "PHP's normal ability to limit memory consumption is retained." What changes is where the request stops.

The allocator no longer bails out when the operating system refuses memory, either. That case now prints "Out of memory" and exits the process (zend_out_of_memory()). After the fix, the only zend_bailout() left in Zend/zend_alloc.c is the one above.

The fix, part 2: a hard limit that exits

A soft limit that lets allocations go ahead needs a ceiling: between queueing the error and reaching the next safe point, a request could keep allocating. So the fix adds a hard limit above memory_limit (Zend/zend_alloc.c):

static void zend_mm_update_hard_limit(zend_mm_heap *heap)
{
    /* ... */
    zend_long percent = heap->hard_limit_percent;

    if (percent == -1) {
        /* For memory limit >= 1G, use a fixed 1G buffer */
        if (heap->limit > 1*1024*1024*1024) {
            size_t offset = 1*1024*1024*1024;
            /* ... */
                heap->hard_limit = heap->limit + offset;
            /* ... */
            return;
        }
        percent = 200;
    }
    /* ... */
    size_t hard_limit = scale_by_percent(heap->limit, percent);

By default, the hard limit is twice memory_limit, or memory_limit plus 1 GiB once memory_limit is above 1 GiB. With PHP's default memory_limit of 128M, that is 256M. A new INI setting changes it (main/main.c):

PHP_INI_ENTRY("memory_hard_limit_percent",  NULL,       PHP_INI_ALL,        OnChangeMemoryHardLimitPercent)

Its value is a percentage of memory_limit, at least 100, or -1 for the default. Anything else is refused with the warning "memory_hard_limit_percent must be >= 100, or -1".

Crossing the hard limit is not handled gracefully at all (Zend/zend_alloc.c):

static ZEND_COLD ZEND_NORETURN void zend_mm_hard_limit_error(zend_mm_heap *heap,
        size_t add_size ZEND_FILE_LINE_DC)
{
    /* ... finds the script's file and line ... */

    fprintf(stderr,
            /* ... */
            "Hard memory limit of %zu bytes exhausted (tried to allocate %zu bytes) in %s on line %d\n",
            /* ... */
            heap->hard_limit
            ZEND_FILE_LINE_RELAY_CC,
            add_size,
            ZSTR_VAL(script_filename),
            script_lineno);
    /* ... */
    _exit(137);
}

_exit(), not exit(): the process ends on the spot. No shutdown functions, destructors, request shutdown, module shutdown or atexit handlers run, so nothing gets to read state that may be inconsistent. As with FPM's exit after a failed startup, request shutdown never runs; unlike it, nothing else does either. And because _exit() ends the whole process, a threaded server (FrankenPHP, or mod_php with a thread-safe PHP under Apache's worker or event MPM) loses every request that process was serving.

The fix, part 3: allocations that may fail, and parsers that stop

Some code can cope with a failed allocation, if it is told. For that code, the commit adds fallible variants of the allocation API (Zend/zend_alloc.h):

/* Fallible allocation.
 * These functions return NULL if allocation would exceed memory limit. */
/* ... */
#define femalloc(size, fallible) \
    ((fallible)?_femalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC):_emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC))

A fallible allocation over the soft limit returns NULL instead of succeeding. It still queues the error, so the request still ends with the fatal error, but it is exempt from the hard-limit exit (the !heap->fallible check in zend_mm_check_limit() above). Hash tables get the same option, a HASH_FALLIBLE flag. The multipart parser uses a fallible allocation where it reads a part's body (main/rfc1867.c):

    while((read_bytes = multipart_buffer_read(self, buf, sizeof(buf), NULL))) {
-       out = erealloc(out, total_bytes + read_bytes + 1);
+       char *new_out = safe_ferealloc(out, 1, total_bytes, read_bytes + 1, /* fallible */ true);
+       if (!new_out) {
+           break;
+       }
+       out = new_out;
        memcpy(out + total_bytes, buf, read_bytes);
        total_bytes += read_bytes;
    }

The soft limit also gives parsers a new duty. Before, crossing the limit stopped a parser on the spot. Now an allocation past the limit succeeds, so a parser that kept going would run on to the hard limit and end the process. The input parsers therefore check ZEND_HAS_OOM() themselves and stop early. For example, while registering a nested request variable such as a[b][c] (main/php_variables.c):

/* Each level retains an array, so stop once over the limit. */
if (ZEND_HAS_OOM()) {
    zval_ptr_dtor_nogc(val);
    free_alloca(var_orig, use_heap);
    return;
}

And between the parts of a multipart body (main/rfc1867.c):

if (ZEND_HAS_OOM()) {
    /* A previous body part has reached the soft memory limit: Stop here */
    goto fileupload_done;
}

The parsers also need less memory than before. A multipart part's headers used to be stored, every one of them; now only the two the parser reads are kept, once each (main/rfc1867.c):

static bool php_mime_should_save_hdr(const char *name)
{
    return !strcasecmp(name, "Content-Disposition")
        || !strcasecmp(name, "Content-Type");
}
/* ... in multipart_buffer_headers(): */
            /* Keep only headers we use, and ignore duplicates */
            if (!php_mime_should_save_hdr(line)
                    || php_mime_get_hdr_value(*header, line)) {
                key = NULL;
            } else {
                key = estrdup(line);
                /* ... */
            }

The multipart reader also stops once it has read more than post_max_size bytes, instead of relying on the declared Content-Length alone (main/rfc1867.c):

if (SG(post_max_size) > 0 && SG(read_post_bytes) > SG(post_max_size)) {
    return 0;
}

And the arrays built for request variables now start with a one-slot table (array_init_singleton(), which sets nTableSize = 1), instead of the usual minimum of eight.

The commit's new regression tests cover the engine (Zend/tests/oom_soft_limit_exceeded.phpt, oom_hard_limit_exceeded.phpt, oom_interrupt.phpt, oom_request_parsing.phpt and others), multipart parsing (tests/basic/oom_rfc1867*.phpt), and extensions including date, gd, json, mbstring, pcre and zlib.

What changes for you after patching

On a patched runtime, a request that reaches the hard limit ends its process, with the message "Hard memory limit of … bytes exhausted" and exit status 137. The message goes to stderr, not to the PHP error log. Under mod_php it lands in Apache's error log. Under PHP-FPM it reaches the FPM log only if catch_workers_output is on; that is off by default, and then the only trace is the master's child … exited with code 137 as it replaces the worker. On container platforms, exit code 137 usually means a process was killed with SIGKILL, for example by the kernel's OOM killer, so look for the message as well. If these exits repeat, something is pushing your memory limits, and the frontend limits below are worth tightening.

Mitigations for CVE-2026-109618 if you cannot patch yet

None of these is a complete fix.

1. Take PHP's memory limit out of play. The advisory calls administratively setting memory_limit=-1 "the primary configuration mitigation", because "It removes the predictable per-request limit that enables the confirmed exploit with a controllable OOM." Set it where applications cannot override it, such as php_admin_value in the FPM pool or Apache configuration. In an FPM pool:

php_admin_value[memory_limit] = -1

It is not complete: "If mmap() or another underlying allocation fails, PHP can still use longjmp() while incomplete request memory is reachable." In the allocator, that is the "Out of memory" error, raised through the same zend_mm_safe_error(). It also removes PHP's per-request memory cap, an availability risk, so pair it with the limits below. Restart every worker, check that no pool, directory or application setting restores a finite limit, and put a finite limit back once you have patched.

2. Keep request bodies small, and bound them at the frontend. php.net's interim guidance: "For applications that don't require file uploads, set post_max_size = 8M. If file uploads are necessary, set post_max_size = 32M. Keep upload_max_filesize below post_max_size." These are starting points, not universal values.

At the web server or reverse proxy, limit the decoded request size, the number of input fields, multipart parts and headers, and the nesting depth. In php.net's words, "These limits must also cover requests without a usable Content-Length." Reduce max_input_nesting_level in PHP as well, and if the application never takes multipart form data, block it before it reaches PHP. Keep these limits after you patch: the advisory notes that they "reduce hard OOM and denial of service risk even after applying the patch".

3. If you use a container or cgroup memory limit, scope it to workers. php.net suggests one "as an availability boundary, preferably with a policy that kills only the affected worker." The advisory warns that it "is not guaranteed to prevent allocation failure and is not a complete mitigation", and that killing a whole container or cgroup can take the FPM master and every worker with it, unless each worker has its own group.

Do not use RLIMIT_AS or RLIMIT_DATA. They make mmap() fail once the limit is reached, "triggering the vulnerable longjmp() path."

CVE-2026-109619: RCE via stale global state

The cause: request memory freed while globals still point into it

A PHP worker serves many requests in its lifetime. Its globals (EG(...) for the engine, PG(...) for PHP's core, PS(...) for sessions, and so on) live as long as the worker does. Some point into memory owned by the current request, and, as the advisory puts it, "That state must be reset before the request memory is released." It names two ways the reset fails:

  • "A fatal error, including one caused by memory exhaustion, can abandon an operation before it performs its matching reset."
  • "A warning or other nonfatal diagnostic can also repopulate error state after that state was already cleared during shutdown."

Either way, the request's memory is freed while a worker global still points into it. Some input, configuration, session and error-handling code then runs in the next request before normal initialization replaces that state, and uses it: a use-after-free. Both requests must reach the same worker, but "Multiple workers and recycling reduce success per request but do not remove the condition."

To see why the reset is easy to miss, look at how the engine ends a request. With Zend's allocator, the default, a release build takes a shortcut (Zend/zend_execute_API.c):

bool fast_shutdown = is_zend_mm() && !EG(full_tables_cleanup);
/* ... */
if (fast_shutdown) {
    /* Fast Request Shutdown
     * =====================
     * Zend Memory Manager frees memory by its own. We don't have to free
     * each allocated block separately.
     */

The request heap is thrown away in one go, which is fast. But only the memory goes, not the pointers to it: any global that still points into that heap now points at freed memory, which the next request's allocations will reuse.

Before the fix, the fast path skipped most of the resets. This is zend_shutdown_executor_values() (Zend/zend_execute_API.c):

    if (!fast_shutdown) {
        /* ... */
        if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
            zval_ptr_dtor(&EG(user_error_handler));
            ZVAL_UNDEF(&EG(user_error_handler));
        }
        /* ... the same for the exception handler and both handler stacks ... */
    } else {
        zend_hash_discard(EG(zend_constants), EG(persistent_constants_count));
    }

    zend_objects_store_free_object_storage(&EG(objects_store), fast_shutdown);
}

The error and exception handlers set with set_error_handler() and set_exception_handler(), and their stacks, were only cleared on the slow path.

The recorded-errors state was not reset at shutdown on either path. While EG(record_errors) is set, for instance while opcache compiles a file or while classes are linked, each error is also stored, in a list in request memory (Zend/zend.c):

if (EG(record_errors)) {
    zend_error_info *info = emalloc(sizeof(zend_error_info));
    /* ... */
    EG(num_errors)++;
    EG(errors) = erealloc(EG(errors), sizeof(zend_error_info*) * EG(num_errors));
    EG(errors)[EG(num_errors)-1] = info;
}

Code that turns recording on turns it off again when it is done. If that is skipped, nothing reset these fields before init_executor() at the start of the next request, and errors can be reported before that runs.

The superglobals had the same gap. Request shutdown destroyed $_GET, $_POST, $_COOKIE and the others but left the pointers in place (main/main.c):

/* 8. Destroy super-globals */
zend_try {
    int i;

    for (i=0; i<NUM_TRACK_VARS; i++) {
        zval_ptr_dtor(&PG(http_globals)[i]);
    }
} zend_end_try();

php_hash_environment() clears them when the next request starts; anything that reads them before then finds pointers to freed arrays.

PHP 8.5: fatal error backtraces

PHP 8.5 added fatal_error_backtraces, on by default, which attaches a stack trace to fatal errors. The engine keeps the trace in EG(last_fatal_error_backtrace), an array in request memory. The advisory: "Resetting of this global state is always missed during shutdown." Before the fix, PHP 8.5's shutdown reset it only on the slow path, in zend_shutdown_executor_values() (Zend/zend_execute_API.c, PHP 8.5):

if (!fast_shutdown) {
    /* ... */
    zval_ptr_dtor(&EG(last_fatal_error_backtrace));
    ZVAL_UNDEF(&EG(last_fatal_error_backtrace));

Release builds normally take the fast path, so after a fatal error with a trace, the global keeps pointing into the freed heap. In the advisory's words, "A diagnostic on a subsequent request reaches the stale value before normal request initialization resets it." This is the advisory's strongest demonstrated case, and the basis of the confirmed mod_php exploitation.

Session upload progress

Session upload progress (session.upload_progress.enabled, on by default) lets a page poll how far an upload has got. It works from inside the multipart parser: as parts arrive, the session extension writes progress into the session, and, per the advisory, "no application call to session_start() is required." Before the fix, its update function did this (ext/session/session.c):

static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, int force_update) /* {{{ */
{
    /* ... */
    php_session_initialize();
    PS(session_status) = php_session_active;
    IF_SESSION_VARS() {
        /* ... writes the progress into $_SESSION ... */
    }
    php_session_flush(1);
}

Recall the order from the background section: the body is parsed in php_hash_environment(), before zend_activate_modules() runs the session extension's RINIT. So this code opens, decodes and writes the session with session globals that, for this request, nothing has initialized yet. The fix's comment says as much: "This runs before RINIT, so we need to clear these early". Normally, the previous request's shutdown has left them clean. After an interrupted request, they may not be: upload progress "can therefore consume session or decoder state left by an interrupted request before normal initialization resets it." Note too that the old code ignored the result of php_session_initialize() and set the status to active either way.

The demonstrated application-independent trigger is an out-of-memory error during input processing. Under mod_php, both the state left behind and the fatal error can happen during multipart startup. FPM ends the worker when startup fails, so the validated FPM path is different: state left behind while the application runs, a fatal error, then upload progress acting on it early in a later request. That works with a normal dynamic pool but depends on a suitable application operation.

Diagnostics while configuration is applied

The advisory's other confirmed consumer is a diagnostic: a warning, notice or deprecation raised while INI settings are applied before request initialization "can consume stale error state", and it "does not need to be fatal, displayed or logged." The advisory's examples:

  • deterministic deprecations: auto_detect_line_endings=1, a non-default filter.default, legacy assert.* settings on 8.3+, legacy session settings on 8.4+, and report_memleaks=0 or a nonzero intl.error_level on 8.5;
  • an explicitly configured mbstring.http_input, mbstring.http_output, mbstring.internal_encoding, iconv.input_encoding, iconv.output_encoding or iconv.internal_encoding;
  • invalid or conflicting zend.assertions, memory_limit, date.timezone, DBA, EXIF, mail, OpenSSL, zlib or extension values;
  • malformed or overflowing quantities on 8.2+, such as memory_limit, body size, input, timeout and stack values;
  • log, mail, session or SOAP cache paths rejected under open_basedir.

Which of these is reachable depends on the SAPI. Under mod_php, .htaccess and Apache php_value, php_flag and php_admin_* settings are applied before php_request_startup(). FPM is exposed when nginx, Apache mod_proxy_fcgi or another frontend sends PHP_VALUE or PHP_ADMIN_VALUE parameters that produce a diagnostic. Pool values are applied when a worker starts and .user.ini after normal initialization, so neither provides this early consumer. LSAPI can apply special environment INI values early and is a conditional candidate. For FrankenPHP's default configuration, no equivalent early consumer was established, which, the advisory adds, "does not make this environment immune."

Hiding the diagnostic does not help: "Global state is accessed before PHP decides whether to report, display or log the warning. Changing error_reporting, using @, or disabling display_errors or log_errors does not protect against this vulnerability."

Session-lifecycle RCE was validated against both mod_php and FPM, and the fatal backtrace path has confirmed RCE against mod_php.

The patch

The second half of the commit, "Properly reset various globals that may be accessed during startup", closes these gaps. The advisory states the rule: the patch resets this state "because it must not survive into operations that precede normal initialization."

The engine's shutdown now clears the handlers on the fast path too, and the recorded-errors state on both paths (Zend/zend_execute_API.c):

    } else {
        /* may be used by zend_error_zstr_at before init_executor */
        ZVAL_UNDEF(&EG(user_error_handler));
        ZVAL_UNDEF(&EG(user_exception_handler));
        memset(&EG(user_error_handlers_error_reporting), 0, sizeof(EG(user_error_handlers_error_reporting)));
        memset(&EG(user_error_handlers), 0, sizeof(EG(user_error_handlers)));
        memset(&EG(user_exception_handlers), 0, sizeof(EG(user_exception_handlers)));

        zend_hash_discard(EG(zend_constants), EG(persistent_constants_count));
    }

    zend_objects_store_free_object_storage(&EG(objects_store), fast_shutdown);

    /* may be used by zend_error_zstr_at before init_executor */
    EG(record_errors) = false;
    EG(num_errors) = 0;
    EG(errors) = NULL;
    EG(error_handling) = EH_NORMAL;
    EG(exception) = NULL;
}

zend_error_zstr_at() is where the engine reports an error, and init_executor() is where it sets up a new request. Hence the comment: errors can be reported between the two, so these fields must not point at the last request's memory. On the fast path the fields are cleared without freeing what they point to, since that whole heap is about to go. shutdown_executor() likewise forgets the object store's buckets on the fast path (EG(objects_store).object_buckets = NULL).

In PHP 8.5, the merge adds the backtrace to the same list (Zend/zend_execute_API.c, PHP 8.5):

/* may be used by zend_error_zstr_at before init_executor */
ZVAL_UNDEF(&EG(last_fatal_error_backtrace));
EG(record_errors) = false;

Request shutdown now clears the superglobals' pointers after destroying them, and resets the last error message and the delayed out-of-memory state. Its last step marks the modules inactive (main/main.c):

        for (i=0; i<NUM_TRACK_VARS; i++) {
            zval_ptr_dtor(&PG(http_globals)[i]);
            /* May be accessed before php_request_startup() */
            ZVAL_UNDEF(&PG(http_globals)[i]);
        }
    /* ... */
    /* May be accessed before php_request_startup() */
    PG(modules_activated) = 0;
}

Request startup gains an early initialization, called right after zend_activate(), for the parts of ext/standard that body parsing uses before RINIT (ext/standard/basic_functions.c):

/* Called from php_request_startup(), before any request data is processed. */
PHPAPI void php_basic_early_rinit(void)
{
    /* The session upload progress handler (un)serializes the session and
     * registers the session id with the URL rewriter from
     * php_hash_environment(), before RINIT. */
    BG(serialize_lock) = 0;
    memset(&BG(serialize), 0, sizeof(BG(serialize)));
    memset(&BG(unserialize), 0, sizeof(BG(unserialize)));
    php_url_scanner_early_rinit();
}

Session upload progress itself changes too. When a multipart body starts, the handler initializes the session globals itself, since RINIT has not run yet (ext/session/session.c):

case MULTIPART_EVENT_START: {
    /* ... */
    /* This runs before RINIT, so we need to clear these early */
    php_rinit_session_globals();

It no longer ignores a failed session start (ext/session/session.c):

-   php_session_initialize();
-   PS(session_status) = php_session_active;
+   /* Runs before RINIT: no user code may be invoked, see php_session_unserialize_init() */
+   PS(in_rfc1867_update) = true;
+   if (php_session_initialize() == FAILURE || PS(session_status) != php_session_active) {
+       PS(in_rfc1867_update) = false;
+       return;
+   }

While it runs, the session is decoded without running any PHP code (ext/session/session.c):

/* The upload progress handler (php_session_rfc1867_update()) decodes and
 * re-encodes the session during request startup, before RINIT, when no user
 * code may run. Objects are then kept as __PHP_Incomplete_Class: no
 * autoloading, no unserialize_callback_func, no __wakeup() or __unserialize(),
 * and they are written back unchanged. */
static void php_session_unserialize_init(php_unserialize_data_t *var_hash)
{
    PHP_VAR_UNSERIALIZE_INIT(*var_hash);
    if (PS(in_rfc1867_update)) {
        php_var_unserialize_set_incomplete_classes_only(*var_hash, true);
    }
}

When the upload ends, the handler deletes the $_SESSION it decoded this way ("$_SESSION was populated in incomplete_classes_only mode"). And it does nothing at all once modules are active, which is the case when PHP code calls request_parse_body() (PHP 8.4 and later): "Do not run here as it corrupts the session".

The regression tests check the lifecycle across requests directly, in tests titled "OOM during request parsing does not leak into the next request" and "OOM raised after a shutdown function does not leak into the next request". A session test checks that "the upload progress update resolves no classes, keeps the session data intact and leaves no $_SESSION behind".

The advisory is explicit: "Updating to a release containing the complete state reset patch is the only reliable mitigation."

Mitigations for CVE-2026-109619 if you cannot patch yet

None of these is complete. Make configuration changes administratively, and restart every worker after them.

1. Turn off session upload progress if you do not use it:

session.upload_progress.enabled = 0

php.net: "Use php.ini, an FPM pool or server configuration that applies before request parsing. Do not rely on ini_set() or FPM .user.ini. This blocks the confirmed session paths but not other variants." The advisory suggests leaving it off after you patch, too, if you do not need the feature.

2. On PHP 8.5, turn off fatal error backtraces:

fatal_error_backtraces = 0

php.net: "This blocks the confirmed fatal backtrace path only."

3. Remove diagnostics from configuration applied before request initialization. Remove obsolete directives and fix invalid values. Prefer php.ini or the FPM pool to per-request overrides. Under mod_php, every php_value, php_flag and php_admin_* directive is applied on each request, wherever it appears in Apache's configuration, so fix or remove a directive that raises a diagnostic rather than moving it. An isolated audit with log_errors=On, a working error_log and error_reporting=E_ALL in startup configuration helps, but the "absence of an error in logs is not proof of safety."

4. Remove fatal errors and execution timeouts an attacker can trigger, in upload and import handling, error pages, shutdown handlers, destructors, serialization, output handlers, callbacks, plugins and extensions. Also remove warnings emitted during extension post-deactivation and server cleanup.

5. Recycle workers, if you can afford it. Under FPM, pm.max_requests=1 gives every request a fresh worker. The advisory suggests it as risk reduction, and only "If performance is not a factor".

Deploying the fix

  1. Find every PHP runtime that serves requests: PHP-FPM pools, Apache mod_php, php-cgi, FrankenPHP, LiteSpeed, and PHP inside containers, hosting panels and appliances. The php on your shell's path is often not the one serving the site.
  2. Install the fixed version, or a vendor package whose changelog names the two advisories. For containers, rebuild the image on a patched base and redeploy; restarting an old image changes nothing. If you install PHP from the volunteer-maintained rpms.remirepo.net: on October 21, php.net said that repository would not have the updates that day, and urged its users to switch to distribution packages or build from source.
  3. Restart or replace every worker, so no process keeps running the old binary: PHP-FPM, Apache, LiteSpeed, and old replicas in an orchestrator.
  4. Verify what is actually running. Check the version and package of the serving runtime, not the CLI. If you need a phpinfo() page for this, restrict it and remove it afterwards.
  5. Undo temporary workarounds deliberately. Put back a finite memory_limit, keep the frontend request limits, and keep session upload progress off if you do not use it.
  6. Test uploads, multipart forms, sessions, imports and background jobs, and watch for hard-limit exits in the first days.

Detection

Neither multipart traffic nor PHP_SESSION_UPLOAD_PROGRESS in a request is evidence of an attack; both are normal. Nor is a crash or an "Allowed memory size" error on its own. Correlate PHP and web server errors with worker crashes, process creation, file changes and outbound connections.

Worth a closer look:

  • repeated memory exhaustion, or workers dying, on upload or multipart routes;
  • fatal errors, uncaught exceptions or timeouts on routes an attacker can reach;
  • warnings or deprecations logged before scripts run, or during shutdown;
  • shell or other child processes started by PHP workers;
  • new or changed files in writable web directories, and unexpected outbound connections.

A first pass over the logs: run this on the PHP error log, and on Apache's or FPM's own log, which is where the hard-limit message or FPM's exit line lands (adjust the path):

Bash (Linux)

sudo grep -Ein 'Allowed memory size.*exhausted|Hard memory limit of|exited with code 137|Out of memory|segmentation fault|SIGSEGV|Maximum execution time.*exceeded|PHP Fatal error|Uncaught Error' /var/log/php/error.log

Powershell (Windows)

Select-String -Path 'C:\path\to\php-error.log' -Pattern 'Allowed memory size.*exhausted|Hard memory limit of|exited with code 137|Out of memory|segmentation fault|SIGSEGV|Maximum execution time.*exceeded|PHP Fatal error|Uncaught Error'

Summary

Both bugs are about state that outlives the work that should have finished it. In CVE-2026-109618, the allocator's longjmp() abandons whatever operation was in progress, and under mod_php, request shutdown then works through what was left half-built. In CVE-2026-109619, a request's memory is freed while worker globals still point into it, and code that runs early in the next request (session upload progress, or error reporting while settings are applied) acts on them.

The fix addresses both. Crossing memory_limit now queues the error for the next safe point instead of jumping, and a new hard limit ends the process with _exit(137) if a request keeps growing. Shutdown now resets the request state that early code can reach, on the fast path too; startup initializes what body parsing needs before RINIT; and session upload progress runs no PHP code. None of this has a configuration equivalent. Patch, restart every worker, verify the runtime that actually serves traffic, and investigate anything that was exposed.

References

Back to the blog

Interested in a pentest?

Discover how AssistSec's AI agents give your organisation faster and more thorough insight into vulnerabilities.

Contact us