Skip to content

Fix use-after-free when assigning to a typed property releases the object - #25065

Open
adapik wants to merge 1 commit into
php:PHP-8.4from
adapik:fix-assign-obj-typed-prop-released-object
Open

adapik wants to merge 1 commit into
php:PHP-8.4from
adapik:fix-assign-obj-typed-prop-released-object

Conversation

@adapik

@adapik adapik commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The slow path protects the object while the value is coerced to the property type (see zend_std_write_property()), because that can run user code (__toString(), an error handler) which frees the object. The fast path in ZEND_ASSIGN_OBJ and the JIT helper don't have this check. So the same code behaves differently depending on whether the cache slot is primed: the first assignment throws "Object was released while assigning to property", the following ones write into freed memory (heap-use-after-free under ASan).

This fix adds the same check to the fast path and the JIT helper, so all paths behave the same. The object is only protected when the value doesn't match the type exactly and coercion can run user code, so f.e. assigning an object to a class-typed property is not affected.

The situation is rare and artificial. Still, I think it is important that the behavior is the same on every path, regardless of whether the cache slot is primed. I found this by accident while working on #25057.

@adapik
adapik requested a review from dstogov as a code owner October 30, 2026 19:40
@adapik
adapik marked this pull request as draft October 30, 2026 19:45
@adapik adapik changed the title Fix use-after-free when assigning to a typed property releases the object [WIP] Fix use-after-free when assigning to a typed property releases the object Oct 30, 2026
@adapik
adapik force-pushed the fix-assign-obj-typed-prop-released-object branch from 6bd6e95 to 34811d4 Compare October 30, 2026 20:09
@adapik
adapik force-pushed the fix-assign-obj-typed-prop-released-object branch from 34811d4 to 919a561 Compare October 30, 2026 20:16
@adapik
adapik marked this pull request as ready for review October 30, 2026 20:20
@adapik adapik changed the title [WIP] Fix use-after-free when assigning to a typed property releases the object Fix use-after-free when assigning to a typed property releases the object Oct 30, 2026
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.

1 participant