Skip to content

Fix use-after-free during lazy object initialization#119

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
fix/gh-22399-lazy-revert-double-free
Closed

Fix use-after-free during lazy object initialization#119
iliaal wants to merge 1 commit into
PHP-8.4from
fix/gh-22399-lazy-revert-double-free

Conversation

@iliaal

@iliaal iliaal commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Lazy object initialization destroyed property values while the slot or the dynamic-properties HashTable still aliased them, so a value whose __destruct reaches back through a reference cycle (unset($this->obj->prop)) double-freed it, a UAF in zend_objects_store_del. The fix clears the slot and detaches the properties table before dropping the refcount, across all four destruction sites in zend_lazy_object_revert_init and zend_lazy_object_init_proxy (declared and dynamic properties, ghost revert and proxy cleanup); verified under ASAN.

Fixes php#22399

zend_lazy_object_revert_init() and zend_lazy_object_init_proxy() dropped a
property value's refcount while the slot or dynamic-properties table still
aliased it, so a value whose destructor reaches back through a reference
cycle (unset($this->obj->prop)) freed it twice. Clear the slot and detach
the properties table before dropping the refcount.

Fixes phpGH-22399
@iliaal iliaal force-pushed the fix/gh-22399-lazy-revert-double-free branch from 7e34907 to d924213 Compare June 22, 2026 16:14
@iliaal

iliaal commented Jun 22, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR php#22401.

@iliaal iliaal closed this Jun 22, 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