Skip to content

Add per-extension child initialization hooks - #24647

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

kairosci wants to merge 3 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 Outdated
@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.

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.

How could I improve it further?

@TimWolla
TimWolla requested a review from arnaud-lb October 26, 2026 21:54
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()

2 participants