Skip to content

Keep dumped objects alive across __debugInfo() and property hooks#22471

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh21024-vardump-debuginfo-uaf
Open

Keep dumped objects alive across __debugInfo() and property hooks#22471
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh21024-vardump-debuginfo-uaf

Conversation

@iliaal

@iliaal iliaal commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

var_dump() and debug_zval_dump() can use-after-free an object when its __debugInfo() triggers a user error handler that frees the object, for example by nulling a reference that aliases the dumped array slot. Both functions hold a raw pointer to the object across the __debugInfo() call and read its class name, handle and properties afterwards.

Fix: hold a reference on the object across zend_get_properties_for() and read its identity through the captured zend_object pointer rather than the zval, releasing the reference after the dump. debug_zval_dump() reports the refcount without the temporary reference.

This crashes with a plain synchronous handler, independent of any error-handler timing change.

php_var_dump(), php_debug_zval_dump() and php_var_export() capture the
object, invoke a userland callback while holding a raw pointer to it, then
read its class, handle, properties or refcount. var_dump() and
debug_zval_dump() call __debugInfo() through
zend_get_properties_for(ZEND_PROP_PURPOSE_DEBUG); var_export() reads
property values, which may run a get hook. A user error handler triggered
from any of these can drop the last reference to the object, for example
by nulling a reference that aliases the dumped array slot, freeing it
before those reads and causing a use-after-free.

Hold a reference on the object across the callback and read its identity
through the captured zend_object pointer instead of re-dereferencing the
zval, whose contents the handler may also have replaced. The
debug_zval_dump() output reports the refcount without this temporary
reference.

Fixes phpGH-21024
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