Skip to contentSkip to conversation

RPCSEC_GSS Version 3 Full MOde MAC Labeling

PATCH New [email protected] 1 participant 13 messages Jul 28, 2017

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

cover RPCSEC_GSS Version 3 Full MOde MAC Labeling

From: Andy Adamson <[email protected]>

Version 6:
- Implemented GSSv3 security for NFSv4.2 Inter Server to Server copy on top of this code. copy_to_auth, copy_from_auth, and copy_confirm_auth payloads should not impose changes to this GSSv3 label code.

Requires on Client:
-------------------
gssd patches: "Version 4 GSSD changes for RPCSEC_GSS version 3"
0001-GSSD-Add-RPCSEC_GSS-version-to-downcall.patch 0002-GSSD-add-option-to-not-put-gss-version-in-downcall.patch

libtirpc patches "Version 4 Libtirpc changes for RPCSEC_GSS version 3"

        0001-Use-RPCSEC_GSS-version-3.patch
        0002-RPCSEC_GSSv3-new-reply-verifier.patch

GSSv3 Implementation Features:
------------------------------
- Negotiate GSS version - starts with GSSv3 then falls back to GSSv1 if
GSSv3 is not supported by gssd or by the NFS server.
- New GSSv3 reply verifier over the RPC header and credential, just like the call verifier caveat the "REPLY" direction. This new reply verifier is stronger than the GSSv1 reply verifier which is only over the GSS sequence number.
- RPCSEC_GSS_CREATE operation generic code is separated from the payload code.
- The first time each client SeLinux thread label is used, an RPCSEC_GSS_CREATE call with a rgss3_label assertion payload is sent, and a GSS3 Child context is associated with the thread label. Each use of the client thread label triggers the use of the associated GSS3 child context handle for the NFS request
- Supports one label assertion payload per RPCSEC_GSS_CREATE
- Kerberos pseudoflavor support (krb5i, krb5p) for RPCSEC_GSS_CREATE calls.
- RPCSEC_GSS_CREATE is only used on krb5i or krb5p parent contexts.
- Client only uses GSSv3 labeling if GSSv3 is in use, selinux is enabled,
and the credential used has the RPC_SEC_GSS_KRB5I or RPC_SEC_GSS_KRB5P
auth flavor.

Issues:
-------
- Perhaps add an administrative configuration on the client (a mount option?) to indicate Full Mode MAC is desired and that NFSv4.2 Labeled NFS (LNFS) is to be used. The current code checks the rpc_auth au_flavor in the GSS layer. This can result in labels being sent only on the RPC_SEC_GSS_KRB5I state management NFS requests (EXCHANGE_ID, CREATE_SESSION, etc) on KRB5, AUTH_SYS, and AUTH_NONE mounts where the non state management NFS requests will not use GSSv3 label contexts. An administrative configuration can clear up this confusion.

- When GSSv3 labeling is configured, should NFS requests fail if a GSSv3 label fails to be created? Should we count on the server failing an NFS request without an associated GSS3 label context handle? The current code ignores an RPCSEC_GSS_CREATE failure.

Functional Description
----------------------
Parent GSS context: the normal GSS context
- "Normal" GSSv3 context is the same as a "normal" GSSv1 context except for the new GSS Version and new reply verifier. For GSSv3 this "normal" context is called the parent context.

Child GSS3 context: Is returned by a successful RPCSEC_GSS_CREATE operation
- Child context is associated with the parent context on both the client and the server.

Client:
If SeLinux is enabled, GSSv3 is in use, and this is a sec=krb5i or sec=krb5p mount option, assume LNFS and GSSv3 full mode MAC security (caveat the first Issue above).

Server:
If SeLinux is enabled, the NFSEXP_SECURITY_LABEL is set on the export, (export option "security_label") and GSSv3 is in use, then both LNFS and GSSv3 labels are in use e.g. full mode MAC security.

When full mode MAC is used:
- Each new GSS3 context (parent) kicks off an RPCSEC_GSS_CREATE with the client thread's SeLinux label as a payload.
- Upon success, the RPCSEC_GSS_CREATE call creates a GSSv3 child context handle that asserts the thread label, and uses the parent context for encrytion services.
- CLIENT: Child context and assertion is stored in an assertion list off the struct gss_cl_ctx.
- SERVER: Child context has it's own rsc cache entry, and the child handle is stored in a list of children handles off the parent rsc entry.
- CLIENT and SERVER: child contexts are destroyed when parent context is destroyed.
- CLIENT: child context associated with the client NFS request thread is used for the NFS request.
- SERVER: Using the child context handle looks up the child rsc entry. Using the parent context handle stored in the child rsc entry looks up the parent rsc entry to use for MIC creation/verification, integrity (krb5i) and/or privacy (krb5p).
- SERVER: the label asserted by the NFS request child handle is imposed upon the NFSD thread servicing the request just like the UID/GIDs in the rpc credential.

Each time a call is made, the client makes a check in gss_match to see if the curren thread's SeLinux label has an associated GSS3 child context handle to use. If not, an RPCSEC_GSS_CREATE call is kicked off to establish the child context prior to the NFS request being sent. The NFS request then uses the child context that asserts the client NFS request thread label when sending the NFS request to the server.

Useful SeLinux commands
------------------------

  - getenforce    will let you know if Selinux is enforced
  - ls -Z         shows label and fetches it via LNFS GETATTR
  - ls -scontext  shows just the label
                                                              105,1  

Andy Adamson (12):
SELINUX export security_current_sid_to_context SUNRPC GSSv3: base definitions
SUNRPC AUTH_GSS get RPCSEC_GSS version from gssd downcall SUNRPC AUTH_GSS gss3 reply verifier
SUNRPC AUTH_GSS RPCSEC_GSS_CREATE with label payload SUNRPC AUTH_GSS store and use gss3 label assertion SUNRPC-AUTH_GSS gss3_free_assertions
SUNRPC SVCAUTH_GSS allow RPCSEC_GSS version 1 or 3 SUNRPC SVCAUTH_GSS gss3 reply verifier
SUNRPC SVCAUTH_GSS gss3 create label
SUNRPC SVCAUTH_GSS set gss3 label on nfsd thread SUNRPC SVCAUTH_gss store gss3 child handles in parent rsc

 fs/nfsd/auth.c                     |  11 +-
 include/linux/selinux.h            |   7 +
 include/linux/sunrpc/auth_gss.h    |  72 ++++-
 include/linux/sunrpc/gss_api.h     |   9 +
 include/linux/sunrpc/svcauth.h     |   1 +
 include/linux/sunrpc/svcauth_gss.h |   1 +
 net/sunrpc/auth_gss/auth_gss.c     | 606 ++++++++++++++++++++++++++++++++++++-
 net/sunrpc/auth_gss/svcauth_gss.c  | 605 ++++++++++++++++++++++++++++++++++--
 security/selinux/hooks.c           |  10 +
 9 files changed, 1281 insertions(+), 41 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/12 SELINUX export security_current_sid_to_context

From: Andy Adamson <[email protected]>

RPCSEC_GSS Version 3 label assertions require the client thread sid in string context form, and so needs this interface or one like it.

---
 include/linux/selinux.h  |  7 +++++++
 security/selinux/hooks.c | 10 ++++++++++
 2 files changed, 17 insertions(+)
include/linux/selinux.h +7 -0
index 44f4596..e82a4ba 100644
@@ -24,12 +24,19 @@
  * selinux_is_enabled - is SELinux enabled?
  */
 bool selinux_is_enabled(void);
+int security_current_sid_to_context(char **scontext, u32 *scontext_len);
 #else
 
 static inline bool selinux_is_enabled(void)
 {
 	return false;
 }
+
+static inline int
+security_current_sid_to_context(char **scontext, u32 *scontext_len)
+{
+	return -EINVAL;
+}
 #endif	/* CONFIG_SECURITY_SELINUX */
 
 #endif /* _LINUX_SELINUX_H */
security/selinux/hooks.c +10 -0
index 819fd68..ba6974b 100644
@@ -6516,3 +6516,13 @@ int selinux_disable(void)
 	return 0;
 }
 #endif
+
+int security_current_sid_to_context(char **scontext, u32 *scontext_len)
+{
+	const struct task_security_struct *ts = current_security();
+
+	if (!selinux_enabled)
+		return -EINVAL;
+	return security_sid_to_context(ts->sid, scontext, scontext_len);
+}
+EXPORT_SYMBOL_GPL(security_current_sid_to_context);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/12 SUNRPC GSSv3: base definitions

In reply to [email protected]

From: Andy Adamson <[email protected]>

---
 include/linux/sunrpc/auth_gss.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/sunrpc/auth_gss.h +5 -1
index 36eebc4..cf5e694 100644
@@ -18,6 +18,7 @@
 #include <linux/sunrpc/gss_api.h>
 
 #define RPC_GSS_VERSION		1
+#define RPC_GSS3_VERSION	3
 
 #define MAXSEQ 0x80000000 /* maximum legal sequence number, from rfc 2203 */
 
@@ -25,7 +26,10 @@ enum rpc_gss_proc {
 	RPC_GSS_PROC_DATA = 0,
 	RPC_GSS_PROC_INIT = 1,
 	RPC_GSS_PROC_CONTINUE_INIT = 2,
-	RPC_GSS_PROC_DESTROY = 3
+	RPC_GSS_PROC_DESTROY = 3,
+	RPC_GSS_PROC_BIND_CHANNEL = 4,	/* GSS2, not used */
+	RPC_GSS_PROC_CREATE = 5,	/* GSS3 */
+	RPC_GSS_PROC_LIST = 6		/* GSS3 */
 };
 
 enum rpc_gss_svc {
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/12 SUNRPC AUTH_GSS get RPCSEC_GSS version from gssd downcall

In reply to [email protected]

From: Andy Adamson <[email protected]>

Due to the addition of RPC_GSS3_VERSION. Assign RPC_GSS_VERSION (version 1) if GSS version is not part of the gssd downcall.

---
 include/linux/sunrpc/auth_gss.h |  1 +
 net/sunrpc/auth_gss/auth_gss.c  | 27 ++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 7 deletions(-)
include/linux/sunrpc/auth_gss.h +1 -0
index cf5e694..dbcdcc2 100644
@@ -70,6 +70,7 @@ struct rpc_gss_init_res {
 
 struct gss_cl_ctx {
 	atomic_t		count;
+	u32			gc_v;
 	enum rpc_gss_proc	gc_proc;
 	u32			gc_seq;
 	spinlock_t		gc_seq_lock;
net/sunrpc/auth_gss/auth_gss.c +20 -7
index 4f16953..3c7fa5d 100644
@@ -209,10 +209,11 @@ struct gss_auth {
 static const void *
 gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct gss_api_mech *gm)
 {
-	const void *q;
+	const void *q, *save;
 	unsigned int seclen;
 	unsigned int timeout;
 	unsigned long now = jiffies;
+	unsigned int gss_v;
 	u32 window_size;
 	int ret;
 
@@ -274,10 +275,22 @@ struct gss_auth {
 	p = simple_get_netobj(q, end, &ctx->gc_acceptor);
 	if (IS_ERR(p))
 		goto err;
+
+	/** Pull in RPCSEC_GSS version if there is one.
+         * Assign RPC_GSS_VERSION (version 1) as the default.
+	 */
+	save = p;
+	p = simple_get_bytes(p, end, &gss_v, sizeof(gss_v));
+	if (IS_ERR(p)) {
+		ctx->gc_v = RPC_GSS_VERSION;
+		p = save;
+	} else {
+		ctx->gc_v = gss_v;
+	}
 done:
-	dprintk("RPC:       %s Success. gc_expiry %lu now %lu timeout %u acceptor %.*s\n",
+	dprintk("RPC:       %s Success. gc_expiry %lu now %lu timeout %u acceptor %.*s gss version %d\n",
 		__func__, ctx->gc_expiry, now, timeout, ctx->gc_acceptor.len,
-		ctx->gc_acceptor.data);
+		ctx->gc_acceptor.data, ctx->gc_v);
 	return p;
 err:
 	dprintk("RPC:       %s returns error %ld\n", __func__, -PTR_ERR(p));
@@ -1511,10 +1524,10 @@ static void gss_pipe_free(struct gss_pipe *p)
 	req->rq_seqno = ctx->gc_seq++;
 	spin_unlock(&ctx->gc_seq_lock);
 
-	*p++ = htonl((u32) RPC_GSS_VERSION);
-	*p++ = htonl((u32) ctx->gc_proc);
-	*p++ = htonl((u32) req->rq_seqno);
-	*p++ = htonl((u32) gss_cred->gc_service);
+	*p++ = htonl((u32)ctx->gc_v);
+	*p++ = htonl((u32)ctx->gc_proc);
+	*p++ = htonl((u32)req->rq_seqno);
+	*p++ = htonl((u32)gss_cred->gc_service);
 	p = xdr_encode_netobj(p, &ctx->gc_wire_ctx);
 	*cred_len = htonl((p - (cred_len + 1)) << 2);
 
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/12 SUNRPC AUTH_GSS gss3 reply verifier

In reply to [email protected]

From: Andy Adamson <[email protected]>

The new GSS Version 3 reply verifier is taken over the same data as the call verifier, caveat REPLY direction

Verifier Data

   xid          tk_rqstp->rq_xid
   direction    REPLY (always a 1) RPC_REPLY
   rpcvers      RPC_VERSION
   prog         clnt->cl_prog
   vers         clnt->cl_vers
   proc         tk_msg.rpc_proc->p_proc
   credential
         flavor       RPC_AUTH_GSS
         length       cred_len is in gss_marshal (new gv_crlen)
         gss version  ctx->gc_v
         gss proc     ctx->gv_proc
         gss seq      tk_rqstp->rq_seqno
         gss svc      gss_cred->gc_service
         gss ctx len  ctx->gc_wire_ctx
         gss ctx data ctx->gc_wire_ctx
---
 net/sunrpc/auth_gss/auth_gss.c | 59 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +57 -2
index 3c7fa5d..28c5491 100644
@@ -1629,6 +1629,53 @@ static int gss_cred_is_negative_entry(struct rpc_cred *cred)
 	return 0;
 }
 
+/**
+ * gss3_reply_verifier: The new gssv3 verifier uses same data as call
+ * caveat REPLY direction - see rpc_encode_header
+ */
+static  void *
+gss3_reply_verifier(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
+		    struct rpc_task *task, __be32 *seq, struct kvec *iov)
+{
+	struct gss_cred *g_cred = container_of(cred, struct gss_cred, gc_base);
+	void	*gss3_buf = NULL;
+	__be32 *crlen, *ptr = NULL;
+	int len;
+
+	/* freed in gss_validate */
+	len = (13 * 4) + ctx->gc_wire_ctx.len;
+	gss3_buf = kmalloc(len, GFP_NOFS);
+	if (!gss3_buf) {
+		gss3_buf = ERR_PTR(-EIO);
+		goto out;
+	}
+	ptr = (__be32 *)gss3_buf;
+
+	*ptr++ = htonl(task->tk_rqstp->rq_xid);
+	*ptr++ = htonl(RPC_REPLY);
+	*ptr++ = htonl(RPC_VERSION);
+	*ptr++ = htonl(task->tk_client->cl_prog);
+	*ptr++ = htonl(task->tk_client->cl_vers);
+	*ptr++ = htonl(task->tk_msg.rpc_proc->p_proc);
+	*ptr++ = htonl(RPC_AUTH_GSS);
+
+	/* credential */
+	crlen = ptr++;
+	*ptr++ = htonl(ctx->gc_v);
+	*ptr++ = htonl(ctx->gc_proc);
+	*ptr++ = *seq;
+	*ptr++ = htonl(g_cred->gc_service);
+	ptr = xdr_encode_netobj(ptr, &ctx->gc_wire_ctx);
+
+	/* backfill cred length */
+	*crlen = htonl((ptr - (crlen + 1)) << 2);
+
+	iov->iov_base = gss3_buf;
+	iov->iov_len = (ptr - (__be32 *)gss3_buf) << 2;
+out:
+	return gss3_buf;
+}
+
 static __be32 *
 gss_validate(struct rpc_task *task, __be32 *p)
 {
@@ -1638,6 +1685,7 @@ static int gss_cred_is_negative_entry(struct rpc_cred *cred)
 	struct kvec	iov;
 	struct xdr_buf	verf_buf;
 	struct xdr_netobj mic;
+	void	*g3_buf = NULL;
 	u32		flav,len;
 	u32		maj_stat;
 	__be32		*ret = ERR_PTR(-EIO);
@@ -1653,14 +1701,21 @@ static int gss_cred_is_negative_entry(struct rpc_cred *cred)
 	if (!seq)
 		goto out_bad;
 	*seq = htonl(task->tk_rqstp->rq_seqno);
-	iov.iov_base = seq;
-	iov.iov_len = 4;
+	if (ctx->gc_v == RPC_GSS_VERSION) {
+		iov.iov_base = seq;
+		iov.iov_len = 4;
+	} else if (ctx->gc_v == RPC_GSS3_VERSION) {
+		g3_buf = gss3_reply_verifier(cred, ctx, task, seq, &iov);
+		if (IS_ERR(g3_buf))
+			goto out_bad;
+	}
 	xdr_buf_from_iov(&iov, &verf_buf);
 	mic.data = (u8 *)p;
 	mic.len = len;
 
 	ret = ERR_PTR(-EACCES);
 	maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &verf_buf, &mic);
+	kfree(g3_buf);
 	if (maj_stat == GSS_S_CONTEXT_EXPIRED)
 		clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
 	if (maj_stat) {
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/12 SUNRPC AUTH_GSS RPCSEC_GSS_CREATE with label payload

In reply to [email protected]

From: Andy Adamson <[email protected]>

Declaration of GSS3 structures.
Determination of Full Mac labeling enabled. GSSv3 in use, SeLinux enabled, and krb5i or krb5p in use.
Creation and xdr encoding an decoding of a gss3_label payload. Generic gss3_proc_create that sends an RPC_GSS_PROC_CREATE operation with any gss3 assertion payload.

Upon success, store the RPC_GSS_PROC_CREATE reply GSS3 assertions in the parent gss_cl_ctx.

---
 include/linux/sunrpc/auth_gss.h |  59 ++++++
 include/linux/sunrpc/gss_api.h  |   7 +
 net/sunrpc/auth_gss/auth_gss.c  | 397 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 463 insertions(+)
include/linux/sunrpc/auth_gss.h +59 -0
index dbcdcc2..16b4f20 100644
@@ -62,6 +62,11 @@ struct rpc_gss_init_res {
 	struct xdr_netobj	gr_token;	/* token */
 };
 
+struct gss3_assert_list {
+	struct list_head	assert_list;
+	spinlock_t		assert_lock;
+};
+
 /* The gss_cl_ctx struct holds all the information the rpcsec_gss client
  * code needs to know about a single security context.  In particular,
  * gc_gss_ctx is the context handle that is used to do gss-api calls, while
@@ -79,6 +84,7 @@ struct gss_cl_ctx {
 	struct xdr_netobj	gc_acceptor;
 	u32			gc_win;
 	unsigned long		gc_expiry;
+	struct gss3_assert_list	gc_alist;
 	struct rcu_head		gc_rcu;
 };
 
@@ -92,6 +98,59 @@ struct gss_cred {
 	unsigned long		gc_upcall_timestamp;
 };
 
+/** GSS3 */
+enum gss3_type {
+	GSS3_LABEL = 0,
+	GSS3_PRIVS = 1,
+};
+
+struct gss3_chan_binding {
+	u32	cb_len;
+	void	*cb_binding;
+};
+
+struct gss3_mp_auth {
+	u32	mp_handle_len;
+	void	*mp_handle;
+	u32	*mp_mic_len;
+	void	*mp_mic;	/* header mic */
+};
+
+struct gss3_label {
+	u32			la_lfs;
+	u32			la_pi;
+	struct xdr_netobj	la_label;
+};
+
+struct gss3_privs {
+	struct xdr_netobj	pr_name;
+	struct xdr_netobj	pr_data;
+};
+
+struct gss3_assertion_u {
+	u32	au_type;
+	union {
+		struct gss3_label	au_label;
+		struct gss3_privs	au_privs;
+	} u;
+};
+
+struct gss3_create_args {
+	struct gss3_mp_auth		*ca_mp_auth;
+	struct gss3_chan_binding	*ca_chan_bind;
+	u32			ca_num;
+	struct gss3_assertion_u	*ca_assertions;
+};
+
+struct gss3_create_res {
+	u32		cr_hlen;
+	void		*cr_handle;
+	struct gss3_mp_auth		*cr_mp_auth;
+	struct gss3_chan_binding	*cr_chan_bind;
+	u32			cr_num;
+	struct gss3_assertion_u	*cr_assertions;
+};
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SUNRPC_AUTH_GSS_H */
 
include/linux/sunrpc/gss_api.h +7 -0
index 68ec78c..7e5da3a 100644
@@ -17,6 +17,13 @@
 #include <linux/sunrpc/msg_prot.h>
 #include <linux/uio.h>
 
+struct gss3_assert {
+	struct list_head	gss3_list;  /* per context list of assertions */
+	struct xdr_netobj	gss3_handle; /* child handle */
+	u32			gss3_num;  /* always one for now */
+	struct gss3_assertion_u	*gss3_assertion;
+};
+
 /* The mechanism-independent gss-api context: */
 struct gss_ctx {
 	struct gss_api_mech	*mech_type;
net/sunrpc/auth_gss/auth_gss.c +397 -0

430 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 6/12 SUNRPC AUTH_GSS store and use gss3 label assertion

In reply to [email protected]

From: Andy Adamson <[email protected]>

After assigning a new gss context to a credential,
call gss3_create_label which will kick off an RPCSED_GSS_CREATE for the thread's label if selinux is enabled.

In gss_match(), check if the current threads SeLinux label (sid) has a matching label assertion. If not, kick off an RPCSEC_GSS_CREATE for the thread's label.

Choose to use a child or parent context handle in gss_marshal and in gss3_reply_verifier.

Add the RPC_GSS_PROC_CREATE case for wrap and unwrap

---
 include/linux/sunrpc/svcauth_gss.h |  1 +
 net/sunrpc/auth_gss/auth_gss.c     | 74 +++++++++++++++++++++++++++++++++++---
 net/sunrpc/auth_gss/svcauth_gss.c  |  2 +-
 3 files changed, 72 insertions(+), 5 deletions(-)
include/linux/sunrpc/svcauth_gss.h +1 -0
index 726aff1..af45bff 100644
@@ -22,6 +22,7 @@
 void gss_svc_shutdown_net(struct net *net);
 int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name);
 u32 svcauth_gss_flavor(struct auth_domain *dom);
+int netobj_equal(struct xdr_netobj *a, struct xdr_netobj *b);
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */
net/sunrpc/auth_gss/auth_gss.c +70 -4

140 lines not on this page · raw message

net/sunrpc/auth_gss/svcauth_gss.c +1 -1
index a54a7a3..aa7cb3b 100644
@@ -63,7 +63,7 @@
  *
  */
 
-static int netobj_equal(struct xdr_netobj *a, struct xdr_netobj *b)
+int netobj_equal(struct xdr_netobj *a, struct xdr_netobj *b)
 {
 	return a->len == b->len && 0 == memcmp(a->data, b->data, a->len);
 }
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 7/12 SUNRPC-AUTH_GSS gss3_free_assertions

In reply to [email protected]

From: Andy Adamson <[email protected]>

Upon GSS context destruction, Free all associated GSS3 child assertions

---
 include/linux/sunrpc/gss_api.h |  1 +
 net/sunrpc/auth_gss/auth_gss.c | 51 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)
include/linux/sunrpc/gss_api.h +1 -0
index 7e5da3a..4e02204 100644
@@ -19,6 +19,7 @@
 
 struct gss3_assert {
 	struct list_head	gss3_list;  /* per context list of assertions */
+	struct rcu_head		gss3_rcu;
 	struct xdr_netobj	gss3_handle; /* child handle */
 	u32			gss3_num;  /* always one for now */
 	struct gss3_assertion_u	*gss3_assertion;
net/sunrpc/auth_gss/auth_gss.c +50 -1

70 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 8/12 SUNRPC SVCAUTH_GSS allow RPCSEC_GSS version 1 or 3

In reply to [email protected]

From: Andy Adamson <[email protected]>

Store the version used in the context INIT phase with the context. Check the incoming rpcsec gss version against the stored context version.

---
 include/linux/sunrpc/gss_api.h    |  1 +
 net/sunrpc/auth_gss/svcauth_gss.c | 20 ++++++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)
include/linux/sunrpc/gss_api.h +1 -0
index 4e02204..d4cff5a 100644
@@ -28,6 +28,7 @@ struct gss3_assert {
 /* The mechanism-independent gss-api context: */
 struct gss_ctx {
 	struct gss_api_mech	*mech_type;
+	u32			 gss_version;
 	void			*internal_ctx_id;
 };
 
net/sunrpc/auth_gss/svcauth_gss.c +14 -6
index aa7cb3b..f7aa8c4 100644
@@ -976,8 +976,8 @@ struct gss_svc_data {
 }
 
 static inline int
-gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp,
-		struct xdr_netobj *out_handle, int *major_status)
+gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, u32 gssv,
+		    struct xdr_netobj *out_handle, int *major_status)
 {
 	struct rsc *rsci;
 	int        rc;
@@ -989,6 +989,8 @@ struct gss_svc_data {
 		*major_status = GSS_S_NO_CONTEXT;
 		return gss_write_null_verf(rqstp);
 	}
+	/* set the RPCSEC_GSS version in the context */
+	rsci->mechctx->gss_version = gssv;
 	rc = gss_write_verf(rqstp, rsci->mechctx, GSS_SEQ_WIN);
 	cache_put(&rsci->h, cd);
 	return rc;
@@ -1130,7 +1132,7 @@ static int svcauth_gss_legacy_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,
+	if (gss_write_init_verf(sn->rsc_cache, rqstp, gc->gc_v,
 				&rsip->out_handle, &rsip->major_status))
 		goto out;
 	if (gss_write_resv(resv, PAGE_SIZE,
@@ -1259,7 +1261,7 @@ static int svcauth_gss_proxy_init(struct svc_rqst *rqstp,
 	}
 
 	/* Got an answer to the upcall; use it: */
-	if (gss_write_init_verf(sn->rsc_cache, rqstp,
+	if (gss_write_init_verf(sn->rsc_cache, rqstp, gc->gc_v,
 				&cli_handle, &ud.major_status))
 		goto out;
 	if (gss_write_resv(resv, PAGE_SIZE,
@@ -1435,14 +1437,15 @@ static void destroy_use_gss_proxy_proc_entry(struct net *net) {}
 	rpcstart -= 7;
 
 	/* credential is:
-	 *   version(==1), proc(0,1,2,3), seq, service (1,2,3), handle
+	 *   version(==1 or 3), proc(0,1,2,3), seq, service (1,2,3), handle
 	 * at least 5 u32s, and is preceded by length, so that makes 6.
 	 */
 
 	if (argv->iov_len < 5 * 4)
 		goto auth_err;
 	crlen = svc_getnl(argv);
-	if (svc_getnl(argv) != RPC_GSS_VERSION)
+	gc->gc_v = svc_getnl(argv);
+	if ((gc->gc_v != RPC_GSS_VERSION) && (gc->gc_v != RPC_GSS3_VERSION))
 		goto auth_err;
 	gc->gc_proc = svc_getnl(argv);
 	gc->gc_seq = svc_getnl(argv);
@@ -1470,6 +1473,11 @@ static void destroy_use_gss_proxy_proc_entry(struct net *net) {}
 		rsci = gss_svc_searchbyctx(sn->rsc_cache, &gc->gc_ctx);
 		if (!rsci)
 			goto auth_err;
+		if (rsci->mechctx->gss_version != gc->gc_v) {
+			pr_warn("NFSD:  RPCSEC_GSS version mismatch (%u:%u)\n",
+				rsci->mechctx->gss_version, gc->gc_v);
+			goto auth_err;
+		}
 		switch (gss_verify_header(rqstp, rsci, rpcstart, gc, authp)) {
 		case SVC_OK:
 			break;
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 9/12 SUNRPC SVCAUTH_GSS gss3 reply verifier

In reply to [email protected]

From: Andy Adamson <[email protected]>

The new GSS Version 3 reply verifier is taken over the same data as the call verifier, caveat REPLY direction

verifier data

rpc_header (6 u32s)
XID (put32) rqstp->rq_xid
type REPLY (putnl) always a 1.
rpcvers u32
prog (getnl) rqstp->rq_prog
vers (getnl) rqstp->rq_vers
proc (getnl) rqstp->rq_proc

credential (7 u32s plus data)
flavor (getnl) (new rq_flav)
length (getnl) (new gc_crlen)
gss version gc_v u32 (svcauth_gss_accept)
gss proceedure u32 gc_proc
gss seq num u32 gc_seq
gss service u32 gc_svc
gss context length u32 gc_ctx->len

gss context gc_ctx->data

size is 13 + gc_ctx->len.

---
 include/linux/sunrpc/auth_gss.h   |  1 +
 net/sunrpc/auth_gss/svcauth_gss.c | 77 ++++++++++++++++++++++++++++++++-------
 2 files changed, 65 insertions(+), 13 deletions(-)
include/linux/sunrpc/auth_gss.h +1 -0
index 16b4f20..c333448 100644
@@ -40,6 +40,7 @@ enum rpc_gss_svc {
 
 /* on-the-wire gss cred: */
 struct rpc_gss_wire_cred {
+	u32			gc_crlen;
 	u32			gc_v;		/* version */
 	u32			gc_proc;	/* control procedure */
 	u32			gc_seq;		/* sequence number */
net/sunrpc/auth_gss/svcauth_gss.c +64 -13

154 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 10/12 SUNRPC SVCAUTH_GSS gss3 create label

In reply to [email protected]

From: Andy Adamson <[email protected]>

GSSv3 uses the same rsc fields as GSSv1 to hold GSS context information. For GSSv3 these 'normal' rsc cache entries are termed parent rsc cache entries.

A successful RPCSEC_GSS_CREATE call results in a child rsc cache entry, which piggy-backs off a parent rsc cache entry, using the parent negotiated crypto for MIC and PRIV calculations.

A child rsc cache entry does not use the cred, seqdata, nor mechctx fields.

New fields for RPCSEC_GSS_CREATE
1) parent_handle: set on a child rsc cache entry to enable the lookup of the parent.
2) assertions: set on a child rsc cache entry to hold the RPCSEC_GSS_CREATE data to assert.

Use a common "act upon the command' switch case for RPC_GSS_PROC_DATA and RPC_GSS_PROC_CREATE to enable wrap and unwrap.

---
 include/linux/sunrpc/auth_gss.h   |   5 +
 net/sunrpc/auth_gss/svcauth_gss.c | 312 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 311 insertions(+), 6 deletions(-)
include/linux/sunrpc/auth_gss.h +5 -0
index c333448..8ac79c7 100644
@@ -136,6 +136,11 @@ struct gss3_assertion_u {
 	} u;
 };
 
+struct gss3_svc_assert {
+	u32			sa_num;
+	struct gss3_assertion_u	sa_assert;
+};
+
 struct gss3_create_args {
 	struct gss3_mp_auth		*ca_mp_auth;
 	struct gss3_chan_binding	*ca_chan_bind;
net/sunrpc/auth_gss/svcauth_gss.c +306 -6

440 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 11/12 SUNRPC SVCAUTH_GSS set gss3 label on nfsd thread

In reply to [email protected]

From: Andy Adamson <[email protected]>

Note: may need to give nfsd selinux authority to change thread label.

---
 fs/nfsd/auth.c                    | 11 ++++++++++-
 include/linux/sunrpc/svcauth.h    |  1 +
 net/sunrpc/auth_gss/svcauth_gss.c | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
fs/nfsd/auth.c +10 -1
index 62469c6..0330fe9 100644
@@ -1,6 +1,7 @@
 /* Copyright (C) 1995, 1996 Olaf Kirch <[email protected]> */
 
 #include <linux/sched.h>
+#include <linux/selinux.h>
 #include "nfsd.h"
 #include "auth.h"
 
@@ -22,7 +23,7 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
 	struct group_info *rqgi;
 	struct group_info *gi;
 	struct cred *new;
-	int i;
+	int i, ret;
 	int flags = nfsexp_flags(rqstp, exp);
 
 	validate_process_creds();
@@ -77,6 +78,14 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
 	else
 		new->cap_effective = cap_raise_nfsd_set(new->cap_effective,
 							new->cap_permitted);
+
+	if (selinux_is_enabled() && rqstp->rq_authop->set_label &&
+	    (exp->ex_flags & NFSEXP_SECURITY_LABEL)) {
+		ret = rqstp->rq_authop->set_label(rqstp, new);
+		if (ret < 0)
+			/* Should nfsd fail this request? */
+			pr_warn("%s set_label FAILED  ret %d\n", __func__, ret);
+	}
 	validate_process_creds();
 	put_cred(override_creds(new));
 	put_cred(new);
include/linux/sunrpc/svcauth.h +1 -0
index d039320..eed6880 100644
@@ -128,6 +128,7 @@ struct auth_ops {
 	int	(*release)(struct svc_rqst *rq);
 	void	(*domain_release)(struct auth_domain *);
 	int	(*set_client)(struct svc_rqst *rq);
+	int	(*set_label)(struct svc_rqst *rq, struct cred *new);
 };
 
 #define	SVC_GARBAGE	1
net/sunrpc/auth_gss/svcauth_gss.c +32 -0
index 1b6e47f..2a48aa0 100644
@@ -1072,6 +1072,37 @@ struct gss_svc_data {
 	return SVC_OK;
 }
 
+/**
+ * the svcdata->rsci_ch pointer is the child context.
+ * assume one GSS3_LABEL per child context.
+ */
+static int
+svcauth_gss_set_label(struct svc_rqst *rqstp, struct cred *new)
+{
+	struct gss_svc_data *svcdata = rqstp->rq_auth_data;
+	struct rsc *rsci_ch = svcdata->rsci_ch;
+	struct gss3_svc_assert *g3a;
+	struct gss3_label *g3l;
+	int ret = -1;
+
+	if (!rsci_ch || !rsci_ch->assertions)
+		goto out;
+
+	g3a = rsci_ch->assertions;
+	if (g3a->sa_num != 1 || g3a->sa_assert.au_type != GSS3_LABEL)
+		goto out;
+
+	g3l = &g3a->sa_assert.u.au_label;
+	if (g3l->la_label.len == 0)
+		goto out;
+
+	/* Assume SeLinux - need to validate la_lfs and la_pi ? */
+	ret = set_security_override_from_ctx(new, (char *)g3l->la_label.data);
+
+out:
+	return ret;
+}
+
 static inline int
 gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp,
 		    struct rpc_gss_wire_cred *gc,
@@ -2126,6 +2157,7 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 	.release	= svcauth_gss_release,
 	.domain_release = svcauth_gss_domain_release,
 	.set_client	= svcauth_gss_set_client,
+	.set_label	= svcauth_gss_set_label,
 };
 
 static int rsi_cache_create_net(struct net *net)
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 12/12 SUNRPC SVCAUTH_gss store gss3 child handles in parent rsc

In reply to [email protected]

From: Andy Adamson <[email protected]>

Keep a parent list of associated child rsc cache entries used upon parent destruction to lookup and reap child rsc cache entries

---
 net/sunrpc/auth_gss/svcauth_gss.c | 182 +++++++++++++++++++++++++++++++++++---
 1 file changed, 172 insertions(+), 10 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +172 -10
index 2a48aa0..1d61345 100644
@@ -348,7 +348,12 @@ struct gss_svc_seq_data {
  *     the parent.
  *     2) assertions: set on a child rsc cache entry to hold the
  *     RPCSEC_GSS_CREATE data to assert.
- *
+ *     3) net:  set on the parent rsc cache entry and is required for the
+ *     lookup associated child rsc cache entries upon parent destruction.
+ *     4) ch_lock: used by the parent; protects the children list
+ *     5) children: used by the parent rsc cache entry to hold a list of
+ *     associated child rsc cache entries and used upon parent destruction
+ *     to lookup child rsc cache entries so as to destroy the children.
  */
 struct rsc {
 	struct cache_head	h;
@@ -358,11 +363,20 @@ struct rsc {
 	struct gss_svc_seq_data	seqdata;
 	struct gss_ctx		*mechctx;
 	struct gss3_svc_assert  *assertions;
+	struct net		*net;
+	spinlock_t		ch_lock; /* for children */
+	struct list_head	children;
+};
+
+struct rsc_child_entry {
+	struct list_head	ce_list;
+	struct xdr_netobj	ce_chandle;
 };
 
 static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old);
 static struct rsc *rsc_lookup(struct cache_detail *cd, struct rsc *item);
 static void gss3_free_svc_assert(struct gss3_svc_assert *g3a);
+static void gss3_free_rsc_children(struct rsc *rsci);
 
 static void rsc_free(struct rsc *rsci)
 {
@@ -373,6 +387,8 @@ static void rsc_free(struct rsc *rsci)
 	free_svc_cred(&rsci->cred);
 	if (rsci->assertions)
 		gss3_free_svc_assert(rsci->assertions);
+	if (!list_empty(&rsci->children))
+		gss3_free_rsc_children(rsci);
 }
 
 static void rsc_put(struct kref *ref)
@@ -399,6 +415,14 @@ static void rsc_put(struct kref *ref)
 }
 
 static void
+init_rsc(struct rsc *rsci)
+{
+	memset(rsci, 0, sizeof(struct rsc));
+	spin_lock_init(&rsci->ch_lock);
+	INIT_LIST_HEAD(&rsci->children);
+}
+
+static void
 rsc_init(struct cache_head *cnew, struct cache_head *ctmp)
 {
 	struct rsc *new = container_of(cnew, struct rsc, h);
@@ -417,6 +441,9 @@ static void rsc_put(struct kref *ref)
 	new->mechctx = NULL;
 	init_svc_cred(&new->cred);
 	new->assertions = NULL;
+	new->net = NULL;
+	spin_lock_init(&new->ch_lock);
+	INIT_LIST_HEAD(&new->children);
 }
 
 static void
@@ -437,6 +464,16 @@ static void rsc_put(struct kref *ref)
 	new->assertions = tmp->assertions;
 	tmp->assertions = NULL;
 	init_svc_cred(&tmp->cred);
+	new->net = tmp->net;
+	tmp->net = NULL;
+	spin_lock_init(&new->ch_lock);
+	INIT_LIST_HEAD(&new->children);
+	spin_lock(&tmp->ch_lock);
+	if (!list_empty(&tmp->children)) {
+		list_move(&tmp->children, &new->children);
+		INIT_LIST_HEAD(&tmp->children);
+	}
+	spin_unlock(&tmp->ch_lock);
 }
 
 static struct cache_head *
@@ -461,7 +498,7 @@ static int rsc_parse(struct cache_detail *cd,
 	int status = -EINVAL;
 	struct gss_api_mech *gm = NULL;
 
-	memset(&rsci, 0, sizeof(rsci));
+	init_rsc(&rsci);
 	/* context handle */
 	len = qword_get(&mesg, buf, mlen);
 	if (len < 0) goto out;
@@ -613,7 +650,7 @@ static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct r
 	struct rsc rsci;
 	struct rsc *found;
 
-	memset(&rsci, 0, sizeof(rsci));
+	init_rsc(&rsci);
 	if (dup_to_netobj(&rsci.handle, handle->data, handle->len))
 		return NULL;
 	found = rsc_lookup(cd, &rsci);
@@ -1285,7 +1322,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
 	time_t expiry;
 	int status = -EINVAL;
 
-	memset(&rsci, 0, sizeof(rsci));
+	init_rsc(&rsci);
 	/* context handle */
 	status = -ENOMEM;
 	/* the handle needs to be just a unique id,
@@ -1544,6 +1581,101 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 	kfree(g3a);
 }
 
+static void
+gss3_free_child(struct rsc_child_entry *cep, struct sunrpc_net *sn)
+{
+	struct rsc *child;
+
+	child = gss_svc_searchbyctx(sn->rsc_cache, &cep->ce_chandle);
+	if (!child) {
+		pr_warn("RPC    %s child in children list not found\n",
+			__func__);
+		goto out_free;
+	}
+	/* balance gss_svc_searchbyctx cache_get */
+	cache_put(&child->h, sn->rsc_cache);
+	/* reap the child */
+	sunrpc_cache_unhash(sn->rsc_cache, &child->h);
+out_free:
+	kfree(cep);
+}
+
+static void gss3_free_rsc_children(struct rsc *parent_rsc)
+{
+	struct rsc_child_entry *cep, *tmp;
+	LIST_HEAD(free);
+	struct sunrpc_net *sn = net_generic(parent_rsc->net, sunrpc_net_id);
+
+	spin_lock(&parent_rsc->ch_lock);
+	list_for_each_entry_safe(cep, tmp, &parent_rsc->children, ce_list) {
+		list_move(&cep->ce_list, &free);
+		/* balance cache_get in gss3_add_child_rsc */
+		cache_put(&parent_rsc->h, sn->rsc_cache);
+	}
+	spin_unlock(&parent_rsc->ch_lock);
+
+	list_for_each_entry_safe(cep, tmp, &free, ce_list) {
+		list_del(&cep->ce_list);
+		gss3_free_child(cep, sn);
+	}
+}
+
+static void
+gss3_free_child_entry(struct rsc *p_rsci, struct xdr_netobj *chandle)
+{
+	struct sunrpc_net *sn = net_generic(p_rsci->net, sunrpc_net_id);
+	struct rsc_child_entry *cep, *tmp;
+
+	spin_lock(&p_rsci->ch_lock);
+	list_for_each_entry_safe(cep, tmp, &p_rsci->children, ce_list) {
+		if (netobj_equal(chandle, &cep->ce_chandle)) {
+			list_del(&cep->ce_list);
+			spin_unlock(&p_rsci->ch_lock);
+			/* balance cache_get in gss3_add_child_rsc */
+			cache_put(&p_rsci->h, sn->rsc_cache);
+			kfree(cep);
+			return;
+		}
+	}
+	spin_unlock(&p_rsci->ch_lock);
+}
+
+/**
+ * After a gss3 child rsc is created, add it's context handle to the
+ * children list of the parent rsc.
+ * Required: gss_svc_searchbyctx has already been called on parent_rsc.
+ */
+static int
+gss3_add_child_rsc(struct cache_detail *cd, struct rsc *parent_rsc,
+		   struct xdr_netobj *chandle)
+{
+	struct rsc_child_entry *cep;
+	int status = -ENOMEM;
+
+	cep = kmalloc(sizeof(*cep), GFP_KERNEL);
+	if (!cep)
+		goto out;
+
+	/* child handle */
+	if (dup_netobj(&cep->ce_chandle, chandle))
+		goto out_free;
+
+	parent_rsc->net = cd->net;
+	INIT_LIST_HEAD(&cep->ce_list);
+	spin_lock(&parent_rsc->ch_lock);
+	list_add(&cep->ce_list, &parent_rsc->children);
+	spin_unlock(&parent_rsc->ch_lock);
+	/* balanced by cache_put in free children routines */
+	cache_get(&parent_rsc->h);
+
+	status = 0;
+out:
+	return status;
+out_free:
+	kfree(cep);
+	goto out;
+}
+
 /**
  * gss3_save_child_rsc()
  * Create a child handle, set the parent handle, assertions, and add to
@@ -1565,8 +1697,7 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 	long dummy;
 	long long ctxh;
 
-	memset(&child, 0, sizeof(child));
-
+	init_rsc(&child);
 	/* context handle */
 	ctxh = atomic64_inc_return(&ctxhctr);
 
@@ -1673,8 +1804,10 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 		       struct sunrpc_net *sn)
 {
 	struct kvec *resv = &rqstp->rq_res.head[0];
+	struct gss_svc_data *svcdata = rqstp->rq_auth_data;
 	struct gss3_svc_assert *g3a;
 	struct gss3_label *glp;
+	struct rsc *p_rsci = svcdata->rsci;
 	u64 c_handle;
 	struct xdr_netobj child_handle;
 	int enc_len, assert_len, ret = 0;
@@ -1689,6 +1822,22 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 	child_handle.data = (u8 *)&c_handle;
 	child_handle.len = sizeof(c_handle);
 
+	ret = gss3_add_child_rsc(sn->rsc_cache, p_rsci, &child_handle);
+	if (ret < 0) {
+		struct rsc *child;
+
+		pr_warn("%s failed to add child rsc to parent\n", __func__);
+		/* delete child */
+		child = gss_svc_searchbyctx(sn->rsc_cache, &child_handle);
+		if (child) {
+			/* balance gss_svc_searchbyctx cache_get */
+			cache_put(&child->h, sn->rsc_cache);
+			 /* reap the child */
+			sunrpc_cache_unhash(sn->rsc_cache, &child->h);
+		}
+		goto auth_err;
+	}
+
 	/* calculate the assert length. Support one assert per request */
 	switch (g3a->sa_assert.au_type) {
 	case GSS3_LABEL:
@@ -1762,8 +1911,7 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 	dprintk("RPC:       svcauth_gss: argv->iov_len = %zd\n",
 			argv->iov_len);
 
-	*authp = rpc_autherr_badcred;
-	if (!svcdata)
+	*authp = rpc_autherr_badcred; if (!svcdata)
 		svcdata = kmalloc(sizeof(*svcdata), GFP_KERNEL);
 	if (!svcdata)
 		goto auth_err;
@@ -1823,6 +1971,7 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 		if (rsci->parent_handle.len != 0) { /* GSSv3 child handle */
 
 			rsci_ch = rsci;
+			/* take reference on child rsc entry */
 			rsci = gss_svc_searchbyctx(sn->rsc_cache,
 						   &rsci_ch->parent_handle);
 			if (!rsci) {
@@ -1854,6 +2003,15 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 	case RPC_GSS_PROC_DESTROY:
 		if (gss_write_verf(rqstp, rsci->mechctx, gc, gc->gc_seq))
 			goto auth_err;
+
+		/* Destroying child, remove from parent list */
+		if (rsci_ch)
+			gss3_free_child_entry(rsci, &rsci_ch->handle);
+
+		/* Destroying parent. Remove all children from list */
+		else if (!list_empty(&rsci->children))
+			gss3_free_rsc_children(rsci);
+
 		/* Delete the entry from the cache_list and call cache_put */
 		sunrpc_cache_unhash(sn->rsc_cache, &rsci->h);
 		if (resv->iov_len + 4 > PAGE_SIZE)
@@ -1934,10 +2092,14 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a)
 drop:
 	ret = SVC_CLOSE;
 out:
+	if (rsci_ch) {
+		if (rsci)
+			cache_put(&rsci_ch->h, sn->rsc_cache);
+		else
+			WARN_ON_ONCE(!rsci);
+	}
 	if (rsci)
 		cache_put(&rsci->h, sn->rsc_cache);
-	if (rsci_ch)
-		cache_put(&rsci_ch->h, sn->rsc_cache);
 	return ret;
 }
 
Signature · 1 line
1.8.3.1