Skip to content

Add per-extension child initialization hooks - #24647

Open
kairosci wants to merge 7 commits into
php:masterfrom
kairosci:feat/gh-22616-extension-child-init
Open

kairosci wants to merge 7 commits into
php:masterfrom
kairosci:feat/gh-22616-extension-child-init

Conversation

@kairosci

Copy link
Copy Markdown
Contributor

Fixes #22616 by adding per-extension child initialization hooks and invalidating inherited session GC randomness after forks. Validated with debug NTS and ZTS builds, shared extensions, nested forks, FPM worker recycling, and unavailable entropy sources.

Comment thread ext/session/session.c Resolved
@kairosci
kairosci requested a review from TimWolla October 26, 2026 21:43
Comment thread ext/session/session.c Resolved
@TimWolla
TimWolla requested a review from arnaud-lb October 26, 2026 21:54
@kairosci

Copy link
Copy Markdown
Contributor Author

The latest revision advances each child RNG state by a PID-derived distance without reseeding or changing the parent state. The reviewer confirmed this should work; all CI checks are green.

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Life cycles look ok: the seed is initialized once per thread from a CSPRNG, and advanced after a fork.

Please add new macros to declare and refer to the child init function, as we do for other hooks.

Comment thread ext/session/session.c Resolved
Comment thread ext/session/session.c Resolved
@kairosci
kairosci force-pushed the feat/gh-22616-extension-child-init branch from 9be2801 to 3d46385 Compare October 30, 2026 14:52
@kairosci

Copy link
Copy Markdown
Contributor Author

Addressed the review by adding macros to declare and reference child-init hooks. Fixed CI build failures by replacing obsolete atomic-store calls in zend_test; checks are rerunning.

@kairosci

Copy link
Copy Markdown
Contributor Author

Fixed the CI build failures by restoring the missing generated arginfo entries for both zend_test functions. The CI checks are running again.

Comment thread main/main.c
Comment on lines +1847 to +1853
zend_module_entry *module;

refresh_memory_manager();
zend_max_execution_timer_init();
php_clear_stat_cache(true, NULL, 0);

ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) {

@TimWolla TimWolla Nov 1, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
zend_module_entry *module;
refresh_memory_manager();
zend_max_execution_timer_init();
php_clear_stat_cache(true, NULL, 0);
ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) {
refresh_memory_manager();
zend_max_execution_timer_init();
php_clear_stat_cache(true, NULL, 0);
ZEND_HASH_MAP_FOREACH_PTR(&module_registry, zend_module_entry *module) {

Comment thread Zend/zend_modules.h Resolved
@kairosci
kairosci force-pushed the feat/gh-22616-extension-child-init branch from 17bab85 to ec720cd Compare November 1, 2026 13:27
@kairosci
kairosci requested a review from derickr as a code owner November 1, 2026 13:27
@kairosci
kairosci force-pushed the feat/gh-22616-extension-child-init branch from ec720cd to ce8ba69 Compare November 1, 2026 13:28
Comment thread main/php.h
#define PHP_GINIT_FUNCTION ZEND_GINIT_FUNCTION
#define PHP_GSHUTDOWN_FUNCTION ZEND_GSHUTDOWN_FUNCTION
#define PHP_CINIT_FUNCTION(module) static void php_##module##_child_init(void)
#define PHP_CINIT(module) php_##module##_child_init

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This one should be in the group above. Also please define these macros in the same way as the existing ones, for consistency.

@kairosci
kairosci force-pushed the feat/gh-22616-extension-child-init branch from 3b86d34 to 3df5b71 Compare November 2, 2026 21:18
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.

Allow extensions to hook into php_child_init()

3 participants