Skip to content

Fix use-after-free in RecursiveIteratorIterator on reentrant teardown#22478

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/spl-rii-reentrant-teardown-uaf
Open

Fix use-after-free in RecursiveIteratorIterator on reentrant teardown#22478
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/spl-rii-reentrant-teardown-uaf

Conversation

@iliaal

@iliaal iliaal commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the endChildren()/valid() reentry devnexen raised reviewing #22466. Both new cases reproduce under ASAN. This overlaps #22466 in spl_recursive_it_move_forward_ex(), so whichever lands first, the other takes a trivial rebase.

spl_recursive_it_move_forward_ex() tears down the exhausted level after
running its sub-iterator, but endChildren() and a sub-iterator's valid()
can re-enter through $this->next() and tear that level down first. The
no-more-elements branch then dtored a stale iterator pointer, and valid()
kept running on a sub-iterator the reentrant call had already freed.
Guard the teardown on the level's iterator being unchanged, and hold a
reference on the sub-iterator across valid().
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