Skip to content
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

chore: Use geteuid() instead of getuid() to check privilege #3364

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ruihe774
Copy link
Contributor

I believe the correct way is to check geteuid() == 0, not getuid() == 0.

Copy link

openshift-ci bot commented Dec 20, 2024

Hi @ruihe774. Thanks for your PR.

I'm waiting for a ostreedev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Collaborator

@ericcurtin ericcurtin left a comment

Choose a reason for hiding this comment

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

This looks correct to me, I tend to favour geteuid over getuid, most of the time that's what people actually want to do. But I'm not sure about every little use-case of OSTree.

What I will say, was there actually a bug or defect found here, etc.?

Or are we just changing for the sake of it because geteuid is the "better" one that's a more true test of rootness?

@ruihe774
Copy link
Contributor Author

ruihe774 commented Dec 20, 2024

What I will say, was there actually a bug or defect found here, etc.?

Not appeared. But it is easy to produce one. You can set the SUID bit of a program using libostree (e.g. ostree itself). In a program that gains privilege by SUID, getuid() returns the user that invokes the program, and geteuid() returns 0.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

No one should be including libostree in a setuid binary.
(Really there should be no setuid binaries at all, but that's another thing)

src/libotutil/ot-unix-utils.c Outdated Show resolved Hide resolved
@cgwalters
Copy link
Member

/ok-to-test

@ruihe774
Copy link
Contributor Author

No one should be including libostree in a setuid binary. (Really there should be no setuid binaries at all, but that's another thing)

Yes. However, processes can drop privileges temporarily using seteuid() as well. In this case, getuid() returns 0 and geteuid() returns a unprivileged uid.

@cgwalters cgwalters enabled auto-merge December 20, 2024 13:06
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.

3 participants