Repository navigation
fix: system ID for Apache graceful restart - #24184
Merged
Merged
Conversation
morrisonlevi
marked this pull request as ready for review
October 7, 2026 23:12
ndossche
approved these changes
Oct 9, 2026
ndossche
left a comment
Member
There was a problem hiding this comment.
Technically this looks right. You should contact the RMs if you think this should be backported.
bwoebi
approved these changes
Oct 9, 2026
Apache forks workers from a parent process. During a graceful restart, PHP shuts down and starts up again in that same parent process. However, `finalized` was not reset to 0 during subsequent startups, so all calls to `zend_add_system_entropy()` would fail. This could cause the process state to diverge from the system ID used to validate OPcache's file cache. For example, `zend_get_resource_handle()` would still allocate a handle, but its entropy would not contribute to the system ID. Enabling, disabling, or reordering extensions or features across graceful restarts could therefore change resource-slot assignments without a corresponding change to the system ID. Reset `finalized` when initializing the system ID so each startup can register fresh entropy.
morrisonlevi
force-pushed
the
system-id-reinitialization
branch
from
October 9, 2026 14:40
91f888f to
6599499
Compare
Member
|
@morrisonlevi this broke the build in some branches due to changes to INI functions. Please make a look. |
arnaud-lb
added a commit
to nicolas-grekas/php-src
that referenced
this pull request
Oct 12, 2026
* PHP-8.4: (33 commits) Update NEWS ext/mbstring: Fix truncated encoding names resolving to full names (php#23974) Backport PCRE2 security fixes to bundled 10.40 Fix backport ext/pdo: Avoid a duplicate warning for a rejected statement class phpdbg: Fix wrong command names Backport phpGH-24241 to 8.4 [ci skip] Update EXTENSIONS and CODEOWNERS for ext/readline Fix throwing behaviour with recursive arrays in VM Fix phpGH-24229: Use SHUT_WR when closing FastCGI connections (php#24230) Add regression test for phpGH-16821 (php#24228) Fix use-after-free when removing a failing zlib.inflate filter (php#24176) Fix phpGH-24218: Invalid opcode for count() of a literal array without SCCP fix: system ID for Apache graceful restart (php#24184) ext/standard: Validate the bcrypt cost before reading it zend_alloc: move a small block shrunk to the size of the bin below Fix phpGH-23979: Nullsafe operator must not flush delayed oplines of an enclosing function ext/zip: Reject ZipArchive mutators during close() (php#24025) Fix OSS-Fuzz #568005340: FETCH_DIM_FUNC_ARG partial conversion Fix too wide type inference for ASSIGN_DIM_OP ...
lyrixx
added a commit
to lyrixx/php-wasm-builder
that referenced
this pull request
Nov 4, 2026
…ater Each run starts PHP and stops it: what opcache compiled was gone with it, and opcache could not start anyway, WASM has no shared memory. With OPCACHE, opcache() for a stack, it keeps what it compiles in /opcache, in the WASM filesystem (file_cache_only), that the next runs read: - runtime: the first run that needs a file compiles it; - precompiled: the warm stage compiles every PHP file of the embedded directory, and the cache is embedded. The system_id that keys the cache does not depend on the binary: the build for node compiles for the one for the web. Two problems of PHP, worked around in run.c: - The first start of the engine gets another system_id than the next ones (zend_system_id.c never resets "finalized"): every run takes the one of the first. PHP fixes it after 8.5.12 (php/php-src#24184). - Without shared memory, opcache leaves smm_shared_globals pointing to a variable of a function that returned, that a later run with the file cache reads: it corrupted the memory (php/php-src#25195). It is reset before each run. opcache is disabled too, unless it has its files. What is embedded is dated 1 s after the epoch: opcache caches it from the first run, and does not cache a file written less than 2 s before, that could be written over in the same second.
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.
Apache forks workers from a parent process. During a graceful restart, PHP shuts down and starts up again in that same parent process. New workers are then forked from the parent.
However,
finalizedwas not reset to 0 during subsequent startups, so all calls tozend_add_system_entropy()would fail. This could cause the process state to diverge from the system ID used to validate OPcache's file cache.For example,
zend_get_resource_handle()would still allocate a handle, but its entropy would not contribute to the system ID. Enabling, disabling, or reordering extensions or features across graceful restarts could therefore change resource-slot assignments without a corresponding change to the system ID.Reset
finalizedwhen initializing the system ID so each startup can register fresh entropy.I think this fix should definitely go into PHP 8.4+ but I think that RMs should consider pulling it for 8.2-8.3. It is not a dangerous change, it's simple, and easy to understand (well, assuming you already understand Apache graceful and system ID), and causes really nasty memory bugs when it's hit.