Skip to content

Fix GH-16321: UAF in list_entry_destructor when resource dtor adds references#24

Closed
iliaal wants to merge 1 commit intomasterfrom
fix/gh-16321-stream-filter-uaf
Closed

Fix GH-16321: UAF in list_entry_destructor when resource dtor adds references#24
iliaal wants to merge 1 commit intomasterfrom
fix/gh-16321-stream-filter-uaf

Conversation

@iliaal
Copy link
Copy Markdown
Owner

@iliaal iliaal commented Apr 9, 2026

Fixes php#16321

list_entry_destructor() freed the resource struct unconditionally after calling its destructor. If user code ran during the destructor (e.g. a stream filter callback) and something captured a new reference to the resource (e.g. an exception backtrace), the struct was freed while still referenced, causing a heap-use-after-free in _build_trace_args().

Bumps the resource refcount before calling the destructor so reentrant calls to zend_list_free() can't trigger a premature free. After the destructor returns, skips the free if the refcount is still elevated. Adds a fallback path in zend_list_free() to free directly when the resource has already been removed from the list.

… references

list_entry_destructor() freed the resource struct unconditionally after
calling its destructor. If user code ran during the destructor (e.g. a
stream filter callback) and something captured a new reference to the
resource (e.g. an exception backtrace), the struct was freed while still
referenced, causing a heap-use-after-free in _build_trace_args().

Bump the resource refcount before calling the destructor so reentrant
calls to zend_list_free() can't trigger a premature free. After the
destructor returns, skip the free if the refcount is still elevated.
Add a fallback path in zend_list_free() to free directly when the
resource has already been removed from the list.

Closes phpGH-16321
@iliaal
Copy link
Copy Markdown
Owner Author

iliaal commented Apr 9, 2026

Submitted upstream as php#21686

@iliaal iliaal closed this Apr 9, 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.

Segmentation fault in Zend/zend_execute.c:4624

1 participant