Skip to content

Fix GH-24701: Use-after-free on typed trait constants during opcache preload - #24710

Merged
arnaud-lb merged 2 commits into
php:PHP-8.4from
lazerg:fix/gh-24701-trait-const-type
Nov 27, 2026
Merged

arnaud-lb merged 2 commits into
php:PHP-8.4from
lazerg:fix/gh-24701-trait-const-type

Conversation

@lazerg

@lazerg lazerg commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

zend_do_traits_constant_binding() copies the trait constant into the using class but doesn't take a reference on its type, so both constants share the same class name string. During preload that string isn't interned yet, and when opcache interns it for the first constant it frees the original while the second still points to it. Now the copy goes through zend_type_copy_ctor(), same as the trait property path. A union type also shared the type list, which trips an assertion in debug builds, so the test covers both.

Based on the reporter's suggested fix.

Fixes #24701

…he preload

Co-authored-by: sanklamm <4759687+sanklamm@users.noreply.github.com>
@lazerg

lazerg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Hey @arnaud-lb, please take a look when you have time~

* PHP-8.4: (262 commits)
  ext/pdo_sqlite: crash when a collation callback closes the statement cursor
  Admit NTS requests to OPcache SHM only in RINIT (php#25509)
  ext/pgsql: pg_meta_data() numeric column names not integer keys with opcache
  [skip ci] Add NEWS entry for php#25674
  ext/bz2: Fix NULL dereference when compress.bzip2:// open fails in write mode
  ext/dom: Reject DTD declaration nodes in adoptNode()
  Fix iconv_mime_encode() overflowing on a negative line-length (php#25485)
  ext/pgsql: pg_get_notify() result is never === false with opcache enabled
  ext/zlib: fix gzwrite() not reporting write errors
  Fix phpGH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded (php#25784)
  Fix stale string metadata in sodium_add() and sodium_increment() (php#25775)
  Sync `session.upload_progress.enabled` default in `php.ini-{development,production}` (php#25743)
  ext/pgsql: fix pg_fetch_object() JIT crash when constructor keeps $this
  Fix hash() and hash_file() hanging on invalid xxh3/xxh128 options (php#25777)
  ext/dom: fix Dom\Notation publicId and systemId property handlers
  Fix FFI::string() reading out of bounds for a negative size
  [ci skip] Update test title
  Fix phpGH-25558: FFI: struct with an enum field passed by value is described to libffi with a void element
  Fix OSS-Fuzz #588264417
  Fix FPM log overflow when errno text exceeds the buffer (phpGH-25648)
  ...
@arnaud-lb
arnaud-lb merged commit 59ccd98 into php:PHP-8.4 Nov 27, 2026
1 of 2 checks passed
arnaud-lb added a commit that referenced this pull request Nov 27, 2026
* PHP-8.6:
  Fix GH-24701: Use-after-free on typed trait constants during opcache preload (#24710)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

felixbuenemann pushed a commit to felixbuenemann/php-src that referenced this pull request Nov 27, 2026
* PHP-8.4:
  Fix phpGH-24701: Use-after-free on typed trait constants during opcache preload (php#24710)
felixbuenemann pushed a commit to felixbuenemann/php-src that referenced this pull request Nov 27, 2026
* PHP-8.5:
  Fix phpGH-24701: Use-after-free on typed trait constants during opcache preload (php#24710)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants