Skip to content

Fix GH-21776: use-after-free in zend_std_read_property magic __isset#36

Closed
iliaal wants to merge 1 commit intoPHP-8.5from
fix/gh-21776-isset-uaf
Closed

Fix GH-21776: use-after-free in zend_std_read_property magic __isset#36
iliaal wants to merge 1 commit intoPHP-8.5from
fix/gh-21776-isset-uaf

Conversation

@iliaal
Copy link
Copy Markdown
Owner

@iliaal iliaal commented Apr 17, 2026

Fixes php#21776.

When __isset drops the last non-temp reference to $this (e.g.
$GLOBALS['o'] = 0), the OBJ_RELEASE(zobj) after the __isset
call freed the object before zend_std_read_property reached the
shared uninit_error check at zend_lazy_object_must_init(zobj).
ASAN reports a heap-use-after-free.

Defer the release via a local flag so zobj stays alive through the
lazy-init check and the recursive read on the initialized instance.
Route the two returns inside the lazy block through exit: so the
deferred release runs on those paths too.

When __isset drops the last non-temp reference to $this (e.g.
$GLOBALS['o'] = 0), the OBJ_RELEASE after the __isset call freed zobj
before zend_std_read_property reached the shared uninit_error check
at zend_lazy_object_must_init(zobj), a heap-use-after-free.

The GC_ADDREF/OBJ_RELEASE pair around __isset has been correct since
2018. The 2023 lazy-object support added a zobj read in the shared
fall-through path without extending the isset branch's ref coverage
to match. Defer the release via a local flag so zobj stays alive
through the lazy-init check and the recursive read on the initialized
instance. Route the two returns inside the lazy block through exit
so the deferred release runs on those paths too.

Closes phpGH-21776
@iliaal
Copy link
Copy Markdown
Owner Author

iliaal commented Apr 17, 2026

Superseded by upstream php#21786.

@iliaal iliaal closed this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant