Skip to contentSkip to conversation

Add support for new upcall mechanism for nfsd

RFC PATCH In review Simo Sorce 4 participants 11 messages Apr 17, 2012 – Apr 18, 2012 1 message not in the archive

Subsystems (6)
lore
Share & tools
lore
author
#6 lore raw

PATCH 4/5 SUNRPC: Add RPC based upcall mechanism for RPCGSS auth

In reply to Simo Sorce

This patch implements a sunrpc client to use the services of the gssproxy userspace daemon.

In particular it allows to perform calls in user space using an RPC call instead of custom hand-coded upcall/downcall messages.

Currently only accept_sec_context is implemented as that is all is needed for the server case.

File server modules like NFS and CIFS can use full gssapi services this way, once init_sec_context is also implemented.

For the NFS server case this code allow to lift the limit of max 2k krb5 tickets. This limit is prevents legitimate kerberos deployments from using krb5 authentication with the Linux NFS server as they have normally ticket that are many kilobytes large.

It will also allow to lift the limitation on the size of the credential set (uid,gid,gids) passed down from user space for users that have very many groups associated. Currently the downcall mechanism used by rpc.svcgssd is limited to around 2k secondary groups of the 65k allowed by kernel structures.

---
 net/sunrpc/auth_gss/Makefile         |    4 +-
 net/sunrpc/auth_gss/gss_rpc_upcall.c |  341 +++++++++++++
 net/sunrpc/auth_gss/gss_rpc_upcall.h |   43 ++
 net/sunrpc/auth_gss/gss_rpc_xdr.c    |  904 ++++++++++++++++++++++++++++++++++
 net/sunrpc/auth_gss/gss_rpc_xdr.h    |  269 ++++++++++
 5 files changed, 1560 insertions(+), 1 deletions(-)
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_upcall.c
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_upcall.h
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_xdr.c
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_xdr.h
net/sunrpc/auth_gss/Makefile +3 -1
index 9e4cb59ef9f0207bc8edc4629dee18c545599de6..bf9f334529416f496ad32a3d0087964df93ff4ac 100644
@@ -5,9 +5,11 @@
 obj-$(CONFIG_SUNRPC_GSS) += auth_rpcgss.o
 
 auth_rpcgss-y := auth_gss.o gss_generic_token.o \
-	gss_mech_switch.o svcauth_gss.o
+	gss_mech_switch.o svcauth_gss.o \
+	gss_rpc_upcall.o gss_rpc_xdr.o
 
 obj-$(CONFIG_RPCSEC_GSS_KRB5) += rpcsec_gss_krb5.o
 
 rpcsec_gss_krb5-y := gss_krb5_mech.o gss_krb5_seal.o gss_krb5_unseal.o \
 	gss_krb5_seqnum.o gss_krb5_wrap.o gss_krb5_crypto.o gss_krb5_keys.o
+
net/sunrpc/auth_gss/gss_rpc_upcall.c new file +341 -0

341 lines not on this page · raw message

net/sunrpc/auth_gss/gss_rpc_upcall.h new file +43 -0

43 lines not on this page · raw message

net/sunrpc/auth_gss/gss_rpc_xdr.c new file +904 -0

904 lines not on this page · raw message

net/sunrpc/auth_gss/gss_rpc_xdr.h new file +269 -0

269 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#2 lore raw
In reply to Simo Sorce
Quoted 12 lines · Simo Sorce

This patchset implements a new upcall mechanism that uses the sunrpc client to talk to gssproxy[1], a new userspace daemon to handle gssapi operations on behalf of other processes on the system.

The main driver for this new mechanism is to overcome limitations with the current daemon and upcall. The current code cannot handle tickets larger than approximatively 2k and cannot handle large user credentials set to be set in the kernel.

These patches have been tested against the development version of gssproxy tagged as kernel_v0.1 in the master repo[2].

Quoted 6 lines

I have tested walking into mountpoints using tickets artificially pumped up to 64k and the user is properly authorized, after the accept_se_context call is performed through the new upcall mechanism and gssproxy.

The gssproxy has the potential of handling also init_sec_context calls, but at the moment the only targeted system is nfsd.

Sorry, forgot to add the [1] and [2] references before sending, here they are:
[1] https://fedorahosted.org/gss-proxy/
[2] http://git.fedorahosted.org/git/?p=gss-proxy.git

Simo.

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

Simo Sorce

author
#0 lore raw

cover Add support for new upcall mechanism for nfsd

This patchset implements a new upcall mechanism that uses the sunrpc client to talk to gssproxy[1], a new userspace daemon to handle gssapi operations on behalf of other processes on the system.

The main driver for this new mechanism is to overcome limitations with the current daemon and upcall. The current code cannot handle tickets larger than approximatively 2k and cannot handle large user credentials set to be set in the kernel.

These patches have been tested against the development version of gssproxy tagged as kernel_v0.1 in the master repo[2].

I have tested walking into mountpoints using tickets artificially pumped up to 64k and the user is properly authorized, after the accept_se_context call is performed through the new upcall mechanism and gssproxy.

The gssproxy has the potential of handling also init_sec_context calls, but at the moment the only targeted system is nfsd.

Simo.

Simo Sorce (5):
SUNRPC: Document a bit RPCGSS handling in the NFS Server
SUNRPC: conditionally return endtime from import_sec_context
SUNRPC: split upcall function to extract reusable parts
SUNRPC: Add RPC based upcall mechanism for RPCGSS auth
SUNRPC: Use gssproxy upcall for nfsd's RPCGSS authentication.

 Documentation/filesystems/nfs/00-INDEX         |    2 +
 Documentation/filesystems/nfs/knfsd-rpcgss.txt |   65 ++
 include/linux/sunrpc/auth_gss.h                |    3 +
 include/linux/sunrpc/gss_api.h                 |    2 +
 include/linux/sunrpc/svcauth_gss.h             |    2 +-
 net/sunrpc/auth_gss/Makefile                   |    4 +-
 net/sunrpc/auth_gss/auth_gss.c                 |   11 +-
 net/sunrpc/auth_gss/gss_krb5_mech.c            |    3 +
 net/sunrpc/auth_gss/gss_mech_switch.c          |    5 +-
 net/sunrpc/auth_gss/gss_rpc_upcall.c           |  341 +++++++++
 net/sunrpc/auth_gss/gss_rpc_upcall.h           |   43 ++
 net/sunrpc/auth_gss/gss_rpc_xdr.c              |  904 ++++++++++++++++++++++++
 net/sunrpc/auth_gss/gss_rpc_xdr.h              |  269 +++++++
 net/sunrpc/auth_gss/svcauth_gss.c              |  342 ++++++++--
 14 files changed, 1945 insertions(+), 51 deletions(-)
 create mode 100644 Documentation/filesystems/nfs/knfsd-rpcgss.txt
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_upcall.c
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_upcall.h
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_xdr.c
 create mode 100644 net/sunrpc/auth_gss/gss_rpc_xdr.h
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH 1/5 SUNRPC: Document a bit RPCGSS handling in the NFS Server

Includes changes intorduced by GSS-Proxy.

---
 Documentation/filesystems/nfs/00-INDEX         |    2 +
 Documentation/filesystems/nfs/knfsd-rpcgss.txt |   65 ++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/filesystems/nfs/knfsd-rpcgss.txt
Documentation/filesystems/nfs/00-INDEX +2 -0
index 1716874a651e1c574e7ca9719dfb4e3521b0a5e9..66eb6c8c5334518ddbc10115c7b34b4dfb1b3c0e 100644
@@ -20,3 +20,5 @@ rpc-cache.txt
 	- introduction to the caching mechanisms in the sunrpc layer.
 idmapper.txt
 	- information for configuring request-keys to be used by idmapper
+knfsd-rpcgss.txt
+	- Information on GSS authentication support in the NFS Server
Documentation/filesystems/nfs/knfsd-rpcgss.txt new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#3 lore raw

PATCH 2/5 SUNRPC: conditionally return endtime from import_sec_context

In reply to Simo Sorce

We expose this parameter for a future caller.
It will be used to extract the endtime from the gss-proxy upcall mechanism, in order to set the rsc cache expiration time.

---
 include/linux/sunrpc/gss_api.h        |    2 ++
 net/sunrpc/auth_gss/auth_gss.c        |    2 +-
 net/sunrpc/auth_gss/gss_krb5_mech.c   |    3 +++
 net/sunrpc/auth_gss/gss_mech_switch.c |    5 +++--
 net/sunrpc/auth_gss/svcauth_gss.c     |    3 ++-
 5 files changed, 11 insertions(+), 4 deletions(-)
include/linux/sunrpc/gss_api.h +2 -0
index 332da61cf8b71fc73d802b2609210f46641a9ea1..7bd486d50f0861b45c98e695751c2f92f1b3bdfa 100644
@@ -36,6 +36,7 @@ int gss_import_sec_context(
 		size_t			bufsize,
 		struct gss_api_mech	*mech,
 		struct gss_ctx		**ctx_id,
+		time_t			*endtime,
 		gfp_t			gfp_mask);
 u32 gss_get_mic(
 		struct gss_ctx		*ctx_id,
@@ -91,6 +92,7 @@ struct gss_api_ops {
 			const void		*input_token,
 			size_t			bufsize,
 			struct gss_ctx		*ctx_id,
+			time_t			*endtime,
 			gfp_t			gfp_mask);
 	u32 (*gss_get_mic)(
 			struct gss_ctx		*ctx_id,
net/sunrpc/auth_gss/auth_gss.c +1 -1
index d3ad81f8da5b79551c36b17a7d53007406946699..836cbecb1947235d38c62eadf79ae96ad73906e6 100644
@@ -232,7 +232,7 @@ gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct
 		p = ERR_PTR(-EFAULT);
 		goto err;
 	}
-	ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx, GFP_NOFS);
+	ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx, NULL, GFP_NOFS);
 	if (ret < 0) {
 		p = ERR_PTR(ret);
 		goto err;
net/sunrpc/auth_gss/gss_krb5_mech.c +3 -0
index 8eff8c32d1b9b403c2365326c16e44df7c0923e6..329c36b9aa269a414932df86d89650c7a39528fd 100644
@@ -679,6 +679,7 @@ out_err:
 static int
 gss_import_sec_context_kerberos(const void *p, size_t len,
 				struct gss_ctx *ctx_id,
+				time_t *endtime,
 				gfp_t gfp_mask)
 {
 	const void *end = (const void *)((const char *)p + len);
@@ -696,6 +697,8 @@ gss_import_sec_context_kerberos(const void *p, size_t len,
 
 	if (ret == 0)
 		ctx_id->internal_ctx_id = ctx;
+		if (endtime)
+			*endtime = ctx->endtime;
 	else
 		kfree(ctx);
 
net/sunrpc/auth_gss/gss_mech_switch.c +3 -2
index ca8cad8251c7ff1c13c9bff6757e098c4f1cd9b2..b22cc24fac482351876c8f4a6c10d8b203a95045 100644
@@ -312,14 +312,15 @@ int
 gss_import_sec_context(const void *input_token, size_t bufsize,
 		       struct gss_api_mech	*mech,
 		       struct gss_ctx		**ctx_id,
+		       time_t			*endtime,
 		       gfp_t gfp_mask)
 {
 	if (!(*ctx_id = kzalloc(sizeof(**ctx_id), gfp_mask)))
 		return -ENOMEM;
 	(*ctx_id)->mech_type = gss_mech_get(mech);
 
-	return mech->gm_ops
-		->gss_import_sec_context(input_token, bufsize, *ctx_id, gfp_mask);
+	return mech->gm_ops->gss_import_sec_context(input_token, bufsize,
+						*ctx_id, endtime, gfp_mask);
 }
 
 /* gss_get_mic: compute a mic over message and return mic_token. */
net/sunrpc/auth_gss/svcauth_gss.c +2 -1
index 1600cfb1618cd2abb4ae14be87f96554100a862a..274df6410057fa23e991545d80fdb90ab37e0b6f 100644
@@ -489,7 +489,8 @@ static int rsc_parse(struct cache_detail *cd,
 		len = qword_get(&mesg, buf, mlen);
 		if (len < 0)
 			goto out;
-		status = gss_import_sec_context(buf, len, gm, &rsci.mechctx, GFP_KERNEL);
+		status = gss_import_sec_context(buf, len, gm, &rsci.mechctx,
+						NULL, GFP_KERNEL);
 		if (status)
 			goto out;
 
Signature · 1 line
1.7.7.6
author
#4 lore raw

PATCH 3/5 SUNRPC: split upcall function to extract reusable parts

In reply to Simo Sorce

This is needed to share code between the current server upcall mechanism and the new gssproxy upcall mechanism introduced in a following patch.

---
 net/sunrpc/auth_gss/svcauth_gss.c |  110 +++++++++++++++++++++++--------------
 1 files changed, 69 insertions(+), 41 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +69 -41
index 274df6410057fa23e991545d80fdb90ab37e0b6f..aa1b649749741c82e60f0f528ac645197fd7ab35 100644
@@ -965,16 +965,17 @@ svcauth_gss_set_client(struct svc_rqst *rqstp)
 }
 
 static inline int
-gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rsi *rsip)
+gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp,
+		struct xdr_netobj *out_handle, int *major_status)
 {
 	struct rsc *rsci;
 	int        rc;
 
-	if (rsip->major_status != GSS_S_COMPLETE)
+	if (*major_status != GSS_S_COMPLETE)
 		return gss_write_null_verf(rqstp);
-	rsci = gss_svc_searchbyctx(cd, &rsip->out_handle);
+	rsci = gss_svc_searchbyctx(cd, out_handle);
 	if (rsci == NULL) {
-		rsip->major_status = GSS_S_NO_CONTEXT;
+		*major_status = GSS_S_NO_CONTEXT;
 		return gss_write_null_verf(rqstp);
 	}
 	rc = gss_write_verf(rqstp, rsci->mechctx, GSS_SEQ_WIN);
@@ -982,6 +983,61 @@ gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rsi
 	return rc;
 }
 
+static inline int
+gss_read_verf(struct rpc_gss_wire_cred *gc,
+	      struct kvec *argv, __be32 *authp,
+	      struct xdr_netobj *in_handle,
+	      struct xdr_netobj *in_token)
+{
+	struct xdr_netobj tmpobj;
+
+	/* Read the verifier; should be NULL: */
+	*authp = rpc_autherr_badverf;
+	if (argv->iov_len < 2 * 4)
+		return SVC_DENIED;
+	if (svc_getnl(argv) != RPC_AUTH_NULL)
+		return SVC_DENIED;
+	if (svc_getnl(argv) != 0)
+		return SVC_DENIED;
+	/* Martial context handle and token for upcall: */
+	*authp = rpc_autherr_badcred;
+	if (gc->gc_proc == RPC_GSS_PROC_INIT && gc->gc_ctx.len != 0)
+		return SVC_DENIED;
+	if (dup_netobj(in_handle, &gc->gc_ctx))
+		return SVC_CLOSE;
+	*authp = rpc_autherr_badverf;
+	if (svc_safe_getnetobj(argv, &tmpobj)) {
+		kfree(in_handle->data);
+		return SVC_DENIED;
+	}
+	if (dup_netobj(in_token, &tmpobj)) {
+		kfree(in_handle->data);
+		return SVC_CLOSE;
+	}
+
+	return 0;
+}
+
+static inline int
+gss_write_resv(struct kvec *resv, size_t size_limit,
+	       struct xdr_netobj *out_handle, struct xdr_netobj *out_token,
+	       int major_status, int minor_status)
+{
+	if (resv->iov_len + 4 > size_limit)
+		return -1;
+	svc_putnl(resv, RPC_SUCCESS);
+	if (svc_safe_putnetobj(resv, out_handle))
+		return -1;
+	if (resv->iov_len + 3 * 4 > size_limit)
+		return -1;
+	svc_putnl(resv, major_status);
+	svc_putnl(resv, minor_status);
+	svc_putnl(resv, GSS_SEQ_WIN);
+	if (svc_safe_putnetobj(resv, out_token))
+		return -1;
+	return 0;
+}
+
 /*
  * Having read the cred already and found we're in the context
  * initiation case, read the verifier and initiate (or check the results
@@ -994,36 +1050,15 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
 {
 	struct kvec *argv = &rqstp->rq_arg.head[0];
 	struct kvec *resv = &rqstp->rq_res.head[0];
-	struct xdr_netobj tmpobj;
 	struct rsi *rsip, rsikey;
 	int ret;
 	struct sunrpc_net *sn = net_generic(rqstp->rq_xprt->xpt_net, sunrpc_net_id);
 
-	/* Read the verifier; should be NULL: */
-	*authp = rpc_autherr_badverf;
-	if (argv->iov_len < 2 * 4)
-		return SVC_DENIED;
-	if (svc_getnl(argv) != RPC_AUTH_NULL)
-		return SVC_DENIED;
-	if (svc_getnl(argv) != 0)
-		return SVC_DENIED;
-
-	/* Martial context handle and token for upcall: */
-	*authp = rpc_autherr_badcred;
-	if (gc->gc_proc == RPC_GSS_PROC_INIT && gc->gc_ctx.len != 0)
-		return SVC_DENIED;
 	memset(&rsikey, 0, sizeof(rsikey));
-	if (dup_netobj(&rsikey.in_handle, &gc->gc_ctx))
-		return SVC_CLOSE;
-	*authp = rpc_autherr_badverf;
-	if (svc_safe_getnetobj(argv, &tmpobj)) {
-		kfree(rsikey.in_handle.data);
-		return SVC_DENIED;
-	}
-	if (dup_netobj(&rsikey.in_token, &tmpobj)) {
-		kfree(rsikey.in_handle.data);
-		return SVC_CLOSE;
-	}
+	ret = gss_read_verf(gc, argv, authp,
+			    &rsikey.in_handle, &rsikey.in_token);
+	if (ret)
+		return ret;
 
 	/* Perform upcall, or find upcall result: */
 	rsip = rsi_lookup(sn->rsi_cache, &rsikey);
@@ -1036,19 +1071,12 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
 
 	ret = SVC_CLOSE;
 	/* Got an answer to the upcall; use it: */
-	if (gss_write_init_verf(sn->rsc_cache, rqstp, rsip))
+	if (gss_write_init_verf(sn->rsc_cache, rqstp,
+				&rsip->out_handle, &rsip->major_status))
 		goto out;
-	if (resv->iov_len + 4 > PAGE_SIZE)
-		goto out;
-	svc_putnl(resv, RPC_SUCCESS);
-	if (svc_safe_putnetobj(resv, &rsip->out_handle))
-		goto out;
-	if (resv->iov_len + 3 * 4 > PAGE_SIZE)
-		goto out;
-	svc_putnl(resv, rsip->major_status);
-	svc_putnl(resv, rsip->minor_status);
-	svc_putnl(resv, GSS_SEQ_WIN);
-	if (svc_safe_putnetobj(resv, &rsip->out_token))
+	if (gss_write_resv(resv, PAGE_SIZE,
+			   &rsip->out_handle, &rsip->out_token,
+			   rsip->major_status, rsip->minor_status))
 		goto out;
 
 	ret = SVC_COMPLETE;
Signature · 1 line
1.7.7.6
author
#11 lore raw

PATCH 5/5 SUNRPC: Use gssproxy upcall for nfsd's RPCGSS authentication.

In reply to Simo Sorce

The main advantge of this new upcall mechanism is that it can handle big tickets as seen in Kerberos implementations where tickets carry authorization data like the MS-PAC buffer with AD or the Posix Authorization Data being discussed in IETF on the krbwg working group.

The Gssproxy program is used to perform the accept_sec_context call on the kernel's behalf. The code is changed to also pass the input buffer straight to upcall mechanism to avoid allocating and copying many pages as tokens can be as big (potentially more in future) as 64KiB.

---
 include/linux/sunrpc/auth_gss.h    |    3 +
 include/linux/sunrpc/svcauth_gss.h |    2 +-
 net/sunrpc/auth_gss/auth_gss.c     |    9 +-
 net/sunrpc/auth_gss/svcauth_gss.c  |  249 ++++++++++++++++++++++++++++++++++--
 4 files changed, 248 insertions(+), 15 deletions(-)
include/linux/sunrpc/auth_gss.h +3 -0
index f1cfd4c85cd047c4b2fadd367eeb819aabc57d29..eb2670f6cf9113f1b4c161b9deda05ee4757fa85 100644
@@ -19,6 +19,9 @@
 
 #define RPC_GSS_VERSION		1
 
+#define GSS_UPCALL_LEGACY	0
+#define GSS_UPCALL_GSSPROXY	1
+
 #define MAXSEQ 0x80000000 /* maximum legal sequence number, from rfc 2203 */
 
 enum rpc_gss_proc {
include/linux/sunrpc/svcauth_gss.h +1 -1
index 7c32daa025eb07b644d8185a27c8ea10d8b7c55f..678c6fc8f1593bc53bc3d875175ed7098cd4db40 100644
@@ -16,7 +16,7 @@
 #include <linux/sunrpc/svcsock.h>
 #include <linux/sunrpc/auth_gss.h>
 
-int gss_svc_init(void);
+int gss_svc_init(unsigned int upcall_type);
 void gss_svc_shutdown(void);
 int gss_svc_init_net(struct net *net);
 void gss_svc_shutdown_net(struct net *net);
net/sunrpc/auth_gss/auth_gss.c +8 -1
index 836cbecb1947235d38c62eadf79ae96ad73906e6..97fe72609387cb8b948bc3aa4d14db4956138d3c 100644
@@ -60,6 +60,8 @@ static const struct rpc_credops gss_nullops;
 #define GSS_RETRY_EXPIRED 5
 static unsigned int gss_expired_cred_retry_delay = GSS_RETRY_EXPIRED;
 
+static unsigned int gss_upcall_daemon_type = GSS_UPCALL_LEGACY;
+
 #ifdef RPC_DEBUG
 # define RPCDBG_FACILITY	RPCDBG_AUTH
 #endif
@@ -1687,7 +1689,7 @@ static int __init init_rpcsec_gss(void)
 	err = rpcauth_register(&authgss_ops);
 	if (err)
 		goto out;
-	err = gss_svc_init();
+	err = gss_svc_init(gss_upcall_daemon_type);
 	if (err)
 		goto out_unregister;
 	err = register_pernet_subsys(&rpcsec_gss_net_ops);
@@ -1717,6 +1719,11 @@ module_param_named(expired_cred_retry_delay,
 		   uint, 0644);
 MODULE_PARM_DESC(expired_cred_retry_delay, "Timeout (in seconds) until "
 		"the RPC engine retries an expired credential");
+module_param_named(upcall_daemon_type,
+		   gss_upcall_daemon_type,
+		   uint, 0644);
+MODULE_PARM_DESC(upcall_daemon_type, "Type of svcgss upcall daemon used "
+		"(legacy=0 or gssproxy=1)");
 
 module_init(init_rpcsec_gss)
 module_exit(exit_rpcsec_gss)
net/sunrpc/auth_gss/svcauth_gss.c +236 -13

321 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#5 lore raw

Re: [PATCH 3/5] SUNRPC: split upcall function to extract reusable parts

In reply to Simo Sorce
Quoted 2 lines · Simo Sorce

This is needed to share code between the current server upcall mechanism and the new gssproxy upcall mechanism introduced in a following patch.

I'll go ahead and take this now, as it seems like reasonable cleanup independent of the rest.

--b.

Quoted 163 lines
---
 net/sunrpc/auth_gss/svcauth_gss.c |  110 +++++++++++++++++++++++--------------
 1 files changed, 69 insertions(+), 41 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +69 -41
index 274df6410057fa23e991545d80fdb90ab37e0b6f..aa1b649749741c82e60f0f528ac645197fd7ab35 100644
@@ -965,16 +965,17 @@ svcauth_gss_set_client(struct svc_rqst *rqstp)
 }
 
 static inline int
-gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rsi *rsip)
+gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp,
+		struct xdr_netobj *out_handle, int *major_status)
 {
 	struct rsc *rsci;
 	int        rc;
 
-	if (rsip->major_status != GSS_S_COMPLETE)
+	if (*major_status != GSS_S_COMPLETE)
 		return gss_write_null_verf(rqstp);
-	rsci = gss_svc_searchbyctx(cd, &rsip->out_handle);
+	rsci = gss_svc_searchbyctx(cd, out_handle);
 	if (rsci == NULL) {
-		rsip->major_status = GSS_S_NO_CONTEXT;
+		*major_status = GSS_S_NO_CONTEXT;
 		return gss_write_null_verf(rqstp);
 	}
 	rc = gss_write_verf(rqstp, rsci->mechctx, GSS_SEQ_WIN);
@@ -982,6 +983,61 @@ gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rsi
 	return rc;
 }
 
+static inline int
+gss_read_verf(struct rpc_gss_wire_cred *gc,
+	      struct kvec *argv, __be32 *authp,
+	      struct xdr_netobj *in_handle,
+	      struct xdr_netobj *in_token)
+{
+	struct xdr_netobj tmpobj;
+
+	/* Read the verifier; should be NULL: */
+	*authp = rpc_autherr_badverf;
+	if (argv->iov_len < 2 * 4)
+		return SVC_DENIED;
+	if (svc_getnl(argv) != RPC_AUTH_NULL)
+		return SVC_DENIED;
+	if (svc_getnl(argv) != 0)
+		return SVC_DENIED;
+	/* Martial context handle and token for upcall: */
+	*authp = rpc_autherr_badcred;
+	if (gc->gc_proc == RPC_GSS_PROC_INIT && gc->gc_ctx.len != 0)
+		return SVC_DENIED;
+	if (dup_netobj(in_handle, &gc->gc_ctx))
+		return SVC_CLOSE;
+	*authp = rpc_autherr_badverf;
+	if (svc_safe_getnetobj(argv, &tmpobj)) {
+		kfree(in_handle->data);
+		return SVC_DENIED;
+	}
+	if (dup_netobj(in_token, &tmpobj)) {
+		kfree(in_handle->data);
+		return SVC_CLOSE;
+	}
+
+	return 0;
+}
+
+static inline int
+gss_write_resv(struct kvec *resv, size_t size_limit,
+	       struct xdr_netobj *out_handle, struct xdr_netobj *out_token,
+	       int major_status, int minor_status)
+{
+	if (resv->iov_len + 4 > size_limit)
+		return -1;
+	svc_putnl(resv, RPC_SUCCESS);
+	if (svc_safe_putnetobj(resv, out_handle))
+		return -1;
+	if (resv->iov_len + 3 * 4 > size_limit)
+		return -1;
+	svc_putnl(resv, major_status);
+	svc_putnl(resv, minor_status);
+	svc_putnl(resv, GSS_SEQ_WIN);
+	if (svc_safe_putnetobj(resv, out_token))
+		return -1;
+	return 0;
+}
+
 /*
  * Having read the cred already and found we're in the context
  * initiation case, read the verifier and initiate (or check the results
@@ -994,36 +1050,15 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
 {
 	struct kvec *argv = &rqstp->rq_arg.head[0];
 	struct kvec *resv = &rqstp->rq_res.head[0];
-	struct xdr_netobj tmpobj;
 	struct rsi *rsip, rsikey;
 	int ret;
 	struct sunrpc_net *sn = net_generic(rqstp->rq_xprt->xpt_net, sunrpc_net_id);
 
-	/* Read the verifier; should be NULL: */
-	*authp = rpc_autherr_badverf;
-	if (argv->iov_len < 2 * 4)
-		return SVC_DENIED;
-	if (svc_getnl(argv) != RPC_AUTH_NULL)
-		return SVC_DENIED;
-	if (svc_getnl(argv) != 0)
-		return SVC_DENIED;
-
-	/* Martial context handle and token for upcall: */
-	*authp = rpc_autherr_badcred;
-	if (gc->gc_proc == RPC_GSS_PROC_INIT && gc->gc_ctx.len != 0)
-		return SVC_DENIED;
 	memset(&rsikey, 0, sizeof(rsikey));
-	if (dup_netobj(&rsikey.in_handle, &gc->gc_ctx))
-		return SVC_CLOSE;
-	*authp = rpc_autherr_badverf;
-	if (svc_safe_getnetobj(argv, &tmpobj)) {
-		kfree(rsikey.in_handle.data);
-		return SVC_DENIED;
-	}
-	if (dup_netobj(&rsikey.in_token, &tmpobj)) {
-		kfree(rsikey.in_handle.data);
-		return SVC_CLOSE;
-	}
+	ret = gss_read_verf(gc, argv, authp,
+			    &rsikey.in_handle, &rsikey.in_token);
+	if (ret)
+		return ret;
 
 	/* Perform upcall, or find upcall result: */
 	rsip = rsi_lookup(sn->rsi_cache, &rsikey);
@@ -1036,19 +1071,12 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
 
 	ret = SVC_CLOSE;
 	/* Got an answer to the upcall; use it: */
-	if (gss_write_init_verf(sn->rsc_cache, rqstp, rsip))
+	if (gss_write_init_verf(sn->rsc_cache, rqstp,
+				&rsip->out_handle, &rsip->major_status))
 		goto out;
-	if (resv->iov_len + 4 > PAGE_SIZE)
-		goto out;
-	svc_putnl(resv, RPC_SUCCESS);
-	if (svc_safe_putnetobj(resv, &rsip->out_handle))
-		goto out;
-	if (resv->iov_len + 3 * 4 > PAGE_SIZE)
-		goto out;
-	svc_putnl(resv, rsip->major_status);
-	svc_putnl(resv, rsip->minor_status);
-	svc_putnl(resv, GSS_SEQ_WIN);
-	if (svc_safe_putnetobj(resv, &rsip->out_token))
+	if (gss_write_resv(resv, PAGE_SIZE,
+			   &rsip->out_handle, &rsip->out_token,
+			   rsip->major_status, rsip->minor_status))
 		goto out;
 
 	ret = SVC_COMPLETE;
Signature · 1 line
1.7.7.6
#7 lore raw

Re: [PATCH 4/5] SUNRPC: Add RPC based upcall mechanism for RPCGSS auth

In reply to Simo Sorce
Quoted 5 lines · Simo Sorce

This patch implements a sunrpc client to use the services of the gssproxy userspace daemon.

In particular it allows to perform calls in user space using an RPC call instead of custom hand-coded upcall/downcall messages.

The "hand-coded" messages aren't really particularly hard to generate or parse. Let's just drop that argument.

Quoted 5 lines

Currently only accept_sec_context is implemented as that is all is needed for the server case.

File server modules like NFS and CIFS can use full gssapi services this way, once init_sec_context is also implemented.

What's the situation with CIFS, by the way? (How does it currently do gssapi, and what are their plans?)

Quoted 9 lines

For the NFS server case this code allow to lift the limit of max 2k krb5 tickets. This limit is prevents legitimate kerberos deployments from using krb5 authentication with the Linux NFS server as they have normally ticket that are many kilobytes large.

It will also allow to lift the limitation on the size of the credential set (uid,gid,gids) passed down from user space for users that have very many groups associated. Currently the downcall mechanism used by rpc.svcgssd is limited to around 2k secondary groups of the 65k allowed by kernel structures.

Remind me what remains to be done before that works?

--b.

author
#8 lore raw

Re: [PATCH 4/5] SUNRPC: Add RPC based upcall mechanism for RPCGSS auth

Quoted 9 lines · J. Bruce Fields
Quoted 5 lines · Simo Sorce

This patch implements a sunrpc client to use the services of the gssproxy userspace daemon.

In particular it allows to perform calls in user space using an RPC call instead of custom hand-coded upcall/downcall messages.

The "hand-coded" messages aren't really particularly hard to generate or parse. Let's just drop that argument.

Sorry wasn't meant as an argument, just a fact.
I guess hand-coded is the wrong term, after all all the RPC code in the kernel is hand-coded as well :-)
(userspace uses rpcgen)

I will drop the line in future if it feels contentious.

Quoted 8 lines
Quoted 5 lines

Currently only accept_sec_context is implemented as that is all is needed for the server case.

File server modules like NFS and CIFS can use full gssapi services this way, once init_sec_context is also implemented.

What's the situation with CIFS, by the way? (How does it currently do gssapi, and what are their plans?)

At the moment I think the cifs.ko code uses an upcall mechanism based on storing blobs in the kernel keyring to have it call a userspace helper. Last time I spoke with Jeff Layton he expressed interest in a unified mechanism like gss-proxy to reduce duplication in the system. I haven't discussed it further.

Quoted 11 lines
Quoted 9 lines

For the NFS server case this code allow to lift the limit of max 2k krb5 tickets. This limit is prevents legitimate kerberos deployments from using krb5 authentication with the Linux NFS server as they have normally ticket that are many kilobytes large.

It will also allow to lift the limitation on the size of the credential set (uid,gid,gids) passed down from user space for users that have very many groups associated. Currently the downcall mechanism used by rpc.svcgssd is limited to around 2k secondary groups of the 65k allowed by kernel structures.

Remind me what remains to be done before that works?

The sunrpc code that deals with AF_LOCAL needs to be fixed to use a stream (tcp like) reader function instead of using the datagram (udp) code, after all it *is* declared as a 'stream' facility, not a datagram one.
It shouldn't really be a lot of work as it should do basically the same thing the tcp code does. I am no expert there but I wonder if the available tcp-named functions couldn't just be reused as is with perhaps some minor tweaks to distinguish between AF_INET and AF_LOCAL if necessary anywhere in that path.
Haven't yet looked deeply enough to be able to tell, I am quite new to this code and would not mind an experienced hand to give some advice.

Simo.

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

Re: [PATCH 4/5] SUNRPC: Add RPC based upcall mechanism for RPCGSS auth

In reply to a message not in the archive
Quoted 10 lines · On Tue, 17 Apr 2012 18:28:25 -0400 "J. Bruce Fields"…
Quoted 5 lines · Simo Sorce

This patch implements a sunrpc client to use the services of the gssproxy userspace daemon.

In particular it allows to perform calls in user space using an RPC call instead of custom hand-coded upcall/downcall messages.

The "hand-coded" messages aren't really particularly hard to generate or parse. Let's just drop that argument.

Quoted 9 lines
Quoted 5 lines

Currently only accept_sec_context is implemented as that is all is needed for the server case.

File server modules like NFS and CIFS can use full gssapi services this way, once init_sec_context is also implemented.

What's the situation with CIFS, by the way? (How does it currently do gssapi, and what are their plans?)

Currently it has its own upcall that's done using the keys API. It's pretty limited. It's stateless and so doesn't handle multistage negotiation properly, for instance but it works well enough for our purposes...

If there's common infrastructure in the kernel for handling GSSAPI then we'd be interested in using that instead. I'm all for less code that we have to maintain ourselves...

We would of course need to come up with a transition scheme to the new daemon. We might need some small modifications too since CIFS expects the blob to be wrapped in SPNEGO as well, but that's fairly easy to manage and we could do that in kernel space if needed.

My only (minor) reservation is that moving to this would mean cifs would be dependent to some degree on the sunrpc code. It's not a huge problem. Most distros won't care, but some embedded ones might.

What we'll probably do is wait until this is more settled with nfs(d) and then look at moving to it.

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