[PATCH] mount.cifs: prevent stolen creds through SUDO_UID

Paulo Alcantara <[email protected]> Tue, 28 Jul 2026 20:35:32 -0300
Newsgroups org.kernel.vger.linux-cifs
Message-ID <[email protected]>
When mount.cifs is invoked with setuid, a non-root user may set
SUDO_UID to be used on the retry kerberos authentication path,
therefore allowing it to mount shares by using credential caches from
different users in the system.

Fix this by trusting the value of SUDO_UID only when mount.cifs is
being executed by sudo or root.

Fixes: 1a1507654c5f ("mount.cifs: use SUDO_UID env variable for cruid")
Reported-by: Daniel Birtwhistle <[email protected]>
Signed-off-by: Paulo Alcantara (Red Hat) <[email protected]>
Cc: Steve French <[email protected]>
Cc: [email protected]
---
 mount.cifs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mount.cifs.c b/mount.cifs.c
index b57c7d346f42..f0e9bc7beae2 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -2145,7 +2145,7 @@ int main(int argc, char **argv)
 	int rc = 0;
 	int already_uppercased = 0;
 	int sloppy = 0;
-	int fallback_sudo_uid = 0;
+	int fallback_sudo_uid = geteuid() || getuid();
 	size_t options_size = MAX_OPTIONS_LEN;
 	struct parsed_mount_info *parsed_info = NULL;
 	struct parsed_mount_info *reinit_parsed_info = NULL;
-- 
2.55.0