Skip to content

running_as_user: don't skip authentication when a chroot is set - #588

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:running-as-user-chroot
Oct 29, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:running-as-user-chroot

Conversation

@iefa-m

@iefa-m iefa-m commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

running_as_user() lets check_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, so sudo -u <self> with a -R directory (allowed by CHROOT=* or runchroot=*) or with runchroot set in Defaults runs without a password, even though the front-end calls chroot(2) as root before it switches to the user. The user ends up with a process rooted in a directory of their choosing, which chroot(2) otherwise reserves for root, and any setuid program reachable there reads that tree's /etc/passwd, /etc/shadow and shared libraries. With alice ALL=(ALL) CHROOT=* /usr/bin/jailtest "", sudo -n -u alice -R /home/alice/jail /usr/bin/jailtest ran chrooted into the alice-owned directory with no password, while the same command with -u root reported "a password is required"; Defaults runchroot=/srv/jail behaved the same way.

Treat a chroot like the other security context changes: only take the shortcut when no -R directory was given and runchroot is unset or *, the same test policy.c uses before it passes chroot= 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 check passes there, and the macOS build with --enable-warnings --enable-werror --enable-sanitizer is clean. A per-rule CHROOT=dir with a non-root runas user currently fails earlier with "unable to set runas group vector" (nested PERM_RUNAS), which is a separate issue.

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 millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@millert
millert merged commit b74a1cf into sudo-project:main Oct 29, 2026
5 checks passed
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.

2 participants