Skip to contentSkip to conversation

cifs.upcall: allow cifs.upcall to grab $KRB5CCNAME from initiating process

PATCH In review Jeff Layton 2 participants 4 messages Feb 14, 2017 1 message not in the archive

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

v2 cover cifs.upcall: allow cifs.upcall to grab $KRB5CCNAME from initiating process

Small respin of the patches that I posted a few days ago. The main difference is the reordering of the series to make it do the group and grouplist manipulation first, and then the patch that makes it grab the KRB5CCNAME from the initiating process.

I think the code is sound, my main question is whether we really need the command-line switch for this. Should this just be the default mode of operation?

Jeff Layton (2):
cifs.upcall: switch group IDs when handling an upcall cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's
/proc/<pid>/environ file

 cifs.upcall.8.in |  10 +++
 cifs.upcall.c    | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 189 insertions(+), 6 deletions(-)
Signature · 1 line
2.9.3

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

#2 lore raw

PATCH v2 1/2 cifs.upcall: switch group IDs when handling an upcall

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 8f146c92b4a5..122b6a7a324a 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"
@@ -693,6 +695,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));
@@ -794,15 +797,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
#3 lore raw

PATCH v2 2/2 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. This patch adds this ability to cifs.upcall.

I'm not 100% convinced that this is a good idea however, so for now, this is disabled unless the command line has a '-e' switch. Anyone wishing to play with this should edit their /etc/request-key.conf files accordingly.

---
 cifs.upcall.8.in |  10 ++++
 cifs.upcall.c    | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 152 insertions(+), 6 deletions(-)
cifs.upcall.8.in +10 -0
index 50f79d18331d..06c6d3a02c2f 100644
@@ -38,6 +38,16 @@ 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
+\-\-env-probe|\-e
+.RS 4
+Allow cifs.upcall to do an environment probe to help find the credential
+cache. This can assist the program with finding credential caches in
+non-default locations. If this is set, then the program will attempt to
+retrieve the KRB5CCNAME environment variable from the process that initiated
+the upcall, and then set that in the upcall process for use when searching for
+a credcache.
+.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 +142 -6

225 lines not on this page · raw message

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

Small respin of the patches that I posted a few days ago. The main difference is the reordering of the series to make it do the group and grouplist manipulation first, and then the patch that makes it grab the KRB5CCNAME from the initiating process.

I think the code is sound, my main question is whether we really need the command-line switch for this. Should this just be the default mode of operation?

Jeff Layton (2):
  cifs.upcall: switch group IDs when handling an upcall cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's /proc/<pid>/environ file

Quoted 4 lines

 cifs.upcall.8.in |  10 +++
 cifs.upcall.c    | 185
+++++++++++++++++++++++++++++++++++++++++++++++++++++--

 2 files changed, 189 insertions(+), 6 deletions(-)

I think I'd make it the default, but maybe leave a way to disable env scraping with a reverse flag.

Simo.