Skip to content

Fix use-after-free during lazy object initialization #16004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Sep 23, 2024

Fixes two issues discovered by #15999:

  • Object may be released during initialization. Increase the object's refcount during initialization to prevent that. If the refcount is zero after restoring it, an exception is thrown (similarly to 47ed190).
  • The assigned value may be changed during initialization, so we may have to de-ref it again before forwarding the zend_std_write_property() call to the initialized object

@arnaud-lb arnaud-lb marked this pull request as ready for review September 23, 2024 16:03
@arnaud-lb arnaud-lb requested a review from dstogov as a code owner September 23, 2024 16:03
Copy link
Member

@DanielEScherzer DanielEScherzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding a test case with the reproduction case from my report in #15999

@arnaud-lb
Copy link
Member Author

Indeed, I forgot to stage the test :)

@arnaud-lb arnaud-lb changed the base branch from master to PHP-8.4 September 25, 2024 11:15
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -1184,12 +1184,22 @@ found:;
return variable_ptr;

lazy_init:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Usually, the restriction to declare a variable after a label is circumvented with a ;.

Suggested change
lazy_init:
lazy_init:;

If you prefer braces, that's fine too.

@arnaud-lb arnaud-lb merged commit ab72fba into php:PHP-8.4 Oct 2, 2024
10 checks passed
arnaud-lb added a commit that referenced this pull request Oct 2, 2024
arnaud-lb added a commit that referenced this pull request Oct 2, 2024
* PHP-8.4:
  [ci skip] NEWS for GH-16004
  Fix use-after-free during lazy object initialization (#16004)
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.

3 participants