Skip to content

Fix use-after-free of an array callable freed during validation - #23014

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/callable-object-uaf
Open

Fix use-after-free of an array callable freed during validation#23014
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/callable-object-uaf

Conversation

@iliaal

@iliaal iliaal commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

INIT_USER_CALL reads the callable array from op2 without holding a reference, so an error handler reached by the compound-callable deprecation can free the receiver before the call frame is built.

class Victim { public $tag = "alive"; public function target() { echo $this->tag; } }
class Holder extends Victim {}
set_error_handler(function ($n, $s) { if (str_contains($s, 'Callables of the form')) { $GLOBALS['cb'] = null; gc_collect_cycles(); } return true; });
$cb = [new Holder(), 'Victim::target'];
call_user_func($cb); // SIGSEGV

array_map() and friends are unaffected: the callable arrives as an argument, so the frame holds a reference for the call.

Unlike #22881 the hold belongs in the VM here. The reference has to outlive zend_is_callable_at_frame(), since releasing it there drops the receiver before the GC_ADDREF a few lines below.

INIT_USER_CALL borrows the callable array from op2 without holding a
reference. Validating a compound [$obj, "Class::method"] callable emits an
E_DEPRECATED that reaches a user error handler, which can drop the array's
last reference; the receiver taken from element 0 is then released before
the call frame is built, and the method body runs with $this pointing at
freed memory. Hold the array across validation and the frame build, as the
closure case in the same handler already does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant