Skip to contentSkip to conversation

mount.cifs: prevent stolen creds through SUDO_UID

PATCH Applied Paulo Alcantara 3 participants 3 messages Jul 28 – Jul 29

Subsystems (2)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/1 mount.cifs: prevent stolen creds through SUDO_UID

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")
Cc Steve French <[email protected]>
---
 mount.cifs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mount.cifs.c +1 -1
index b57c7d346f42..f0e9bc7beae2 100644
@@ -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;
Signature · 1 line
2.55.0
#1 lore raw

Hello Steve and Paulo,

Yes. I applied the exact patch to cifs-utils 7.7 at
3a7dc396306654aa225c35767e56ac1fb239922e, built it successfully, and tested the ENOKEY retry decision using matched unpatched and patched setuid binaries.

The results were:

- Unpatched direct setuid invocation (ruid=1000, euid=0, caller-controlled SUDO_UID=4242): the ENOKEY retry added cruid=4242.
- Patched with the same identity and environment: no retry occurred and no cruid option was constructed.
- Patched root/sudo invocation (ruid=0, euid=0, SUDO_UID=4242): the retry retained cruid=4242, preserving the intended sudo behavior.

My conclusion is that the patch closes the demonstrated SUDO_UID-to-cruid credential-selection issue. I am also happy to test the final committed version.

For clarity, this validation is specific to the SUDO_UID issue. The separate credential-file TOCTOU/privilege-drop case and the remaining Low parse_unc hardening item are independent and are not addressed by this change.

Thank you for the quick fix and for including the credit.

Best Regards,

Daniel Birtwhistle
Senior Director Product Security & Assessment

________________________________________
From: Paulo Alcantara <[email protected]>
Sent: Tuesday, July 28, 2026 7:35 PM
To: Pavel Shilovsky
Cc: Birtwhistle, Daniel; Paulo Alcantara (Red Hat); Steve French; [email protected]
Subject: [PATCH] mount.cifs: prevent stolen creds through SUDO_UID

CAUTION: This email originated from outside of GE HealthCare. Only open links or attachments if you trust the sender. Report suspicious emails using Outlook’s “Report” button.

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")
Cc Steve French <[email protected]>
---
 mount.cifs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mount.cifs.c +1 -1
index b57c7d346f42..f0e9bc7beae2 100644
@@ -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

Applied
#2 lore raw

merged into cifs-utils and smb3-utils for-next

Quoted 67 lines · Daniel

Hello Steve and Paulo,

Yes. I applied the exact patch to cifs-utils 7.7 at
3a7dc396306654aa225c35767e56ac1fb239922e, built it successfully, and tested the ENOKEY retry decision using matched unpatched and patched setuid binaries.

The results were:

- Unpatched direct setuid invocation (ruid=1000, euid=0, caller-controlled SUDO_UID=4242): the ENOKEY retry added cruid=4242.
- Patched with the same identity and environment: no retry occurred and no cruid option was constructed.
- Patched root/sudo invocation (ruid=0, euid=0, SUDO_UID=4242): the retry retained cruid=4242, preserving the intended sudo behavior.

My conclusion is that the patch closes the demonstrated SUDO_UID-to-cruid credential-selection issue. I am also happy to test the final committed version.

For clarity, this validation is specific to the SUDO_UID issue. The separate credential-file TOCTOU/privilege-drop case and the remaining Low parse_unc hardening item are independent and are not addressed by this change.

Thank you for the quick fix and for including the credit.

Best Regards,

Daniel Birtwhistle
Senior Director Product Security & Assessment

________________________________________
From: Paulo Alcantara <[email protected]>
Sent: Tuesday, July 28, 2026 7:35 PM
To: Pavel Shilovsky
Cc: Birtwhistle, Daniel; Paulo Alcantara (Red Hat); Steve French; [email protected]
Subject: [PATCH] mount.cifs: prevent stolen creds through SUDO_UID

CAUTION: This email originated from outside of GE HealthCare. Only open links or attachments if you trust the sender. Report suspicious emails using Outlook’s “Report” button.

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")
Cc Steve French <[email protected]>
---
 mount.cifs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mount.cifs.c +1 -2
index b57c7d346f42..f0e9bc7beae2 100644
@@ -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

Signature · 3 lines
Thanks,

Steve