Repository navigation
Fix use-after-free in zend_compile_const_decl() under opcache - #25302
Closed
nicolas-grekas wants to merge 1 commit into
Closed
nicolas-grekas wants to merge 1 commit into
nicolas-grekas wants to merge 1 commit into
Conversation
|
“Thanks for the fix — this looks like a real lifetime issue in zend_compile_const_decl() when OPcache interns the same constant name across threads. Registering the seen symbol before the literal interning step prevents the name from being released after shared-memory interning. The ASAN trace matches a use-after-free pattern. |
|
“Could an engine/OPcache maintainer review the lifetime/refcounting change here? The PR describes an ASAN use-after-free under concurrent compilation and notes there is no regression test because the bug is a race. A maintainer check on the ordering change would be helpful before merge.” |
iliaal
approved these changes
Nov 8, 2026
LamentXU123
added a commit
that referenced
this pull request
Nov 9, 2026
* PHP-8.6: Fix use-after-free in zend_compile_const_decl() under opcache (#25302)
LamentXU123
added a commit
to LamentXU123/php-src
that referenced
this pull request
Nov 9, 2026
* PHP-8.4: Fix use-after-free in zend_compile_const_decl() under opcache (php#25302)
LamentXU123
added a commit
to LamentXU123/php-src
that referenced
this pull request
Nov 9, 2026
* PHP-8.5: Fix use-after-free in zend_compile_const_decl() under opcache (php#25302)
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.
zend_compile_const_decl() interns the name of the constant, hands it to the literal of ZEND_DECLARE_CONST, then registers it as a seen symbol. With opcache, interning at runtime only finds strings already in shared memory: when the first call misses and another thread or process caches a script holding the same name before the literal interns it again, the literal swaps in the shared string and releases the original, which zend_register_seen_symbol() then reads and addrefs.
Registering the symbol first keeps the name referenced while the literal does that.
Found with FrankenPHP: restarting its workers makes them compile the same files concurrently on a fresh SHM. ASAN:
No test: this is a race between threads.