Skip to content

Fix GH-17808: PharFileInfo refcount bug - #17811

Closed
ndossche wants to merge 1 commit into
php:PHP-8.3from
ndossche:phar-entry-rc
Closed

ndossche wants to merge 1 commit into
php:PHP-8.3from
ndossche:phar-entry-rc

Conversation

@ndossche

Copy link
Copy Markdown
Member

PharFileInfo just takes a pointer from the manifest without refcounting anything. If the entry is then removed from the manifest while the PharFileInfo object still exists, we get a UAF.
We fix this by using the fp_refcount field. This is technically a behaviour change as the unlinking is now blocked, and potentially file modifications can be blocked as well. The alternative would be to have a field that indicates whether deletion is blocked, but similar corruption bugs may occur as well with file overwrites, so we increment fp_refcount instead.
This also fixes an issue where a destructor called multiple times resulted in a UAF as well, by moving the NULL'ing of the entry field out of the if.

PharFileInfo just takes a pointer from the manifest without refcounting
anything. If the entry is then removed from the manifest while the
PharFileInfo object still exists, we get a UAF.
We fix this by using the fp_refcount field. This is technically a
behaviour change as the unlinking is now blocked, and potentially file
modifications can be blocked as well. The alternative would be to have a
field that indicates whether deletion is blocked, but similar corruption
bugs may occur as well with file overwrites, so we increment fp_refcount
instead.
This also fixes an issue where a destructor called multiple times
resulted in a UAF as well, by moving the NULL'ing of the entry field out
of the if.
@ndossche ndossche linked an issue Feb 15, 2025 that may be closed by this pull request

@devnexen devnexen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, IMHO fp_refcount handling should have its macros on master. I do not know if there any gain you can get changing all these bitfields in phar_entry_info.

@ndossche ndossche closed this in e735d2b Feb 15, 2025
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.

PharFileInfo refcount bug

2 participants