Fix Segmentation Fault when call fpm_get_status()#18662
Closed
txuna wants to merge 2 commits intophp:PHP-8.3from
Closed
Fix Segmentation Fault when call fpm_get_status()#18662txuna wants to merge 2 commits intophp:PHP-8.3from
txuna wants to merge 2 commits intophp:PHP-8.3from
Conversation
Member
|
Thanks for a good analysis. It's spot on. I merged slightly cleaned up version in 48b4922 . I have also create WST test (my testing tool for testing more advance scenarios - especially those that our PHP test framework might not properly cover like this one) which is here: wstool/wst-php-fpm@d30230a . It confirms that the fix works. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #18595 regression in 8.3.23 and 8.4.7
fix #18595
This bug is essentially like a race condition. Imagine there is one parent process (P) and two child processes (A and B), and assume each child’s max_requests is set to 1. Now suppose two clients quickly http requests in succession:
fpm_children_bury->fpm_scoreboard_proc_freeto zero out A's process structurefpm_children_make->fpm_resources_prepare->fpm_scoreboard_proc_alloc. infpm_scoreboard_proc_alloc, the code setsmarking this new slot as “in use.” At this point,
usedfield is1butrequest_stagefield is still0, because the latter isn’t initialized until the child actually begins toaccept a request.Note
REMEMBER THE PROCESS A not reach
fpm_request_acceptingfunction yet!!fpm_get_status->fpm_status_export_to_zval.Since process A’s
usedfield is set to1,fpm_request_get_stage_namegets called. However, the newly spawned process A hasn’t yet invokedfpm_request_accepting, so itsrequest_stage fieldis still0.In this array, because
FPM_REQUEST_ACCEPTINGhas the value 1, the string entries begin at index 1, and index 0 is left as NULL.Therefore, when
fpm_request_get_stage_nameis called with arequest_stageof0, it returnsNULL, which leads to asegmentation fault.So, I append new stage the
FPM_REQUEST_CREATINGand this is0.Reproduce in 8.3.23
build
and do many client request burst.
Note
stage argument is 0!! and will occur segmentation fault when call strlen!
fixed bug branch
when request_stage field is
0, but no segmentation fault