Skip to contentSkip to conversation

gssd: add the GSSAPI acceptor name to the info passed in downcall

PATCH Superseded Jeff Layton 3 participants 13 messages Apr 10, 2014 – Apr 14, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/5 gssd: handle malloc failure appropriately in do_downcall

In reply to Jeff Layton

...and get rid of some pointless NULL ptr checks.

---
 utils/gssd/gssd_proc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
utils/gssd/gssd_proc.c +5 -2
index 33cfeb2afd2e..5f7fb32c41b5 100644
@@ -694,6 +694,9 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
 		sizeof(context_token->length) + context_token->length;
 	p = buf = malloc(buf_size);
+	if (!buf)
+		goto out_err;
+
 	end = buf + buf_size;
 
 	/* context_timeout set by -t option overrides context lifetime */
@@ -706,10 +709,10 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (write_buffer(&p, end, context_token)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
-	if (buf) free(buf);
+	free(buf);
 	return 0;
 out_err:
-	if (buf) free(buf);
+	free(buf);
 	printerr(1, "Failed to write downcall!\n");
 	return -1;
 }
Signature · 1 line
1.9.0
#2 lore raw

PATCH 2/5 gssd: make do_downcall a void return

In reply to Jeff Layton

...since its return code is ignored anyway.

---
 utils/gssd/gssd_proc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
utils/gssd/gssd_proc.c +3 -3
index 5f7fb32c41b5..7387cce010cf 100644
@@ -681,7 +681,7 @@ parse_enctypes(char *enctypes)
 	return 0;
 }
 
-static int
+static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
 {
@@ -710,11 +710,11 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
-	return 0;
+	return;
 out_err:
 	free(buf);
 	printerr(1, "Failed to write downcall!\n");
-	return -1;
+	return;
 }
 
 static int
Signature · 1 line
1.9.0
#3 lore raw

PATCH 3/5 gssd: move hostbased name routines into separate file

In reply to Jeff Layton

In a later patch, we'll need gssd to call into this code as well as svcgssd. Move it into a common file that both can link in.

---
 utils/gssd/Makefile.am    |   2 +
 utils/gssd/gss_names.c    | 123 ++++++++++++++++++++++++++++++++++++++++++++++
 utils/gssd/gss_names.h    |  34 +++++++++++++
 utils/gssd/svcgssd_proc.c |  66 +------------------------
 4 files changed, 160 insertions(+), 65 deletions(-)
 create mode 100644 utils/gssd/gss_names.c
 create mode 100644 utils/gssd/gss_names.h
utils/gssd/Makefile.am +2 -0
index a9a3e42de19d..af597918e8e0 100644
@@ -18,11 +18,13 @@ COMMON_SRCS = \
 	context_lucid.c \
 	gss_util.c \
 	gss_oids.c \
+	gss_names.c \
 	err_util.c \
 	\
 	context.h \
 	err_util.h \
 	gss_oids.h \
+	gss_names.h \
 	gss_util.h
 
 gssd_SOURCES = \
utils/gssd/gss_names.c new file +123 -0

123 lines not on this page · raw message

utils/gssd/gss_names.h new file +34 -0
new file mode 100644
index 000000000000..1d5f49c1c1d2
@@ -0,0 +1,34 @@
+/*
+  Copyright (c) 2000 The Regents of the University of Michigan.
+  All rights reserved.
+
+  Copyright (c) 2002 Bruce Fields <[email protected]>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of the University nor the names of its
+     contributors may be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+extern int get_hostbased_client_name(gss_name_t client_name, gss_OID mech,
+					char **hostbased_name);
utils/gssd/svcgssd_proc.c +1 -65

78 lines not on this page · raw message

Signature · 1 line
1.9.0
#4 lore raw

PATCH 4/5 gssd: add new routine for generating a hostbased principal in a gss_buffer_t

In reply to Jeff Layton

We'll need a gss_buffer_t to pass to the downcall marshalling code.

---
 utils/gssd/gss_names.c | 15 +++++++++++++++
 utils/gssd/gss_names.h |  2 ++
 2 files changed, 17 insertions(+)
utils/gssd/gss_names.c +15 -0
index aa61e4d7a851..047069de1755 100644
@@ -121,3 +121,18 @@ out_rel_buf:
 out_err:
 	return res;
 }
+
+void
+get_hostbased_client_buffer(gss_name_t client_name, gss_OID mech,
+			    gss_buffer_t buf)
+{
+	char *hname;
+
+	if (!get_hostbased_client_name(client_name, mech, &hname)) {
+		buf->length = strlen(hname) + 1;
+		buf->value = hname;
+	} else {
+		buf->length = 0;
+		buf->value = NULL;
+	}
+}
utils/gssd/gss_names.h +2 -0
index 1d5f49c1c1d2..ce182f7985f3 100644
@@ -32,3 +32,5 @@
 
 extern int get_hostbased_client_name(gss_name_t client_name, gss_OID mech,
 					char **hostbased_name);
+extern void get_hostbased_client_buffer(gss_name_t client_name,
+			gss_OID mech, gss_buffer_t buf);
Signature · 1 line
1.9.0
#5 lore raw

PATCH 5/5 gssd: scrape the acceptor name out of the context

In reply to Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +28 -11
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.
+	 */
 	if (serialize_context_for_kernel(&pd.pd_ctx, &token, &krb5oid, NULL)) {
 		printerr(0, "WARNING: Failed to serialize krb5 context for "
 			    "user with uid %d for server %s\n",
@@ -1190,9 +1206,10 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	do_downcall(fd, uid, &pd, &token, lifetime_rec);
+	do_downcall(fd, uid, &pd, &token, lifetime_rec, &acceptor);
 
 out:
+	gss_release_buffer(&min_stat, &acceptor);
 	if (token.value)
 		free(token.value);
 #ifdef HAVE_AUTHGSS_FREE_PRIVATE_DATA
Signature · 1 line
1.9.0
#0 lore raw

cover gssd: add the GSSAPI acceptor name to the info passed in downcall

Recently, I started a mailing list thread about some authentication failures that I was seeing on the callback channel when krb5 was in use.

After a bit of discussion we determined that the right way to fix it was to save off the GSSAPI acceptor name used in the SETCLIENT call, and then ensure that the same principal is used in callback requests.

This patchset is the userland portion of that change. It basically just adds the acceptor name to the downcall, immediately following the context token. Older kernel will just ignore this data, so this should be safe.

There is also a companion kernel patchset that will allow the kernel to save off this info for later usage.

Jeff Layton (5):
gssd: handle malloc failure appropriately in do_downcall
gssd: make do_downcall a void return
gssd: move hostbased name routines into separate file
gssd: add new routine for generating a hostbased principal in a
gss_buffer_t
gssd: scrape the acceptor name out of the context

 utils/gssd/Makefile.am    |   2 +
 utils/gssd/gss_names.c    | 138 ++++++++++++++++++++++++++++++++++++++++++++++
 utils/gssd/gss_names.h    |  36 ++++++++++++
 utils/gssd/gssd_proc.c    |  52 +++++++++++------
 utils/gssd/svcgssd_proc.c |  66 +---------------------
 5 files changed, 213 insertions(+), 81 deletions(-)
 create mode 100644 utils/gssd/gss_names.c
 create mode 100644 utils/gssd/gss_names.h
Signature · 1 line
1.9.0
#6 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

In reply to Jeff Layton
Quoted 46 lines · On Thu, 10 Apr 2014 16:31:03 -0400 Jeff Layton <[email protected]> wrote:

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +7 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;

utils/gssd/gssd_proc.c do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd, · line 715

Quoted 5 lines
utils/gssd/gssd_proc.c +2 -0
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;

I think I'll need to make a minor change to this patch. In the event that the acceptor has zero length, then I think we still want to add the length to the downcall. That will allow us to extend the downcall format again in the future if needed.

The only thing I'll need to do to fix that is to remove the "acceptor->length > 0" check above. I'll do that and send a v2 patch once I've given everyone a chance to comment on the set.

Quoted 55 lines
utils/gssd/gssd_proc.c +19 -8
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.
+	 */
 	if (serialize_context_for_kernel(&pd.pd_ctx, &token, &krb5oid, NULL)) {
 		printerr(0, "WARNING: Failed to serialize krb5 context for "
 			    "user with uid %d for server %s\n",
@@ -1190,9 +1206,10 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	do_downcall(fd, uid, &pd, &token, lifetime_rec);
+	do_downcall(fd, uid, &pd, &token, lifetime_rec, &acceptor);
 
 out:
+	gss_release_buffer(&min_stat, &acceptor);
 	if (token.value)
 		free(token.value);
 #ifdef HAVE_AUTHGSS_FREE_PRIVATE_DATA
Signature · 1 line
Jeff Layton <[email protected]>
#7 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

In reply to Jeff Layton

Hey Jeff,

Just a couple nit....

Quoted 65 lines · Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +12 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1178

Quoted 5 lines
utils/gssd/gssd_proc.c +0 -2
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */

Why get rid of this comment instead of updating it?

Quoted 10 lines
utils/gssd/gssd_proc.c +4 -5
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1200

Quoted 10 lines
utils/gssd/gssd_proc.c +9 -0
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.

I'm not sure what you are trying to say here...

steved.

Quoted 17 lines
utils/gssd/gssd_proc.c +3 -1
+	 */
 	if (serialize_context_for_kernel(&pd.pd_ctx, &token, &krb5oid, NULL)) {
 		printerr(0, "WARNING: Failed to serialize krb5 context for "
 			    "user with uid %d for server %s\n",
@@ -1190,9 +1206,10 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	do_downcall(fd, uid, &pd, &token, lifetime_rec);
+	do_downcall(fd, uid, &pd, &token, lifetime_rec, &acceptor);
 
 out:
+	gss_release_buffer(&min_stat, &acceptor);
 	if (token.value)
 		free(token.value);
 #ifdef HAVE_AUTHGSS_FREE_PRIVATE_DATA
#8 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

Quoted 73 lines · On Mon, 14 Apr 2014 11:07:37 -0400 Steve Dickson <[email protected]> wrote:

Hey Jeff,

Just a couple nit....

Quoted 68 lines · Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +12 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
Quoted 4 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1178

Quoted 2 lines
utils/gssd/gssd_proc.c +0 -2
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */

Why get rid of this comment instead of updating it?

I suppose I could do that. Would you prefer I respin and update that comment instead?

Quoted 16 lines
Quoted 16 lines
utils/gssd/gssd_proc.c +9 -5
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
Quoted 8 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1200

Quoted 4 lines
utils/gssd/gssd_proc.c +4 -0
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.

I'm not sure what you are trying to say here...

steved.

Just a semi-helpful context for posterity...

On my initial attempt, I tried to change the code around to grab the lifetime and acceptor out of the context in do_downcall. That didn't work, because once you call serialize_context_for_kernel, the GSS context is turned into a "lucid context". At that point, things like gss_inquire_context no longer work on it.

IOW, once you call serialize_context_for_kernel, you can't count on being able to do anything useful with pd.pd_ctx at all.

Quoted 17 lines
Quoted 17 lines
utils/gssd/gssd_proc.c +3 -1
+	 */
 	if (serialize_context_for_kernel(&pd.pd_ctx, &token, &krb5oid, NULL)) {
 		printerr(0, "WARNING: Failed to serialize krb5 context for "
 			    "user with uid %d for server %s\n",
@@ -1190,9 +1206,10 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	do_downcall(fd, uid, &pd, &token, lifetime_rec);
+	do_downcall(fd, uid, &pd, &token, lifetime_rec, &acceptor);
 
 out:
+	gss_release_buffer(&min_stat, &acceptor);
 	if (token.value)
 		free(token.value);
 #ifdef HAVE_AUTHGSS_FREE_PRIVATE_DATA
Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

Quoted 76 lines · Jeff Layton
Quoted 73 lines · On Mon, 14 Apr 2014 11:07:37 -0400 Steve Dickson <[email protected]> wrote:

Hey Jeff,

Just a couple nit....

Quoted 68 lines · Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +12 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
Quoted 7 lines
Quoted 4 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1178

Quoted 2 lines
utils/gssd/gssd_proc.c +0 -2
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */

Why get rid of this comment instead of updating it?

I suppose I could do that. Would you prefer I respin and update that comment instead?

If you would not mind.... I may not get to it for a while... I'm going to be traveling this week...

thanks!

steved.

Quoted 58 lines
Quoted 17 lines
Quoted 17 lines
utils/gssd/gssd_proc.c +9 -5
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
Quoted 8 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1200

Quoted 4 lines
utils/gssd/gssd_proc.c +4 -0
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.

I'm not sure what you are trying to say here...

steved.

Just a semi-helpful context for posterity...

On my initial attempt, I tried to change the code around to grab the lifetime and acceptor out of the context in do_downcall. That didn't work, because once you call serialize_context_for_kernel, the GSS context is turned into a "lucid context". At that point, things like gss_inquire_context no longer work on it.

IOW, once you call serialize_context_for_kernel, you can't count on being able to do anything useful with pd.pd_ctx at all.

Quoted 17 lines
Quoted 17 lines
utils/gssd/gssd_proc.c +3 -1
+	 */
 	if (serialize_context_for_kernel(&pd.pd_ctx, &token, &krb5oid, NULL)) {
 		printerr(0, "WARNING: Failed to serialize krb5 context for "
 			    "user with uid %d for server %s\n",
@@ -1190,9 +1206,10 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
-	do_downcall(fd, uid, &pd, &token, lifetime_rec);
+	do_downcall(fd, uid, &pd, &token, lifetime_rec, &acceptor);
 
 out:
+	gss_release_buffer(&min_stat, &acceptor);
 	if (token.value)
 		free(token.value);
 #ifdef HAVE_AUTHGSS_FREE_PRIVATE_DATA
#10 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

In reply to Jeff Layton
Quoted 111 lines · Jeff Layton
Quoted 73 lines · On Mon, 14 Apr 2014 11:07:37 -0400 Steve Dickson <[email protected]> wrote:

Hey Jeff,

Just a couple nit....

Quoted 68 lines · Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +12 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
Quoted 4 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1178

Quoted 2 lines
utils/gssd/gssd_proc.c +0 -2
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */

Why get rid of this comment instead of updating it?

I suppose I could do that. Would you prefer I respin and update that comment instead?

Quoted 16 lines
Quoted 16 lines
utils/gssd/gssd_proc.c +9 -5
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
Quoted 8 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1200

Quoted 4 lines
utils/gssd/gssd_proc.c +4 -0
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.

I'm not sure what you are trying to say here...

steved.

Just a semi-helpful context for posterity...

Quoted 8 lines

On my initial attempt, I tried to change the code around to grab the lifetime and acceptor out of the context in do_downcall. That didn't work, because once you call serialize_context_for_kernel, the GSS context is turned into a "lucid context". At that point, things like gss_inquire_context no longer work on it.

IOW, once you call serialize_context_for_kernel, you can't count on being able to do anything useful with pd.pd_ctx at all.

This is on purpose, when you export the lucid context, the original context is destroyed, this is to avoid having 2 parties with a context for the same connection as the sequence numbers would get messed up and communication fail if 2 parties tried to use them at the same time anyway.

Simo.

Signature · 1 line
Simo Sorce * Red Hat, Inc * New York
#11 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

Quoted 118 lines · On Mon, 14 Apr 2014 14:36:34 -0400 Simo Sorce <[email protected]> wrote:
Quoted 117 lines · Jeff Layton
Quoted 73 lines · On Mon, 14 Apr 2014 11:07:37 -0400 Steve Dickson <[email protected]> wrote:

Hey Jeff,

Just a couple nit....

Quoted 68 lines · Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +12 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
Quoted 4 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1178

Quoted 2 lines
utils/gssd/gssd_proc.c +0 -2
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */

Why get rid of this comment instead of updating it?

I suppose I could do that. Would you prefer I respin and update that comment instead?

Quoted 16 lines
Quoted 16 lines
utils/gssd/gssd_proc.c +9 -5
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
Quoted 8 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1200

Quoted 4 lines
utils/gssd/gssd_proc.c +4 -0
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.

I'm not sure what you are trying to say here...

steved.

Just a semi-helpful context for posterity...

On my initial attempt, I tried to change the code around to grab the lifetime and acceptor out of the context in do_downcall. That didn't work, because once you call serialize_context_for_kernel, the GSS context is turned into a "lucid context". At that point, things like gss_inquire_context no longer work on it.

Quoted 9 lines
Quoted 2 lines

IOW, once you call serialize_context_for_kernel, you can't count on being able to do anything useful with pd.pd_ctx at all.

This is on purpose, when you export the lucid context, the original context is destroyed, this is to avoid having 2 parties with a context for the same connection as the sequence numbers would get messed up and communication fail if 2 parties tried to use them at the same time anyway.

Yes, I gathered that it's intentional behavior. You get back an error that basically means that the context handle is no longer valid when you try to use it. It's just not obvious that that's the case at this point in the code, so I figured it warranted a comment.

Signature · 1 line
Jeff Layton <[email protected]>
#12 lore raw

Re: [PATCH 5/5] gssd: scrape the acceptor name out of the context

Quoted 131 lines · Jeff Layton
Quoted 118 lines · On Mon, 14 Apr 2014 14:36:34 -0400 Simo Sorce <[email protected]> wrote:
Quoted 117 lines · Jeff Layton
Quoted 73 lines · On Mon, 14 Apr 2014 11:07:37 -0400 Steve Dickson <[email protected]> wrote:

Hey Jeff,

Just a couple nit....

Quoted 68 lines · Jeff Layton

...and pass it to the kernel in the downcall. Legacy kernels will just ignore the extra data, but with a proposed kernel patch the kernel will grab this info and use it to verify requests on the v4.0 callback channel.

---
 utils/gssd/gssd_proc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
utils/gssd/gssd_proc.c +12 -3
index 7387cce010cf..d95e39416c28 100644
@@ -77,6 +77,7 @@
 #include "context.h"
 #include "nfsrpc.h"
 #include "nfslib.h"
+#include "gss_names.h"
 
 /*
  * pollarray:
@@ -683,16 +684,19 @@ parse_enctypes(char *enctypes)
 
 static void
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
+	    gss_buffer_desc *acceptor)
 {
 	char    *buf = NULL, *p = NULL, *end = NULL;
 	unsigned int timeout = context_timeout;
 	unsigned int buf_size = 0;
 
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
+		lifetime_rec, acceptor->length, acceptor->value);
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
-		sizeof(context_token->length) + context_token->length;
+		sizeof(context_token->length) + context_token->length +
+		acceptor->length;
 	p = buf = malloc(buf_size);
 	if (!buf)
 		goto out_err;
@@ -707,6 +711,8 @@ do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
 	if (write_buffer(&p, end, context_token)) goto out_err;
+	if (acceptor->length > 0 &&
+	    write_buffer(&p, end, acceptor)) goto out_err;
 
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
 	free(buf);
@@ -1034,6 +1040,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 	gss_cred_id_t		gss_cred;
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
 	pid_t			pid;
+	gss_name_t		gacceptor;
+	gss_OID			mech;
+	gss_buffer_desc		acceptor  = {0};
 
 	pid = fork();
 	switch(pid) {
@@ -1174,15 +1183,22 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 		goto out_return_error;
 	}
 
Quoted 4 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1178

Quoted 2 lines
utils/gssd/gssd_proc.c +0 -2
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
-	 * is set to zero on error */

Why get rid of this comment instead of updating it?

I suppose I could do that. Would you prefer I respin and update that comment instead?

Quoted 16 lines
Quoted 16 lines
utils/gssd/gssd_proc.c +9 -5
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
 
-	if (maj_stat)
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
-			    "maj_stat %u\n", maj_stat);
+	if (maj_stat != GSS_S_COMPLETE) {
+		printerr(1, "WARNING: Failed to inquire context "
+			    "maj_stat (0x%x)\n", maj_stat);
+	} else {
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
+		gss_release_name(&min_stat, &gacceptor);
+	}
 
Quoted 8 lines

utils/gssd/gssd_proc.c process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname, · line 1200

Quoted 4 lines
utils/gssd/gssd_proc.c +4 -0
+	/*
+	 * The serialization can mean turning the ctx into a lucid context. If
+	 * that happens then the original ctx is no longer valid, so we mustn't
+	 * try to use if after this point.

I'm not sure what you are trying to say here...

steved.

Just a semi-helpful context for posterity...

On my initial attempt, I tried to change the code around to grab the lifetime and acceptor out of the context in do_downcall. That didn't work, because once you call serialize_context_for_kernel, the GSS context is turned into a "lucid context". At that point, things like gss_inquire_context no longer work on it.

Quoted 9 lines
Quoted 2 lines

IOW, once you call serialize_context_for_kernel, you can't count on being able to do anything useful with pd.pd_ctx at all.

This is on purpose, when you export the lucid context, the original context is destroyed, this is to avoid having 2 parties with a context for the same connection as the sequence numbers would get messed up and communication fail if 2 parties tried to use them at the same time anyway.

Quoted 4 lines

Yes, I gathered that it's intentional behavior. You get back an error that basically means that the context handle is no longer valid when you try to use it. It's just not obvious that that's the case at this point in the code, so I figured it warranted a comment.

Yes it is a good thing, or people that are unaware of the export semantic may get confused.

Simo.

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