Skip to content

Add per-extension child initialization hooks - #24647

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

kairosci wants to merge 8 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 Outdated
Comment on lines +3446 to +3447
/* Move the child's GC sequence forward without requesting new entropy. */
php_random_pcgoneseq128xslrr64_advance(PS(random).state, 1);

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.

No, this does not work: This will advance the RNG’s state by the same amount for each child - without touching the parent state. As a result, each of the childs will have the same state.

And even if that worked, advancing by 1 means that the childs would immediately catch up with each other.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe I've done. Now each child advances the PCG by a large distance derived from its own PID, without changing the parent's state or requesting new entropy.

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.

Not great, but it should work indeed.

@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.

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