UAF in report_class_fetch_error() when the autoloader frees the class name (PHP 8.6.0)

Offen
#25,639 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
c, php
Bereich
compilers

Rechercherichtung

Start in zend_execute_API.c with zend_lookup_class_ex(), where the class name string is released around line 1355, and with report_class_fetch_error(), which builds the message around line 1785. zend_fetch_class() around line 1828 reaches the same path. Reproduce with the PoC under AddressSanitizer to confirm the heap-use-after-free at main/spprintf.c:367. Done when the not-found message is built from a string that is still alive and ASan reports no error.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Hi,

PHP 8.6.0 (official Windows NTS x64 build, 18/11/2026) reads a freed class-name string in report_class_fetch_error().

When the autoloader frees the variable that holds the class name, zend_lookup_class_ex() drops the last reference at zend_execute_API.c:1355, and report_class_fetch_error() then builds the "Class ... not found" message from the freed string (main/spprintf.c:367).

PoC:

<?php
spl_autoload_register(function ($cls) {
    $GLOBALS['cls'] = null;
});
function test() {
    global $cls;
    $cls::method();
}
$cls = implode("", ["Undefined", "Class"]);
try { test(); } catch (Throwable $e) { echo $e->getMessage(), "\n"; }

On the official 8.6.0 build the message contains freed memory, e.g. Class "UndefineD\x1aB..." not found. With a class name of about 1.45 MB or more, the process crashes with 0xC0000005 (DoS) because the large block is unmapped before the read.

ASAN: heap-use-after-free, READ of size 8 at main/spprintf.c:367; the free is in zend_string_release_ex called from zend_lookup_class_ex:1355; the read is reached from report_class_fetch_error (zend_execute_API.c:1785) and zend_fetch_class:1828.

I could not find an existing report for this call site. PRs #22688 and #22881 cover the dynamic-call paths, not report_class_fetch_error.

I know SECURITY.md treats this family as bugs, not security issues, so this is a bug report.

Suggested fix: keep a reference to class_name until after report_class_fetch_error() has built the message, or copy the name before releasing it.

Vorherrschende Sprache
C
Sterne
41.8k
Forks
8.6k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
125

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus php/php-src

Alle Issues in php/php-src

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.