Skip to content

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

Closed
iliaal wants to merge 1 commit into
masterfrom
fix/gh21024-vardump-debuginfo-uaf
Closed

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

Conversation

@iliaal

@iliaal iliaal commented Jun 26, 2026

Copy link
Copy Markdown
Owner

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 on master with a plain synchronous handler, independent of error-handler timing. One of the reports aggregated under phpGH-20018. Verified red-before/green-after.

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
@iliaal
iliaal force-pushed the fix/gh21024-vardump-debuginfo-uaf branch from 5e562bc to a14da72 Compare June 26, 2026 11:06
@iliaal iliaal changed the title Keep the dumped object alive across __debugInfo() callbacks Keep dumped objects alive across __debugInfo() and property hooks Jun 26, 2026
@iliaal

iliaal commented Jun 26, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22471.

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