-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix GH-19320: Prevent FPM UID and GID overflow #22986
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
Open
prateekbhujel
wants to merge
3
commits into
php:PHP-8.4
Choose a base branch
from
prateekbhujel:prateek/fix-gh-19320-fpm-id-overflow
base: PHP-8.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --TEST-- | ||
| FPM: Reject out-of-range numeric user and group IDs | ||
| --SKIPIF-- | ||
| <?php | ||
| include "skipif.inc"; | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| require_once "tester.inc"; | ||
|
|
||
| $id = '18446744073709551615'; | ||
| $settings = [ | ||
| "user = $id", | ||
| "user = 1\ngroup = $id", | ||
| "user = 1\nlisten.owner = $id", | ||
| "user = 1\nlisten.group = $id", | ||
| ]; | ||
|
|
||
| foreach ($settings as $setting) { | ||
| $cfg = <<<EOT | ||
| [global] | ||
| error_log = {{FILE:LOG}} | ||
| [unconfined] | ||
| listen = {{ADDR:UDS}} | ||
| $setting | ||
| pm = dynamic | ||
| pm.max_children = 5 | ||
| pm.start_servers = 2 | ||
| pm.min_spare_servers = 1 | ||
| pm.max_spare_servers = 3 | ||
| EOT; | ||
|
|
||
| $tester = new FPM\Tester($cfg); | ||
| $tester->testConfig(); | ||
| } | ||
|
|
||
| ?> | ||
| Done | ||
| --EXPECT-- | ||
| ERROR: [pool unconfined] user ID '18446744073709551615' is out of range | ||
| ERROR: FPM initialization failed | ||
| ERROR: [pool unconfined] group ID '18446744073709551615' is out of range | ||
| ERROR: FPM initialization failed | ||
| ERROR: [pool unconfined] user ID '18446744073709551615' is out of range | ||
| ERROR: FPM initialization failed | ||
| ERROR: [pool unconfined] group ID '18446744073709551615' is out of range | ||
| ERROR: FPM initialization failed | ||
| Done | ||
| --CLEAN-- | ||
| <?php | ||
| require_once "tester.inc"; | ||
| FPM\Tester::clean(); | ||
| ?> |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should someone re-check but couldn't that shift be in some cases undefined (e.g. on 32bit)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-checked this.
UINTMAX_C(1)makes the left operand an unsigneduintmax_t, so on a 32-bit system this is a shift by 31 and is defined.uintmax_tis required to be able to represent any unsigned integer type, and this branch is only used whenuid_tis signed. So this should be safe here, but I can add a short comment if you think it would make the intent clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me. Maybe add a comment to say that
maxspecifically excludes-1because it's a sentinel value, or check for-1separately (I was confused by-2at first).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, checking it separately is clearer. I pushed that now:
maxis the actual type maximum, and(uid_t)-1/(gid_t)-1are rejected explicitly as sentinels. The full FPM test suite still passes.