Repository navigation
running_as_user: don't skip authentication when a chroot is set - #588
Merged
Merged
Conversation
running_as_user() let "sudo -u <self>" skip authentication unless an SELinux role/type, AppArmor profile or Solaris privilege set was in effect, but it did not consider the root directory. A -R directory (allowed by CHROOT=* or runchroot=*) or a runchroot set in Defaults was therefore applied without a password, even though chroot(2) is done as root before switching to the user. Treat a chroot like the other security context changes and require authentication.
millert
approved these changes
Oct 29, 2026
millert
left a comment
Collaborator
There was a problem hiding this comment.
The chroot code is slated to be removed in a future release (not 1.9.18) but while it is present it is good to have it work as well as possible.
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.
running_as_user()letscheck_user()skip authentication when the runas user is the invoking user, unless an SELinux role/type, AppArmor profile or Solaris privilege set is in effect. It does not look at the root directory, sosudo -u <self>with a-Rdirectory (allowed byCHROOT=*orrunchroot=*) or withrunchrootset in Defaults runs without a password, even though the front-end callschroot(2)as root before it switches to the user. The user ends up with a process rooted in a directory of their choosing, whichchroot(2)otherwise reserves for root, and any setuid program reachable there reads that tree's/etc/passwd,/etc/shadowand shared libraries. Withalice ALL=(ALL) CHROOT=* /usr/bin/jailtest "",sudo -n -u alice -R /home/alice/jail /usr/bin/jailtestran chrooted into the alice-owned directory with no password, while the same command with-u rootreported "a password is required";Defaults runchroot=/srv/jailbehaved the same way.Treat a chroot like the other security context changes: only take the shortcut when no
-Rdirectory was given andrunchrootis unset or*, the same testpolicy.cuses before it passeschroot=to the front-end. Running as yourself without a chroot still needs no password, and the chroot cases still work after authenticating. Checked end to end on Linux with sudo built and installed from main,make checkpasses there, and the macOS build with--enable-warnings --enable-werror --enable-sanitizeris clean. A per-ruleCHROOT=dirwith a non-root runas user currently fails earlier with "unable to set runas group vector" (nestedPERM_RUNAS), which is a separate issue.