Uh oh!
There was an error while loading. Please reload this page.
FileStatus.Unix/Process.Unix: align caching of user identity. - #60160
Conversation
ghost
commented
Oct 8, 2021
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsThe effective user, and group of the process won't change. @dotnet/area-system-io ptal.
|
What if the process calls setuid, seteuid, or setegid? |
tmds
commented
Oct 8, 2021
It is not supposed to be changed. In case someone changed it, we'd still be checking against the cached values. In cases where you want to do something as a different user, it's very recommended to start a new process. We already do this type of caching in Process.Unix: |
stephentoub
commented
Oct 8, 2021
Do you mean a conforming libc implementation isn't supposed to change the values in response to these functions, or do you mean these functions aren't recommended for use but if someone uses them the values may be changed? For the former case, caching seems reasonable. |
tmds
commented
Oct 8, 2021
Sorry for being unclear. The latter. You can call these functions to change the value. This means you have the capability to change user (e.g. you're It's best to call them from apps that are in tight control of their resources to limit security issues due to leaking resources of the privileged user. I'm not aware of apps that do this besides those specifically meant to change user (like That's why I seriously discourage doing this in a .NET app. We could, if it makes a difference, avoid caching for |
carlossanlop
left a comment
There was a problem hiding this comment.
In cases where you want to do something as a different user, it's very recommended to start a new process.
Can you recommend a link I can read explaining this expectation for Unix permissions?
We could, if it makes a difference, avoid caching for root (egid = 0), since that is the most expected privileged user (which can use these calls).
Do you mean that if the initial process owner is root, we should always invoke Interop.Sys.GetEUid()/Interop.Sys.GetEGid() instead of returning the cached value, and if the value changes to a non-root user at some point, we then cache it, and start returning that? That would contradict the above statement, wouldn't it? That the recommendation is to start a new process if the user wants to switch to a different user.
Uh oh!
There was an error while loading. Please reload this page.
carlossanlop
commented
Oct 8, 2021
Is this PR being submitted in response to an existing issue? |
tmds
commented
Oct 8, 2021
No, I wanted to apply the same pattern here that I knew exits in Process.Unix and thought it was going to be a simple change, but I did not anticipate @stephentoub's feedback. I think we want to do the same thing in both places. I'll take another shot next week. |
stephentoub
commented
Oct 8, 2021
Sorry :-) |
Uh oh!
There was an error while loading. Please reload this page.
tmds
commented
Oct 13, 2021
@carlossanlop@stephentoub@jkotas please take another look. I've aligned the caching between FileStatus and Process, so it is only used on Linux when the user cannot change its identity. |
tmds
commented
Oct 13, 2021
I'm going to make another pass at this and remove the caching on Linux because it's adding some complexity, and the additional logic is circumventing the identity check in |
tmds
commented
Oct 14, 2021
I've eliminated the user identity caching.
This is up for review. |
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM! It's great to see the identity caching being unified everywhere and the checks optimized for common cases.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
commented
Nov 17, 2021
@tmds could you please solve the conflicts and answer #60160 (comment) ? |
Process: remove the user identity caching and extend the logic to avoid retrieving the identity in most cases by checking if all x-bits are set or not set. FileStatus: use same group check as Process. FileStatus: cache the read only flag instead of caching the identity.
The effective user, and group of the process won't change.
@dotnet/area-system-io ptal.