Skip to contentSkip to conversation

cifs.upcall: allow cifs.upcall to scrape cache location initiating task's environment

PATCH Superseded Jeff Layton 6 participants 14 messages Feb 15, 2017 – Feb 24, 2017 9 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover cifs.upcall: allow cifs.upcall to scrape cache location initiating task's environment

Apologies for v3 series, I had some extra patches in there. This is the one that should have been sent. Relabeled as v4 for clarity.

Third respin of this series. Reordered for better safety for bisecting. The environment scraping is now on by default, but can be disabled with "-E" in environments where it's not needed.

Also, I've added a patch to make cifs.upcall drop capabilities before doing most of its work. This may help reduce the attack surface of the program.

Jeff Layton (4):
cifs.upcall: convert two flags from int to bool cifs.upcall: switch group IDs when handling an upcall cifs.upcall: drop capabilities early in program cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's
/proc/<pid>/environ file

 Makefile.am      |   2 +-
 cifs.upcall.8.in |   9 ++
 cifs.upcall.c    | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 256 insertions(+), 10 deletions(-)
Signature · 1 line
2.9.3

A message that is not in the archive (sent off-list or not yet received): 20170215161522.17063-1-jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org

#2 lore raw

PATCH v4 1/4 cifs.upcall: convert two flags from int to bool

---
 cifs.upcall.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
cifs.upcall.c +5 -4
index 8f146c92b4a5..418b179d7f29 100644
@@ -685,7 +685,8 @@ int main(const int argc, char *const argv[])
 	size_t datalen;
 	unsigned int have;
 	long rc = 1;
-	int c, try_dns = 0, legacy_uid = 0;
+	int c;
+	bool try_dns = false, legacy_uid = false;
 	char *buf;
 	char hostbuf[NI_MAXHOST], *host;
 	struct decoded_args arg;
@@ -705,7 +706,7 @@ int main(const int argc, char *const argv[])
 			/* legacy option -- skip it */
 			break;
 		case 't':
-			try_dns++;
+			try_dns = true;
 			break;
 		case 'k':
 			if (setenv("KRB5_CONFIG", optarg, 1) != 0) {
@@ -717,7 +718,7 @@ int main(const int argc, char *const argv[])
 			keytab_name = optarg;
 			break;
 		case 'l':
-			legacy_uid++;
+			legacy_uid = true;
 			break;
 		case 'v':
 			rc = 0;
@@ -899,7 +900,7 @@ retry_new_hostname:
 		if (rc)
 			break;
 
-		try_dns = 0;
+		try_dns = false;
 		host = hostbuf;
 		goto retry_new_hostname;
 	default:
Signature · 1 line
2.9.3
#3 lore raw

PATCH v4 2/4 cifs.upcall: switch group IDs when handling an upcall

In reply to a message not in the archive

Currently, we leave the group ID alone, but in a later patch we'll be changing cifs.upcall to scrape $KRB5CCNAME out of the originating process. At that point, we want to be a little more careful with the process credentials we'll be using.

After we get the uid, do a getpwuid and grab the default gid for the user. Then use setgid to set it before calling setuid.

---
 cifs.upcall.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
cifs.upcall.c +37 -0
index 418b179d7f29..2b535a133a30 100644
@@ -46,6 +46,8 @@
 #include <netdb.h>
 #include <arpa/inet.h>
 #include <ctype.h>
+#include <pwd.h>
+#include <grp.h>
 
 #include "replace.h"
 #include "data_blob.h"
@@ -694,6 +696,7 @@ int main(const int argc, char *const argv[])
 	uid_t uid;
 	char *keytab_name = NULL;
 	krb5_ccache ccache = NULL;
+	struct passwd *pw;
 
 	hostbuf[0] = '\0';
 	memset(&arg, 0, sizeof(arg));
@@ -795,15 +798,49 @@ int main(const int argc, char *const argv[])
 		goto out;
 	}
 
+	/*
+	 * The kernel doesn't pass down the gid, so we resort here to scraping
+	 * one out of the passwd nss db. Note that this might not reflect the
+	 * actual gid of the process that initiated the upcall. While we could
+	 * scrape that out of /proc, relying on that is a bit more risky.
+	 */
+	pw = getpwuid(uid);
+	if (!pw) {
+		syslog(LOG_ERR, "Unable to find pw entry for uid %d: %s\n",
+			uid, strerror(errno));
+		rc = 1;
+		goto out;
+	}
+
+	/*
+	 * The kernel should send down a zero-length grouplist already, but
+	 * just to be on the safe side...
+	 */
+	rc = setgroups(0, NULL);
+	if (rc == -1) {
+		syslog(LOG_ERR, "setgroups: %s", strerror(errno));
+		rc = 1;
+		goto out;
+	}
+
+	rc = setgid(pw->pw_gid);
+	if (rc == -1) {
+		syslog(LOG_ERR, "setgid: %s", strerror(errno));
+		rc = 1;
+		goto out;
+	}
+
 	rc = setuid(uid);
 	if (rc == -1) {
 		syslog(LOG_ERR, "setuid: %s", strerror(errno));
+		rc = 1;
 		goto out;
 	}
 
 	rc = krb5_init_context(&context);
 	if (rc) {
 		syslog(LOG_ERR, "unable to init krb5 context: %ld", rc);
+		rc = 1;
 		goto out;
 	}
 
Signature · 1 line
2.9.3

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): d29a36ca-693d-e3c6-9428-90b1ee9bce10-JAjqph6Yjy/[email protected]

#6 lore raw

Re: problem when testing recent cifs.upcall

Quoted 62 lines · Chad William Seys

Hi Jeff,
I'm testing the most recent cifs.upcall (most recent commit
"cifs.upcall: trim even more capabilities") .
I copied cifs.upcall over the one provided in Debian package of
cifs-utils 6.6
While testing, one of the things I did was destroy my kerberos ticket
and then try to enter a directory in which the user did not have a listing in the ACL, except through membership in a group. I wasn't able to ls the directory (fine). However, kinit failed. ls-ing shows that the credential cache kinit tries to create already exists, but is owned by root. Uh oh. :)
Looks like root must go create a credential cache file with same name
instead of just looking for an existing one.
The steps are below:

cwseys:

# kdestroy
# cd /

root:

# umount /smb
# umount /smb  # to be sure!

cwseys:

# kinit
Password for [email protected]:
# ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys  939 Feb 22 11:06 /tmp/krb5cc_1494_sM11PG

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb 
-osec=krb5,multiuser,[email protected],cruid='0',uid=0 
--verbose

cwseys:

# cd /smb
# kdestroy
# ls /tmp/krb5cc_* -al
[user's credential cache not listed]
# cd to a directory on which cwseys not listed directly in ACLs (but
# indirectly as part of a group)
# cd obs-cos
# ls
ls: reading directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
# ls /tmp/krb5cc_* -al
-rw------- 1 root   root   1050 Feb 22 11:09 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
# kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error 
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]
Quoted 6 lines

Valid starting Expires Service principal
02/22/2017 11:27:41 03/04/2017 11:27:41 krbtgt/[email protected] 02/22/2017 11:27:41 03/04/2017 11:27:41 cifs/[email protected]

Let's take this to the linux-cifs mailing list...

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: problem when testing recent cifs.upcall

Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57 krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59 krbtgt/[email protected] 02/23/2017 13:05:59 03/05/2017 13:05:59 cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after trying to cd obs-cos]
vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs
to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 . ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Feb 23 13:05:59 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb02.physics.wisc.edu;ip4=128.104.164.79;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x3397
Feb 23 13:05:59 trog cifs.upcall: ver=2
Feb 23 13:05:59 trog cifs.upcall: host=smb02.physics.wisc.edu
Feb 23 13:05:59 trog cifs.upcall: ip=128.104.164.79
Feb 23 13:05:59 trog cifs.upcall: sec=1
Feb 23 13:05:59 trog cifs.upcall: uid=0
Feb 23 13:05:59 trog cifs.upcall: creduid=0
Feb 23 13:05:59 trog cifs.upcall: [email protected]
Feb 23 13:05:59 trog cifs.upcall: pid=13207
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:59 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:59 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:05:59 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb02.physics.wisc.edu
Feb 23 13:05:59 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:59 trog cifs.upcall: Exit status 0
Feb 23 13:05:59 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb02.physics.wisc.edu;ip4=128.104.164.79;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:05:59 trog cifs.upcall: ver=2
Feb 23 13:05:59 trog cifs.upcall: host=smb02.physics.wisc.edu
Feb 23 13:05:59 trog cifs.upcall: ip=128.104.164.79
Feb 23 13:05:59 trog cifs.upcall: sec=1
Feb 23 13:05:59 trog cifs.upcall: uid=1494
Feb 23 13:05:59 trog cifs.upcall: creduid=1494
Feb 23 13:05:59 trog cifs.upcall: pid=26405
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:05:59 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:05:59 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:05:59 trog cifs.upcall: Exit status 1
Feb 23 13:06:03 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb02.physics.wisc.edu;ip4=128.104.164.79;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6ba0
Feb 23 13:06:03 trog cifs.upcall: ver=2
Feb 23 13:06:03 trog cifs.upcall: host=smb02.physics.wisc.edu
Feb 23 13:06:03 trog cifs.upcall: ip=128.104.164.79
Feb 23 13:06:03 trog cifs.upcall: sec=1
Feb 23 13:06:03 trog cifs.upcall: uid=1494
Feb 23 13:06:03 trog cifs.upcall: creduid=1494
Feb 23 13:06:03 trog cifs.upcall: pid=27552
Feb 23 13:06:03 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27552/environ
Feb 23 13:06:03 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:06:03 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:06:03 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:06:03 trog cifs.upcall: Exit status 1

Thanks for your work!
Chad.

A message that is not in the archive (sent off-list or not yet received): f922a603-0095-b86a-27a0-c7a6064e93d3-JAjqph6Yjy/[email protected]

#10 lore raw

Re: problem when testing recent cifs.upcall

Quoted 202 lines · Chad William Seys
Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57 krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al

(quoted diff) +0 -2
-rw------- 1 root   root   1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys  939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
(quoted diff) +0 -2
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59 krbtgt/[email protected] 02/23/2017 13:05:59 03/05/2017 13:05:59 cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after trying to cd obs-cos] vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

Quoted 6 lines

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 .
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yep, that's clearly the issue. The question is how you're ending up in that situation...

Regardless of how it's happening to you, it's probably possible to fool the environment scraping like this, by triggering a krb5 upcall from the context of a setuid program that has inherited the KRB5CCNAME environment variable from an unprivileged process.

I'm not sure what we can reasonably do about that. I suppose it might be interesting to dump the Uid: line from /proc/pid/status when we do this upcall, and see what all of the values are set to. Maybe we can reject using the credcache if the uid in the upcall doesn't match one of the values?

I'll see if I can cook up a debug patch sometime soon for that.

Quoted 58 lines
Feb 23 13:05:59 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb02.physics.wisc.edu;ip4=128.104.164.79;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x3397
Feb 23 13:05:59 trog cifs.upcall: ver=2
Feb 23 13:05:59 trog cifs.upcall: host=smb02.physics.wisc.edu
Feb 23 13:05:59 trog cifs.upcall: ip=128.104.164.79
Feb 23 13:05:59 trog cifs.upcall: sec=1
Feb 23 13:05:59 trog cifs.upcall: uid=0
Feb 23 13:05:59 trog cifs.upcall: creduid=0
Feb 23 13:05:59 trog cifs.upcall: [email protected]
Feb 23 13:05:59 trog cifs.upcall: pid=13207
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:59 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:59 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:05:59 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb02.physics.wisc.edu
Feb 23 13:05:59 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:59 trog cifs.upcall: Exit status 0
Feb 23 13:05:59 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb02.physics.wisc.edu;ip4=128.104.164.79;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:05:59 trog cifs.upcall: ver=2
Feb 23 13:05:59 trog cifs.upcall: host=smb02.physics.wisc.edu
Feb 23 13:05:59 trog cifs.upcall: ip=128.104.164.79
Feb 23 13:05:59 trog cifs.upcall: sec=1
Feb 23 13:05:59 trog cifs.upcall: uid=1494
Feb 23 13:05:59 trog cifs.upcall: creduid=1494
Feb 23 13:05:59 trog cifs.upcall: pid=26405
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:05:59 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:05:59 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:05:59 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:05:59 trog cifs.upcall: Exit status 1
Feb 23 13:06:03 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb02.physics.wisc.edu;ip4=128.104.164.79;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6ba0
Feb 23 13:06:03 trog cifs.upcall: ver=2
Feb 23 13:06:03 trog cifs.upcall: host=smb02.physics.wisc.edu
Feb 23 13:06:03 trog cifs.upcall: ip=128.104.164.79
Feb 23 13:06:03 trog cifs.upcall: sec=1
Feb 23 13:06:03 trog cifs.upcall: uid=1494
Feb 23 13:06:03 trog cifs.upcall: creduid=1494
Feb 23 13:06:03 trog cifs.upcall: pid=27552
Feb 23 13:06:03 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27552/environ
Feb 23 13:06:03 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:06:03 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:06:03 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:06:03 trog cifs.upcall: Exit status 1

Thanks for your work!
Chad.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: problem when testing recent cifs.upcall

Quoted 218 lines · Jeff Layton
Quoted 202 lines · Chad William Seys
Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57 krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al

(quoted diff) +0 -2
-rw------- 1 root   root   1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys  939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
(quoted diff) +0 -2
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59 krbtgt/[email protected] 02/23/2017 13:05:59 03/05/2017 13:05:59 cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after trying to cd obs-cos] vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

Quoted 6 lines

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 .
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yep, that's clearly the issue. The question is how you're ending up in that situation...

Regardless of how it's happening to you, it's probably possible to fool the environment scraping like this, by triggering a krb5 upcall from the context of a setuid program that has inherited the KRB5CCNAME environment variable from an unprivileged process.

Quoted 8 lines

I'm not sure what we can reasonably do about that. I suppose it might be interesting to dump the Uid: line from /proc/pid/status when we do this upcall, and see what all of the values are set to. Maybe we can reject using the credcache if the uid in the upcall doesn't match one of the values?

I'll see if I can cook up a debug patch sometime soon for that.

Just out of curiousity. As that unprivileged user, what do you get back
if you do this?

    $ which cd ; ls -l `which cd`

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: problem when testing recent cifs.upcall

Quoted 228 lines · Jeff Layton
Quoted 218 lines · Jeff Layton
Quoted 202 lines · Chad William Seys
Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57 krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al

(quoted diff) +0 -2
-rw------- 1 root   root   1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys  939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
(quoted diff) +0 -2
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59 krbtgt/[email protected] 02/23/2017 13:05:59 03/05/2017 13:05:59 cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after trying to cd obs-cos] vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

Quoted 6 lines

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 .
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yep, that's clearly the issue. The question is how you're ending up in that situation...

Regardless of how it's happening to you, it's probably possible to fool the environment scraping like this, by triggering a krb5 upcall from the context of a setuid program that has inherited the KRB5CCNAME environment variable from an unprivileged process.

Quoted 8 lines

I'm not sure what we can reasonably do about that. I suppose it might be interesting to dump the Uid: line from /proc/pid/status when we do this upcall, and see what all of the values are set to. Maybe we can reject using the credcache if the uid in the upcall doesn't match one of the values?

I'll see if I can cook up a debug patch sometime soon for that.

Quoted 6 lines

Just out of curiousity. As that unprivileged user, what do you get back
if you do this?

    $ which cd ; ls -l `which cd`

Thanks,

Nevermind, I see the problem. From follow_automount in the pathwalking code:

        old_cred = override_creds(&init_cred); mnt = path->dentry->d_op->d_automount(path); revert_creds(old_cred);

So we end up overriding the process creds in order to do the automount, which leads to exactly this problem.

I think the best we can do here is probably to just not do the environment scraping if the uid is 0. It's pretty hacky, but hey, we're already in rather nasty hack territory as it is.

Thoughts?

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw

Re: problem when testing recent cifs.upcall

Quoted 243 lines · Jeff Layton
Quoted 228 lines · Jeff Layton
Quoted 218 lines · Jeff Layton
Quoted 202 lines · Chad William Seys
Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57 krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al

(quoted diff) +0 -2
-rw------- 1 root   root   1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys  939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
(quoted diff) +0 -2
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59 krbtgt/[email protected] 02/23/2017 13:05:59 03/05/2017 13:05:59 cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after trying to cd obs-cos] vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

Quoted 6 lines

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 .
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yep, that's clearly the issue. The question is how you're ending up in that situation...

Regardless of how it's happening to you, it's probably possible to fool the environment scraping like this, by triggering a krb5 upcall from the context of a setuid program that has inherited the KRB5CCNAME environment variable from an unprivileged process.

Quoted 8 lines

I'm not sure what we can reasonably do about that. I suppose it might be interesting to dump the Uid: line from /proc/pid/status when we do this upcall, and see what all of the values are set to. Maybe we can reject using the credcache if the uid in the upcall doesn't match one of the values?

I'll see if I can cook up a debug patch sometime soon for that.

Quoted 6 lines

Just out of curiousity. As that unprivileged user, what do you get back
if you do this?

    $ which cd ; ls -l `which cd`

Thanks,

Nevermind, I see the problem. From follow_automount in the pathwalking code:

        old_cred = override_creds(&init_cred);
        mnt = path->dentry->d_op->d_automount(path);
        revert_creds(old_cred);
Quoted 8 lines

So we end up overriding the process creds in order to do the automount, which leads to exactly this problem.

I think the best we can do here is probably to just not do the environment scraping if the uid is 0. It's pretty hacky, but hey, we're already in rather nasty hack territory as it is.

Thoughts?

Can't we detect that the process has changed id ?
Cutting off root may be a way, but I can see how some peoepl may want root too to be able to mount and walk cifs shares ...

Simo.

#17 lore raw

Re: problem when testing recent cifs.upcall

Quoted 258 lines · Simo Sorce
Quoted 257 lines · Jeff Layton
Quoted 239 lines · Jeff Layton
Quoted 229 lines · Jeff Layton
Quoted 213 lines · Chad William Seys
Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:Simo.>

Quoted 1 line

--> To unsubscribe from this list: send the line

"unsubscribe linux-cifs" in> the body of a message to [email protected]> More majordomo info at http://vge
r.kernel.org/majordomo-info.html

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57
krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al

(quoted diff) +0 -2
-rw------- 1 root   root   1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys  939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01
krbtgt/[email protected]
02/23/2017 13:00:01 03/05/2017 13:00:01
cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to

gSimo.>

Quoted 1 line

--> To unsubscribe from this list: send the line

"unsubscribe linux-cifs" in> the body of a message to [email protected]> More majordomo info at http://vge
r.kernel.org/majordomo-info.html
et principal

Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
(quoted diff) +0 -2
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59
krbtgt/[email protected]
02/23/2017 13:05:59 03/05/2017 13:05:59
cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01
krbtgt/[email protected]
02/23/2017 13:00:01 03/05/2017 13:00:01
cifs/[email protected]

[debug.log after trying to cd obs-cos] vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

Quoted 6 lines

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 .
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yep, that's clearly the issue. The question is how you're ending up in that situation...

Regardless of how it's happening to you, it's probably possible to fool the environment scraping like this, by triggering a krb5 upcall from the context of a setuid program that has inherited the KRB5CCNAME environment variable from an unprivileged process.

Quoted 8 lines

I'm not sure what we can reasonably do about that. I suppose it might be interesting to dump the Uid: line from /proc/pid/status when we do this upcall, and see what all of the values are set to. Maybe we can reject using the credcache if the uid in the upcall doesn't match one of the values?

I'll see if I can cook up a debug patch sometime soon for that.

Quoted 6 lines

Just out of curiousity. As that unprivileged user, what do you get back
if you do this?

    $ which cd ; ls -l `which cd`

Thanks,

Nevermind, I see the problem. From follow_automount in the pathwalking code:

        old_cred = override_creds(&init_cred);
        mnt = path->dentry->d_op->d_automount(path);
        revert_creds(old_cred);

So we end up overriding the process creds in order to do the automount, which leads to exactly this problem.

Quoted 8 lines
Quoted 5 lines

I think the best we can do here is probably to just not do the environment scraping if the uid is 0. It's pretty hacky, but hey, we're already in rather nasty hack territory as it is.

Thoughts?

Can't we detect that the process has changed id ?

How? The credentials are completely overridden with the init_creds once we get into d_automount.

Quoted 4 lines

Cutting off root may be a way, but I can see how some peoepl may want root too to be able to mount and walk cifs shares ...

Well, root still can with this patch -- just not if his credcache is in a non-default location.

The other option is to just unset the environment var. That will probably fix Chad's issue, but my worry there is that root's session setup can end up being done with the wrong credcache if cwseys had a valid one when he triggers the automount.

Maybe the right fix is to have mount creds be separate from root's creds altogether. You'd have a duplicate session for root in most cases, but maybe that's ok?

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw

Re: problem when testing recent cifs.upcall

Quoted 279 lines · Jeff Layton
Quoted 258 lines · Simo Sorce
Quoted 257 lines · Jeff Layton
Quoted 239 lines · Jeff Layton
Quoted 229 lines · Jeff Layton
Quoted 213 lines · Chad William Seys
Quoted 3 lines

To be clear...I assume that you have a keytab set up someplace that has the smbadmin@ credentials in it, correct? That's the only way that cifs.upcall would instantiate a new credcache.

Right. smbadmin@ credentials are in /etc/krb5.keytab. 'mount' must check there by default.

Quoted 3 lines

It sounds like you're walking into the DFS mount in a task that is running as root, but that has inherited a KRB5CCNAME environment variable from a cwseys@ login session.

The task that is walking into the DFS mount is running as 'cwseys' . My guess is that when cwseys tries to cd into DFS mount, cifs.upcall or the kernel is using the wrong name for root's credential cache.

Quoted 2 lines

It might be nice to see the debug level output from syslog, so we can tell what's actually happening in the upcall. Can you provide that?

cwseys:Simo.>

Quoted 1 line

--> To unsubscribe from this list: send the line

"unsubscribe linux-cifs" in> the body of a message to [email protected]> More majordomo info at http://vge
r.kernel.org/majordomo-info.html

$ kdestroy
$ cd /

root:

# umount /smb
# umount /smb  # to be sure!
# kdestroy
#  ls /tmp/krb5cc_* -al
ls: cannot access '/tmp/krb5cc_*': No such file or directory

cwseys:

$ kinit
Password for [email protected]:
$ ls /tmp/krb5cc_* -al
-rw------- 1 cwseys cwseys 939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
$ klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 12:59:00 03/05/2017 12:58:57 krbtgt/[email protected]

root:

# mount -t cifs //smb.physics.wisc.edu/smb /smb
-osec=krb5,multiuser,[email protected] --verbose
mount.cifs kernel mount options:
ip=128.104.160.17,unc=\\smb.physics.wisc.edu\smb,sec=krb5,multiuser,[email protected],pass=********

# ls /tmp/krb5cc_* -al

(quoted diff) +0 -2
-rw------- 1 root   root   1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 cwseys cwseys  939 Feb 23 12:59 /tmp/krb5cc_1494_sM11PG
# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after mount]

Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160
.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to get principal
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x0;creduid=0x0;[email protected];pid=0x6abf
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=0
Feb 23 13:00:01 trog cifs.upcall: creduid=0
Feb 23 13:00:01 trog cifs.upcall: [email protected]
Feb 23 13:00:01 trog cifs.upcall: pid=27327
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/27327/environ
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_0
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:00:01 trog cifs.upcall: Exit status 0
Feb 23 13:00:01 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x6725
Feb 23 13:00:01 trog cifs.upcall: ver=2
Feb 23 13:00:01 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:00:01 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:00:01 trog cifs.upcall: sec=1
Feb 23 13:00:01 trog cifs.upcall: uid=1494
Feb 23 13:00:01 trog cifs.upcall: creduid=1494
Feb 23 13:00:01 trog cifs.upcall: pid=26405
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/26405/environ
Feb 23 13:00:01 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_bkfO2z
Feb 23 13:00:01 trog cifs.upcall: get_tgt_time: unable to

gSimo.>

Quoted 1 line

--> To unsubscribe from this list: send the line

"unsubscribe linux-cifs" in> the body of a message to [email protected]> More majordomo info at http://vge
r.kernel.org/majordomo-info.html
et principal

Feb 23 13:00:01 trog cifs.upcall: Exit status 1

cwseys:

$ cd /smb

[debug.log after cd /smb]

Feb 23 13:05:20 trog cifs.upcall: key description:
cifs.spnego;0;0;39010000;ver=0x2;host=smb.physics.wisc.edu;ip4=128.104.160.17;sec=krb5;uid=0x5d6;creduid=0x5d6;pid=0x3397
Feb 23 13:05:20 trog cifs.upcall: ver=2
Feb 23 13:05:20 trog cifs.upcall: host=smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: ip=128.104.160.17
Feb 23 13:05:20 trog cifs.upcall: sec=1
Feb 23 13:05:20 trog cifs.upcall: uid=1494
Feb 23 13:05:20 trog cifs.upcall: creduid=1494
Feb 23 13:05:20 trog cifs.upcall: pid=13207
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
pathname=/proc/13207/environ
Feb 23 13:05:20 trog cifs.upcall: get_cachename_from_process_env:
cachename = FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: get_existing_cc: default ccache is
FILE:/tmp/krb5cc_1494_sM11PG
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: getting service
ticket for smb.physics.wisc.edu
Feb 23 13:05:20 trog cifs.upcall: handle_krb5_mech: obtained service ticket
Feb 23 13:05:20 trog cifs.upcall: Exit status 0
$ kdestroy
$ ls /tmp/krb5cc_* -al
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
# obs-cos is on a different server - DFS linked.
$ cd obs-cos
$ ls
ls: cannot open directory '.': Permission denied
# kerberos cache file created with root owner/group !
# The file has bytes in it, but not matching the size above. Wonder
# what's in it... ?
$ ls /tmp/krb5cc_* -al
(quoted diff) +0 -2
-rw------- 1 root root 1046 Feb 23 13:00 /tmp/krb5cc_0
-rw------- 1 root root 1050 Feb 23 13:05 /tmp/krb5cc_1494_sM11PG
# now cannot kinit
$ kinit
Password for [email protected]:
kinit: Failed to store credentials: Internal credentials cache error
(filename: /tmp/krb5cc_1494_sM11PG) while getting initial credentials

root:

# lets look in the credential cache that was created by root.
# looks like credentials used by root to mount /smb:
# My guess is the kernel was trying to stash the
# cifs/[email protected]
# kerberos ticket, but put it in krb5cc_1494_sM11PG instead
# of krb5cc_0
# klist -c /tmp/krb5cc_1494_sM11PG
Ticket cache: FILE:/tmp/krb5cc_1494_sM11PG
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:05:59 03/05/2017 13:05:59 krbtgt/[email protected] 02/23/2017 13:05:59 03/05/2017 13:05:59 cifs/[email protected]

# klist -c /tmp/krb5cc_0
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting Expires Service principal
02/23/2017 13:00:01 03/05/2017 13:00:01 krbtgt/[email protected] 02/23/2017 13:00:01 03/05/2017 13:00:01 cifs/[email protected]

[debug.log after trying to cd obs-cos] vvvvvvvvvvvvvvvvvvvvvvvvvvvv
I think the error is here: Notice pid=13207, that belongs to cwseys but cifs.upcall key description is trying to use uid=0 and creduid=0 . The credential cache file is correct, but the uid/creduid are not.

Quoted 6 lines

cwseys 13207 /bin/bash

Also, in the above the log from 'cd /smb' cifs.upcall used uid=1494 and creduid=1494 .
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yep, that's clearly the issue. The question is how you're ending up in that situation...

Regardless of how it's happening to you, it's probably possible to fool the environment scraping like this, by triggering a krb5 upcall from the context of a setuid program that has inherited the KRB5CCNAME environment variable from an unprivileged process.

Quoted 8 lines

I'm not sure what we can reasonably do about that. I suppose it might be interesting to dump the Uid: line from /proc/pid/status when we do this upcall, and see what all of the values are set to. Maybe we can reject using the credcache if the uid in the upcall doesn't match one of the values?

I'll see if I can cook up a debug patch sometime soon for that.

Quoted 6 lines

Just out of curiousity. As that unprivileged user, what do you get back
if you do this?

    $ which cd ; ls -l `which cd`

Thanks,

Nevermind, I see the problem. From follow_automount in the pathwalking code:

        old_cred = override_creds(&init_cred);
        mnt = path->dentry->d_op->d_automount(path);
        revert_creds(old_cred);

So we end up overriding the process creds in order to do the automount, which leads to exactly this problem.

Quoted 8 lines
Quoted 5 lines

I think the best we can do here is probably to just not do the environment scraping if the uid is 0. It's pretty hacky, but hey, we're already in rather nasty hack territory as it is.

Thoughts?

Can't we detect that the process has changed id ?

How? The credentials are completely overridden with the init_creds once we get into d_automount.

Quoted 4 lines

Cutting off root may be a way, but I can see how some peoepl may want root too to be able to mount and walk cifs shares ...

Well, root still can with this patch -- just not if his credcache is in a non-default location.

Quoted 8 lines

The other option is to just unset the environment var. That will probably fix Chad's issue, but my worry there is that root's session setup can end up being done with the wrong credcache if cwseys had a valid one when he triggers the automount.

Maybe the right fix is to have mount creds be separate from root's creds altogether. You'd have a duplicate session for root in most cases, but maybe that's ok?

Sounds sensible, with cifs specifically you may want to use "machine creds" to mount, and then root creds to walk on the filesystem.

Simo.

#20 lore raw

PATCH v4 3/4 cifs.upcall: drop capabilities early in program

In reply to a message not in the archive

Much of cifs.upcall can and should be run without elevated privileges. On entry into the program, drop as many capabilities as we can get away with, and then always drop any remaining caps after calling setuid().

---
 Makefile.am   |  2 +-
 cifs.upcall.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)
Makefile.am +1 -1
index 2e99e601049a..4823b6381082 100644
@@ -16,7 +16,7 @@ clean-local: clean-local-upcall clean-local-idmap clean-local-cifsacl
 if CONFIG_CIFSUPCALL
 sbin_PROGRAMS += cifs.upcall
 cifs_upcall_SOURCES = cifs.upcall.c data_blob.c asn1.c spnego.c
-cifs_upcall_LDADD = -ltalloc -lkeyutils $(KRB5_LDADD)
+cifs_upcall_LDADD = -ltalloc -lkeyutils $(KRB5_LDADD) $(CAPNG_LDADD)
 man_MANS += cifs.upcall.8
 
 #
cifs.upcall.c +63 -0

87 lines not on this page · raw message

Signature · 1 line
2.9.3
#21 lore raw

PATCH v4 4/4 cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's /proc/<pid>/environ file

In reply to a message not in the archive

Chad reported that he was seeing a regression in cifs-utils-6.6. Prior to that, cifs.upcall was able to find credcaches in non-default FILE:
locations, but with the rework of that code, that ability was lost.

Unfortunately, the krb5 library design doesn't really take into account the fact that we might need to find a credcache in a process that isn't descended from the session.

When the kernel does an upcall, it passes several bits of info about the task that initiated the upcall. One of those things is the PID (the tgid, in particular). We can use that info to reach into the /proc/<pid>/environ file for the process, and grab whatever value of $KRB5CCNAME is there.

Then, after switching credentials, set $KRB5CCNAME in the environment to the same value before opening the credcache, to hint to the krb5 libs where they ought to look.

This new behavior is on by default, but can be disabled by having request-key pass a '-E' flag to cifs.upcall.

---
 cifs.upcall.8.in |   9 ++++
 cifs.upcall.c    | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 152 insertions(+), 7 deletions(-)
cifs.upcall.8.in +9 -0
index 50f79d18331d..e1f3956e176a 100644
@@ -38,6 +38,15 @@ for a particular key type\&. While it can be run directly from the command\-line
 This option is deprecated and is currently ignored\&.
 .RE
 .PP
+\-\-no-env-probe|\-E
+.RS 4
+Normally, cifs.upcall will probe the environment variable space of the process
+that initiated the upcall in order to fetch the value of $KRB5CCNAME. This can
+assist the program with finding credential caches in non-default locations. If
+this option is set, then the program won't do this and will rely on finding
+credcaches in the default locations specified in krb5.conf.
+.RE
+.PP
 \--krb5conf=/path/to/krb5.conf|-k /path/to/krb5.conf
 .RS 4
 This option allows administrators to set an alternate location for the
cifs.upcall.c +143 -7

233 lines not on this page · raw message

Signature · 1 line
2.9.3
#22 lore raw
In reply to a message not in the archive
Quoted 18 lines · Jeff Layton

Apologies for v3 series, I had some extra patches in there. This is the one that should have been sent. Relabeled as v4 for clarity.

Third respin of this series. Reordered for better safety for bisecting. The environment scraping is now on by default, but can be disabled with "-E" in environments where it's not needed.

Also, I've added a patch to make cifs.upcall drop capabilities before doing most of its work. This may help reduce the attack surface of the program.

Jeff Layton (4):
cifs.upcall: convert two flags from int to bool cifs.upcall: switch group IDs when handling an upcall cifs.upcall: drop capabilities early in program cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's
/proc/<pid>/environ file

Quoted 5 lines
 Makefile.am      |   2 +-
 cifs.upcall.8.in |   9 ++
 cifs.upcall.c    | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 256 insertions(+), 10 deletions(-)

You can add a reviewed-by with my name.

Simo.

Signature · 1 line
Simo Sorce * Red Hat, Inc * New York