Skip to content

sapi/phpdbg: Fix use-after-free releasing recursive watchpoints on arrays - #25876

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/phpdbg-watch-release-uaf
Open

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/phpdbg-watch-release-uaf

Conversation

@iliaal

@iliaal iliaal commented Nov 28, 2026

Copy link
Copy Markdown
Member

With w r $a on an array, phpdbg registered the watchpoint id on the internal $a[] child instead of the watch the user created. That child is freed whenever the watch's subtree is torn down, so phpdbg_release_watch_elements() read freed memory at script end and w d deleted the wrong watch. Registering the real watch exposed a second use-after-free in phpdbg_remove_watch_element(), which freed a recursive root's child before recursing into it; that already crashed when deleting a recursive watch whose variable had become an array. The notice for such a watch now reads [Added recursive watchpoint #N for $a], as it does for w r on a non-array.

…rays

A recursive watch on an array registered its id on the child element
phpdbg creates for the array rather than on the watch root. The root owns
that child and frees it whenever its subtree is torn down, leaving a
dangling pointer in watch_elements that phpdbg_release_watch_elements()
read at shutdown. Register the root instead, and let
phpdbg_remove_watch_element() leave a root's subtree to
phpdbg_remove_watch_element_recursively(): it freed the root's child before
recursing into it, which already crashed on deleting a recursive watch
whose variable had become an array.
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