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

tcb_(un)convert: Check for UID and EUID to be 0 before proceeding. #32

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

besser82
Copy link
Contributor

@besser82 besser82 commented Dec 22, 2024

Ensuring the program is run with root privileges on startup is the safer approach instead on relying that mode 0700 may prevent the tool being run by a regular system user.

@solardiz
Copy link
Member

Why do this instead of keeping mode 700?

Also, I'd write "proceeding" in place of "performing".

@besser82 besser82 force-pushed the topic/besser82/progs_root_check branch from 237815f to bc50e3f Compare December 22, 2024 18:28
@besser82 besser82 changed the title tcb_(un)convert: Check for UID == 0 before performing. tcb_(un)convert: Check for UID == 0 before proceeding. Dec 22, 2024
@besser82
Copy link
Contributor Author

Why do this instead of keeping mode 700?

Technically I think this the safer approach, than relying on filesystem modes.

Also, I'd write "proceeding" in place of "performing".

Fixed.

@solardiz
Copy link
Member

I think the code should be checking euid, not uid.

Technically I think this the safer approach, than relying on filesystem modes.

This depends on context. Each distro relies on filesystem modes for a lot of things anyway. So within a distro we control, relying on the modes may actually be safer.

Also with the 700 file modes these programs are normally excluded from the shell's tab completion when working as a user. I think this is good.

Overall, I'm not convinced this PR is an improvement, but I suppose it could fit some distros' packaging guidelines better, and is also defense against sloppy packaging. So I don't mind.

As an option, we could add the code checks to support different distros' packaging conventions, but keep our mode 700 defaults (which packages may override).

@besser82 besser82 force-pushed the topic/besser82/progs_root_check branch from bc50e3f to 5777b93 Compare December 22, 2024 21:03
@besser82
Copy link
Contributor Author

I think the code should be checking euid, not uid.

Well, euid == 0 would also be true, if the file has SETUID capabilities and is executed, which could be dangerous; uid == 0 is only true, if the file is executed from a root login or run through sudo or su.

Also with the 700 file modes these programs are normally excluded from the shell's tab completion when working as a user. I think this is good.

Reverted.

@solardiz
Copy link
Member

Well, euid == 0 would also be true, if the file has SETUID capabilities and is executed, which could be dangerous;

Do we seriously want to defend against such misconfiguration? Most programs in the system would be dangerous if installed SUID or the like.

uid == 0 is only true, if the file is executed from a root login or run through sudo or su.

Yet it is technically possible to have uid == 0 && euid != 0, in which case with your current patch the programs will proceed to run, but will fail. So to me it makes most sense to check for the privileges they actually need to do their job, for which euid == 0 is a closer match. OTOH, indeed it is also technically possible to have euid == 0 yet no capabilities to chown files, which these programs need, so would we also be checking for this capability? This could get ridiculous.

So I think it is reasonable that we either don't make these changes at all (don't merge this PR) or require euid == 0 or require uid == 0 && euid == 0.

We could also check what precedent there is - how do other sysadmin tools that require to be run by root handle this?

Ensuring the program is run with root privileges on startup is the
safer approach instead on relying that mode 0700 may prevent the
tool being run by a regular system user.

Signed-off-by: Björn Esser <[email protected]>
@besser82 besser82 force-pushed the topic/besser82/progs_root_check branch from 5777b93 to e789235 Compare December 23, 2024 08:25
@besser82 besser82 changed the title tcb_(un)convert: Check for UID == 0 before proceeding. tcb_(un)convert: Check for UID and EUID to be 0 before proceeding. Dec 23, 2024
@besser82
Copy link
Contributor Author

So I think it is reasonable that we either don't make these changes at all (don't merge this PR) or require euid == 0 or require uid == 0 && euid == 0.

Fixed.

We could also check what precedent there is - how do other sysadmin tools that require to be run by root handle this?

Some tools do it the same way, others check setuid(0) == 0 before performing; there are even tools that perform SELinux checks on permissions and allowance for certain type transitions.

Copy link
Collaborator

@ldv-alt ldv-alt left a comment

Choose a reason for hiding this comment

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

I don't think this extra check would break anything.

@solardiz solardiz merged commit c96fded into openwall:main Dec 27, 2024
19 checks passed
@besser82 besser82 deleted the topic/besser82/progs_root_check branch December 27, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants