[php-src] Issue #25090: ext/phar: use-after-free / double free in phar_wrapper_rename() via shared metadata string
| From: | cxxz16 | Date: | Sat, 31 Oct 2026 16:31:40 +0000 |
| Subject: | [php-src] Issue #25090: ext/phar: use-after-free / double free in phar_wrapper_rename() via shared metadata string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253953@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25090
Author: cxxz16
### Description
phar_wrapper_rename(): metadata string shared between source and destination entries
Category: heap-use-after-free READ + double free; CWE-416 / CWE-415.
Context: rename() through the phar stream wrapper on an entry carrying
metadata (PharFileInfo::setMetadata).
Observed: ASan reports heap-use-after-free READ of size 8 in phar_flush_ex
(ext/phar/phar.c:2690) during phar_wrapper_rename's internal phar_flush
(ext/phar/stream.c:978). The freed string is the serialized metadata
produced by php_var_serialize; it was freed when the internal flush removed
the is_deleted source entry. Manifest destruction at request shutdown
releases the same zend_string a second time.
Relevant source: ext/phar/stream.c:869 (memcpy of phar_entry_info), :871-876
(source marked is_deleted; fp/symlink/tmp cleared, metadata_tracker.str NOT
cleared), flush at stream.c:978; free of the deleted entry's metadata at
ext/phar/phar.c:2636 (phar_flush_clean_deleted_apply); dangling read at
phar.c:2690; second release at phar.c:378 (destroy_phar_manifest_entry_int).
Source assessment: the shallow copy transfers ownership of
metadata_tracker.str to the new entry without clearing it from the source
entry that the same rename operation then deletes and frees.
Expected: clear or deep-copy metadata_tracker.str on the source entry when
marking it deleted, so ownership stays exclusive.
[poc.php](https://github.com/user-attachments/files/34221464/poc.php)
[PHAR-02-rename-metadata-uaf.asan.txt](https://github.com/user-attachments/files/34221465/PHAR-02-rename-metadata-uaf.asan.txt)
### PHP Version
```plain
Component: ext/phar in php-src master, commit b9ea38ef639f5b9bbb67d27834be9c52b922520b (cloned
2026-10-21).
PHP: 8.7.0-dev (cli), NTS.
Platform: Linux x86-64 (Ubuntu 22.04 container, Docker).
Sanitizer: AddressSanitizer (-fsanitize=address -g -O1).
Configure: --disable-all --enable-cli --enable-phar --with-zlib --without-pcre-jit.
Recorded runtime environment:
USE_ZEND_ALLOC=0
ZEND_DONT_UNLOAD_MODULES=1
ASAN_OPTIONS=abort_on_error=0:detect_leaks=0
write-path tests additionally: php -d phar.readonly=0
PHAR-05 runs under the CLI development server (php -S with a router script).
```
### Operating System
_No response_