Skip to content

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

Closed
iliaal wants to merge 1 commit into
masterfrom
fix/callable-object-uaf
Closed

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

Conversation

@iliaal

@iliaal iliaal commented Aug 4, 2026

Copy link
Copy Markdown
Owner

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. Master only, matching php#22881.

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.
@iliaal
iliaal force-pushed the fix/callable-object-uaf branch from 8021708 to 104fb20 Compare August 4, 2026 01:19
@iliaal

iliaal commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream: php#23014

@iliaal iliaal closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant