StreamPollHandle UAF
@iliaal is already working on this.
Since Jul 21, 2026.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
StreamPollHandle::__construct() caches the raw php_stream * pointer but only takes a reference on the stream's zend_resource container not on the stream itself. When the stream is closed with fclose() php_stream_free() calls pefree() on the php_stream and zend_resource_dtor() sets res->ptr = NULL yet the handle's cached data->stream field is never cleared and keeps pointing at the freed memory. The methods isValid() getFileDescriptor() and getStream() check the stale data->stream pointer (which is still non-NULL) instead of the resource so they dereference the freed php_stream. This is a use-after-free: getFileDescriptor() reaches php_stream_cast() which reads stream->ops and performs an indirect call through stream->ops->cast() from freed memory and getStream() even hands the freed stream back to userland as a live resource. The fix is to validate and read the stream through the held resource (data->res->ptr/type) rather than the cached raw pointer, or not cache data->stream at all.
PHP Version
8.6.0-dev. Component: Standard (ext/standard/io_poll.c)
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.