You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Zend: Pin closure in zend_call_function() before deprecation check - #25941
In zend_call_function() (Zend/zend_execute_API.c), zend_deprecated_function() and zend_param_must_be_ref() can invoke a user error handler before the call frame takes a reference to a ZEND_ACC_CLOSURE (ZEND_CLOSURE_OBJECT(func)). If the error handler releases the last external reference to the closure (for example via spl_autoload_unregister() or pcntl_signal()), the closure object and its zend_function are freed while zend_call_function() is still setting up the call, causing a use-after-free (zend_mm_heap corrupted).
Following GH-22151 (pinned_this), this hoists the ZEND_CLOSURE_OBJECT(func) refcount (pinned_closure) before the deprecation check, releases it on all early-return error paths, and transfers that reference directly to the call frame once ZEND_CALL_CLOSURE is set — adding no extra refcount operations on the normal call path.
Adds Zend/tests/gh25941.phpt (covering spl_autoload_unregister() with normal continuation and exception unwind) and ext/pcntl/tests/pcntl_signal_dispatch_closure_uaf.phpt. Verified crash -> PASS on master (Debug + ZTS), with Zend/tests/closures/ and ext/pcntl/tests/*signal*.phpt passing 155/155.
Note: AI-assisted code audit; manually verified and reproduced locally.
This isn't pcntl-specific. zend_call_function() emits the #[Deprecated] notice before the call frame holds a reference to the closure, so the same crash happens on master through autoloading (an error handler that spl_autoload_unregister()s a deprecated closure). GH-22151 already pins $this there; pinning the closure next to it until the frame takes its own reference fixes both. Since it needs an error handler that replaces the callback, this should target master rather than 8.4.
This isn't pcntl-specific. zend_call_function() emits the #[Deprecated] notice before the call frame holds a reference to the closure, so the same crash happens on master through autoloading (an error handler that spl_autoload_unregister()s a deprecated closure). GH-22151 already pins $this there; pinning the closure next to it until the frame takes its own reference fixes both. Since it needs an error handler that replaces the callback, this should target master rather than 8.4.
hohphu8
changed the title
ext/pcntl: Fix UAF in pcntl_signal_dispatch() when handler is replaced
Zend: Pin closure in zend_call_function() before deprecation check
Nov 30, 2026
Updated the PR to target master, with the engine-level fix and regression tests for both cases. Thanks again for the guidance!
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
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.
In
zend_call_function()(Zend/zend_execute_API.c),zend_deprecated_function()andzend_param_must_be_ref()can invoke a user error handler before the call frame takes a reference to aZEND_ACC_CLOSURE(ZEND_CLOSURE_OBJECT(func)). If the error handler releases the last external reference to the closure (for example viaspl_autoload_unregister()orpcntl_signal()), the closure object and itszend_functionare freed whilezend_call_function()is still setting up the call, causing a use-after-free (zend_mm_heap corrupted).Following GH-22151 (
pinned_this), this hoists theZEND_CLOSURE_OBJECT(func)refcount (pinned_closure) before the deprecation check, releases it on all early-return error paths, and transfers that reference directly to the call frame onceZEND_CALL_CLOSUREis set — adding no extra refcount operations on the normal call path.Adds
Zend/tests/gh25941.phpt(coveringspl_autoload_unregister()with normal continuation and exception unwind) andext/pcntl/tests/pcntl_signal_dispatch_closure_uaf.phpt. Verified crash -> PASS onmaster(Debug + ZTS), withZend/tests/closures/andext/pcntl/tests/*signal*.phptpassing 155/155.Note: AI-assisted code audit; manually verified and reproduced locally.