Skip to content

Fix GH-9589: dl() segfaults when module is already loaded #9689

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

Closed
wants to merge 2 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Oct 7, 2022

As of PHP 8.2.0, zend_module_entry structures are no longer copied, so when a module is permanently loaded, and users try to dynamically load that module again, the structure is corrupted[1], causing a segfault on shutdown.

We catch that by checking whether any dynamically loaded module is already loaded, and bailing out in that case without modifying the zend_module_entry structure.

[1] #9589 (comment)

As of PHP 8.2.0, `zend_module_entry` structures are no longer copied,
so when a module is permanently loaded, and users try to dynamically
load that module again, the structure is corrupted[1], causing a
segfault on shutdown.

We catch that by checking whether any dynamically loaded module is
already loaded, and bailing out in that case without modifying the
`zend_module_entry` structure.

[1] <php#9589 (comment)>
@cmb69
Copy link
Member Author

cmb69 commented Oct 7, 2022

Note that this may be applied with or without also applying PR #9648; while that duplicates a bit of code in the former case (where it is not strictly necessary), it still seems to be good practice to catch this condition early, and to fail fast.

/cc @arnaud-lb, @morrisonlevi

--TEST--
dl() segfaults when module is already loaded
--EXTENSIONS--
dl_test
Copy link
Member Author

Choose a reason for hiding this comment

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

It's probably sensible to add a comment regarding the usage of dl_test; actually, it doesn't matter which extension we use for the test, but it is mandatory that it is a shared module; this is always given for dl_test.

Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

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

Looks good to me

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

@cmb69 cmb69 closed this in 6e0505b Oct 10, 2022
@cmb69 cmb69 deleted the cmb/gh9589 branch October 10, 2022 11:39
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