Skip to content

Fix GH-22480: phpdbg use-after-free re-watching a watched variable#136

Closed
iliaal wants to merge 1 commit into
masterfrom
fix/gh-22480-phpdbg-watch-uaf
Closed

Fix GH-22480: phpdbg use-after-free re-watching a watched variable#136
iliaal wants to merge 1 commit into
masterfrom
fix/gh-22480-phpdbg-watch-uaf

Conversation

@iliaal

@iliaal iliaal commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Fixes php#22480

phpdbg_add_watch_element() frees the passed element and returns the existing one when the variable is already watched, but several callers kept using the freed pointer, so re-watching a variable was a use-after-free. The two reported derefs are not the whole bug: with only the proposed two-line capture, w a $a typed twice still crashes, relocated to a later interned-string read. This reports the duplicate back through the parse callback so the wrapper registers nothing, and rejects a recursive watch's hashtable element that collides with an existing watch, at creation and recreation, instead of freeing a still-referenced one.

@iliaal iliaal force-pushed the fix/gh-22480-phpdbg-watch-uaf branch 4 times, most recently from b018fe0 to 6e36ea3 Compare June 27, 2026 21:33
phpdbg_add_watch_element() frees the passed element and returns the
existing one when the variable is already watched, but several callers
kept using the freed pointer, so re-watching a variable was a
use-after-free in more places than the two reported. Report the duplicate
back through the parse callback and register nothing, and reject a
recursive watch's hashtable element that collides with an existing watch,
at creation and recreation, rather than freeing a still-referenced one. A
recursive watch over an already-array-watched variable now watches only
the root and skips the shared hashtable.

Fixes phpGH-22480
@iliaal iliaal force-pushed the fix/gh-22480-phpdbg-watch-uaf branch from 6e36ea3 to f02c6b2 Compare June 27, 2026 21:36
@iliaal

iliaal commented Jun 27, 2026

Copy link
Copy Markdown
Owner Author

Promoted to php#22493.

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

[phpdbg] Multiple Use-After-Free bugs in watchpoint management due to ignored return values

1 participant