From 108e25fedb679762d54fb0e6e442577dfc8b6f8d Mon Sep 17 00:00:00 2001 From: iefa m Date: Thu, 29 Oct 2026 13:27:49 +0530 Subject: [PATCH] running_as_user: don't skip authentication when a chroot is set running_as_user() let "sudo -u " 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. --- plugins/sudoers/check.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c index 19facee317..38fcc556cc 100644 --- a/plugins/sudoers/check.c +++ b/plugins/sudoers/check.c @@ -83,8 +83,8 @@ get_authpw(struct sudoers_context *ctx, unsigned int mode) /* * Returns true if the user is running the command as themselves - * and no SELinux type/role, AppArmor profile or Solaris privilege - * was specified. + * and no SELinux type/role, AppArmor profile, Solaris privilege + * or root directory was specified. */ static bool running_as_user(struct sudoers_context *ctx) @@ -93,7 +93,9 @@ running_as_user(struct sudoers_context *ctx) user_in_group(ctx->user.pw, ctx->runas.gr->gr_name)) && ctx->runas.role == NULL && ctx->runas.type == NULL && ctx->runas.apparmor_profile == NULL && - ctx->runas.privs == NULL && ctx->runas.limitprivs == NULL; + ctx->runas.privs == NULL && ctx->runas.limitprivs == NULL && + ctx->runas.chroot == NULL && + (def_runchroot == NULL || strcmp(def_runchroot, "*") == 0); } /*