PHP2Shell: How Two Out-of-Memory and Stale-State Bugs Turned PHP
Two flaws in the PHP engine let an unauthenticated attacker corrupt memory: one through out-of-memory handling during multipart parsing, the other through global state left pointing at a freed request heap. The project says this can lead to heap use-after-free, memory disclosure and remote code execution with the web worker's privileges.
Published on medium.com
Both bugs come from the same underlying problem. PHP aborts a request with a bailout, a longjmp() out of the current context.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely PHP's bailout mechanism (a longjmp out of the current context) can fire while internal state is half-built or still points into request-owned memory, and the reset of that global state can be skipped or undone.
Impact
The project describes unauthenticated heap use-after-free, memory disclosure and RCE with worker privileges; mod_php carries the highest risk with a confirmed pre-application path, FPM has a validated path only for the stale-state bug, and the advisory notes that no complete FPM exploit has been demonstrated.
What the attacker needed
No authentication needed; request reaches a vulnerable PHP worker; multipart parsing or per-request INI diagnostics; same worker handles the next request
The fix
It was fixed in PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35 by removing longjmp for out-of-memory and by correcting the stale-state handling, and every worker must be restarted afterwards.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
PHP is the software many websites use to build pages on the fly. These bugs are in PHP itself, not in a website's own code, and they involve the cleanup code that runs when something goes wrong, such as running out of memory. Because that cleanup can leave the server confused about memory it no longer owns, a later request handled by the same worker process may read or reuse it, which the project says can end in an attacker running their own commands.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.