Repository navigation
Fix potential infinite recursion in HYBRID/TAILCALL VMs - #25039
Merged
Merged
Conversation
morrisonlevi
commented
Oct 29, 2026
Comment on lines
+10449
to
+10453
| /* Like ZEND_VM_ENTER() but don't check for interrupts yet to avoid recursion if the | ||
| * interrupt handler re-sets the vm_interrupt flag. */ | ||
| execute_data = EG(current_execute_data); | ||
| LOAD_OPLINE(); | ||
| ZEND_VM_LEAVE(); |
Contributor
Author
There was a problem hiding this comment.
Here's how ZEND_VM_ENTER and ZEND_VM_LEAVE expand across VM kinds (courtesy of claude) so you can see how the change from ZEND_VM_ENTER(); to execute_data = EG(current_execute_data); LOAD_OPLINE(); ZEND_VM_LEAVE(); changes things:
| Kind | ZEND_VM_ENTER() |
ZEND_VM_LEAVE() |
|---|---|---|
| HYBRID (8.4–8.6) | execute_data = EG(current_execute_data); LOAD_OPLINE(); then ZEND_VM_INTERRUPT_CHECK(); then ZEND_VM_CONTINUE() |
ZEND_VM_CONTINUE() |
| CALL, 8.4 | return 1 |
return 2 |
| CALL, 8.5–8.6 (and 8.5 TAILCALL) | execute_data = EG(current_execute_data); LOAD_OPLINE(); return opline | ZEND_VM_ENTER_BIT |
return opline | ZEND_VM_ENTER_BIT |
| TAILCALL, 8.6 | execute_data = EG(current_execute_data); LOAD_OPLINE(); then ZEND_VM_INTERRUPT_CHECK(); then ZEND_VM_CONTINUE() (musttail call to the next handler) |
ZEND_VM_CONTINUE() |
I don't understand return 1 and return 2 on PHP 8.4's CALL VM but the rest seem correct to me.
The recursion will result in a stack overflow on HYBRID VMs and infinite recursion in TAILCALL VMs. The property that the VM makes guaranteed forward progress is useful for testing but it's also helpful to guard against for edge cases in production as well.
morrisonlevi
force-pushed
the
vm-interrupt-loop
branch
from
October 30, 2026 13:08
e7d21dc to
97cca8f
Compare
arnaud-lb
added a commit
that referenced
this pull request
Oct 30, 2026
* PHP-8.6: Fix potential infinite recursion in HYBRID/TAILCALL VMs (#25039)
Member
|
Thank you! |
kairosci
pushed a commit
to kairosci/php-src
that referenced
this pull request
Oct 30, 2026
* PHP-8.4: Fix potential infinite recursion in HYBRID/TAILCALL VMs (php#25039)
kairosci
pushed a commit
to kairosci/php-src
that referenced
this pull request
Oct 30, 2026
* PHP-8.5: Fix potential infinite recursion in HYBRID/TAILCALL VMs (php#25039)
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.
If an extension re-arms
EG(vm_interrupt)inside ofzend_interrupt_function(as-in, unconditionally, every time), then on some VM kinds there will be infinite recursion. For the HYBRID VM this will crash with stack overflow and for TAILCALL this is just regular infinite recursion (on 8.6, no problem on 8.5).The VM should always make progress. This is a useful testing property (does my interrupt handler work properly under ASAN for every possible vm interrupt point that was provided?) but it's also a nice property to protect production against a misbehaving extension.
I've discussed this with @arnaud-lb previously (see his draft #24472) but I wanted to fix it more generically, backport it to PHP 8.4, and add a test to prevent regressions. The core of the fix is this: