-
Notifications
You must be signed in to change notification settings - Fork 7.9k
PharFileInfo refcount bug #17808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, can t reproduce this one. Would it be possible to automatically add to your flowfusion reports the following env var :
|
@devnexen sure! thank you for letting me know about this option.
|
Simplified: <?php
$fname = __DIR__.'/ext/phar/tests/tar/files/Structures_Graph-1.0.3.tgz';
$tar = new PharData($fname);
foreach (new RecursiveIteratorIterator($tar) as $file) {
}
unlink("$file"); EDIT: ah if you do this instead, the bug disappears, so the unlink removes some data still in use by file: $str = "$file";
unset($file);
unlink($str); |
BTW, the address looks dangerous to me. Is it controllable? |
It's probably controllable by a subsequent allocation. Question remains how an attacker would do this though but it's not outside the realm of possibility. |
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.
* PHP-8.3: Fix GH-17808: PharFileInfo refcount bug
* PHP-8.4: Fix GH-17808: PharFileInfo refcount bug
* PHP-8.3: [ci skip] Fix GH-17808 dependencies
* PHP-8.4: [ci skip] Fix GH-17808 dependencies
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. Closes phpGH-17811.
Description
The following code:
Resulted in this output:
To reproduce:
Commit:
Configurations:
Operating System:
This report is automatically generated by FlowFusion
PHP Version
5acff0e
Operating System
No response
The text was updated successfully, but these errors were encountered: