Repository navigation
Security: PHP 5.6 - CVE-2026-109618 CVE-2026-109619 - #1
Open
phillarmonkey wants to merge 7 commits into
Open
phillarmonkey wants to merge 7 commits into
phillarmonkey wants to merge 7 commits into
Conversation
PHP decodes the session record for upload progress during request
startup, before RINIT. A record written by anyone who can set a session
cookie therefore reaches the unserializer before any of the script has
run: a class gets autoloaded, unserialize_callback_func is called,
__wakeup() runs, and a Serializable payload is handed to the class's
unserialize(). That is user code running inside PHP's own startup path,
for a request the attacker chose, and the same record is then re-encoded
with that code still in play.
Upstream removed the whole class of failure by replacing the OOM bailout
with UnwindExit and fallible allocation: 578 files, starting at 8.2.
This branch carries the part of that fix the 5.6 engine can hold:
- a decoder mode that resolves no class, calls no callback and keeps
every object as __PHP_Incomplete_Class, so the record serializes back
unchanged. A C: payload is copied verbatim for the same reason;
- the session globals reset at MULTIPART_EVENT_START, which runs before
RINIT, so a pointer left by a bailed-out request cannot be reused;
- the temporary $_SESSION the handler registers removed when the parse
ends;
- a failed decode no longer forces session_status to active, so nothing
is written over a record that could not be read.
Adapted for 5.6: there is no
php_var_unserialize_set_incomplete_classes_only and no UnwindExit, so
the mode rides on a core global, PG(unserialize_no_user_code), which
php_request_startup clears in case a bailout skipped the restore. The
raw C: payload is kept in __PHP_Incomplete_Class_Serialized and
php_var_serialize_class() writes it back.
This closes the session path of CVE-2026-109619. It does not close
CVE-2026-109618: an OOM during request parsing still leaves request
state half-built, because 5.6 has no fallible allocation and no unwind
path to replace longjmp(). Treat a worker as compromised after an OOM at
the wrong moment, and apply the advisory's mitigations. Do not describe
this branch as a complete PHP2Shell fix.
Test: ext/session/tests/rfc1867_no_user_code.phpt (new; fails on the
unpatched tree, passes here)
CVE: CVE-2026-109619
Upstream: 3584a98
Advisory: GHSA-6wmf-4rv5-p3rp
The first 5.6 build since 5.6.40 in January 2019. The tree is 5.6.40 plus
the change that keeps user code out of the upload progress decode; no
other behaviour changes.
Test: ext/session/tests (209 pass, bug42596 fails on the macOS bind
mount), ext/standard/tests/serialize, tests/lang, sapi/cli/tests
CVE-2026-109618 is the other half of PHP2Shell. PHP leaves the context
with longjmp() when an allocation fails, and request startup is not
ready for that exit: the allocation that fails leaves part of the
request half-built, and the rest of startup and shutdown read it.
Upstream removed the class of failure: delayed OOM state, fallible
allocation, UnwindExit instead of the bailout. That is the 578-file
allocator rewrite and it does not fit on 5.6, which has neither the
allocator API nor a place to unwind to. A heap that failed mid-startup
cannot be repaired on this branch.
So this does not repair it. It refuses to reuse the process. When the
allocator reports an out-of-memory and the bailout lands in
php_request_startup, the process exits before any cleanup runs. Modules
are what reset their own request state, and they are activated at the
end of that block, so otherwise the half-built state is read by the next
request in the same worker. That reuse is what the published exploit
needs.
The cost is deliberate, and it is why this is not a repair: a worker
dies on an out-of-memory during startup instead of logging and moving
on. FPM respawns it, and mod_php's child is replaced. The request had
already failed, and the alternative is a process whose heap state is
unknown.
The test drives the built-in server: a normal GET, then a POST larger
than memory_limit, then it asserts the process is gone. On the unpatched
tree the worker survives and takes the next request.
Test: sapi/cli/tests/oom_startup_worker_exits.phpt (new; fails on the
unpatched tree, passes here)
CVE: CVE-2026-109618
Upstream: 3584a98
Advisory: GHSA-w8hw-w9fx-j79w
The 5.6 rows ran tests/lang and Zend/tests against the default --disable-all --enable-cli build. The two new regression tests need session, CGI, and the extensions under them, so a row can now name its own configure line in a tenth column. A column that is empty or "-" keeps the default. 5.6 builds with cgi, session, and the rest of its test set, and runs ext/session/tests and sapi/cli/tests next to the language and engine suites. That puts both regression tests in CI instead of only on a developer's machine.
The second trigger in CVE-2026-109618 is an allocation that fails inside
a shutdown function or a destructor. That runs after the response, in
php_request_shutdown, and the rest of the shutdown then works on state
the aborted call left behind.
The startup barrier does not see this one: modules were activated long
before. This adds the rule at the other end. When a request enters
shutdown with no OOM behind it and one appears while shutdown runs, the
process exits once the cleanup that can still run has finished, instead
of taking the next request.
A memory limit that a script hits during execution keeps the old
behaviour: the request fails, the shutdown functions run, and the worker
stays. Only an OOM in the engine's own startup or shutdown path, where
the request never got to a consistent state, is treated as poisoned.
Test: sapi/cli/tests/oom_shutdown_worker_exits.phpt (new; the built-in
server serves the response, then the process is gone, where the
unpatched tree keeps the worker)
CVE: CVE-2026-109618
Upstream: 3584a98
Advisory: GHSA-w8hw-w9fx-j79w
phillarmonkey
marked this pull request as draft
November 2, 2026 12:24
A draft is a tree its author expects to be broken. Building it on every push spends runner time on work that is announced as incomplete, and since the 5.6 rows now build CGI and session, a run is not cheap. The pull request triggers gain ready_for_review, which is not a default type. Without it a draft marked ready would wait forever, because the opened and synchronize runs were skipped. They also gain converted_to_draft, which exists for the concurrency rule rather than for a build: the new run joins the pull request's group, cancels the run in flight, and then skips every job. Going back to draft therefore stops a build that is already running. push and workflow_dispatch are unchanged. image.yml and the release workflow do not run on pull requests at all.
phillarmonkey
marked this pull request as ready for review
November 2, 2026 12:26
sapi/cli/tests/bug61546 asserts that get_current_user() is not empty, and it failed on both Linux rows of the 5.6 matrix. The cause has nothing to do with the tree: the source is bind-mounted, so a script file belongs to the host uid, and php_get_current_user() resolves that owner with getpwuid(). The image knows root, www-data and _apt, not the runner's uid, so getpwuid() returns NULL and the function returns "". Mount the image's own /etc/passwd plus an entry for each uid involved: the host's, which owns the files, and the one the container runs as. PHP_BACKPORTS_DOCKER_USER changes only the second, so running the tests as root keeps the host entry the files need. The image's copy is cached under .build/ against the image id; the mounted file is regenerated from it, so the cache cannot go stale against a changed uid. A name is all that is needed: the test checks for a non-empty string, and every lookup inside the container now agrees, posix_getpwuid() and whoami() included. bug61546 passes on the branch after this, as root and as the host user, and the run is clean apart from the upstream XFAIL in ext/session/tests/bug69111, which warns on the unpatched 5.6.40 tree too.
|
I'll test it later on the day. Can I have Fable have a look at this code as well? |
|
Also, is this the shape for the Backports of the 7.x and 8.x variants as well? |
Member
Author
|
About Fable, have fun. |
|
I gave it a quick lookaround. I'm under the impression the ABI will break on build for custom extensions. Will validate later on the day. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch addresses the most serious vulnerabilities in PHP at the moment: CVE-2026-109618 CVE-2026-109619
Proposed version: 5.6.41
Please be mindful of our code review procedures specific for this repo.
Thank you.