summaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2018-12-02 19:30:30 -0500
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2018-12-19 13:52:44 -0500
commit97f68c6b02e0225b38d327103c59cfe2ab5ecda7 (patch)
tree87d434407fef925b2d3fefad5dd759d33b9eb31a /net/sunrpc
parentf06bc03339ad4c1baa964a5f0606247ac1c3c50b (diff)
SUNRPC: add 'struct cred *' to auth_cred and rpc_cred
The SUNRPC credential framework was put together before Linux has 'struct cred'. Now that we have it, it makes sense to use it. This first step just includes a suitable 'struct cred *' pointer in every 'struct auth_cred' and almost every 'struct rpc_cred'. The rpc_cred used for auth_null has a NULL 'struct cred *' as nothing else really makes sense. For rpc_cred, the pointer is reference counted. For auth_cred it isn't. struct auth_cred are either allocated on the stack, in which case the thread owns a reference to the auth, or are part of 'struct generic_cred' in which case gc_base owns the reference, and "acred" shares it. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/auth.c8
-rw-r--r--net/sunrpc/auth_generic.c8
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c2
-rw-r--r--net/sunrpc/auth_unix.c1
4 files changed, 17 insertions, 2 deletions
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index ad8ead738981..a7e08e44f92b 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -659,6 +659,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int flags)
659 acred.uid = cred->fsuid; 659 acred.uid = cred->fsuid;
660 acred.gid = cred->fsgid; 660 acred.gid = cred->fsgid;
661 acred.group_info = cred->group_info; 661 acred.group_info = cred->group_info;
662 acred.cred = cred;
662 ret = auth->au_ops->lookup_cred(auth, &acred, flags); 663 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
663 return ret; 664 return ret;
664} 665}
@@ -674,6 +675,7 @@ rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
674 cred->cr_auth = auth; 675 cred->cr_auth = auth;
675 cred->cr_ops = ops; 676 cred->cr_ops = ops;
676 cred->cr_expire = jiffies; 677 cred->cr_expire = jiffies;
678 cred->cr_cred = get_cred(acred->cred);
677 cred->cr_uid = acred->uid; 679 cred->cr_uid = acred->uid;
678} 680}
679EXPORT_SYMBOL_GPL(rpcauth_init_cred); 681EXPORT_SYMBOL_GPL(rpcauth_init_cred);
@@ -694,11 +696,15 @@ rpcauth_bind_root_cred(struct rpc_task *task, int lookupflags)
694 struct auth_cred acred = { 696 struct auth_cred acred = {
695 .uid = GLOBAL_ROOT_UID, 697 .uid = GLOBAL_ROOT_UID,
696 .gid = GLOBAL_ROOT_GID, 698 .gid = GLOBAL_ROOT_GID,
699 .cred = get_task_cred(&init_task),
697 }; 700 };
701 struct rpc_cred *ret;
698 702
699 dprintk("RPC: %5u looking up %s cred\n", 703 dprintk("RPC: %5u looking up %s cred\n",
700 task->tk_pid, task->tk_client->cl_auth->au_ops->au_name); 704 task->tk_pid, task->tk_client->cl_auth->au_ops->au_name);
701 return auth->au_ops->lookup_cred(auth, &acred, lookupflags); 705 ret = auth->au_ops->lookup_cred(auth, &acred, lookupflags);
706 put_cred(acred.cred);
707 return ret;
702} 708}
703 709
704static struct rpc_cred * 710static struct rpc_cred *
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
index ab4a3be1542a..16a0a4b89bb4 100644
--- a/net/sunrpc/auth_generic.c
+++ b/net/sunrpc/auth_generic.c
@@ -61,11 +61,15 @@ struct rpc_cred *rpc_lookup_machine_cred(const char *service_name)
61 .gid = RPC_MACHINE_CRED_GROUPID, 61 .gid = RPC_MACHINE_CRED_GROUPID,
62 .principal = service_name, 62 .principal = service_name,
63 .machine_cred = 1, 63 .machine_cred = 1,
64 .cred = get_task_cred(&init_task),
64 }; 65 };
66 struct rpc_cred *ret;
65 67
66 dprintk("RPC: looking up machine cred for service %s\n", 68 dprintk("RPC: looking up machine cred for service %s\n",
67 service_name); 69 service_name);
68 return generic_auth.au_ops->lookup_cred(&generic_auth, &acred, 0); 70 ret = generic_auth.au_ops->lookup_cred(&generic_auth, &acred, 0);
71 put_cred(acred.cred);
72 return ret;
69} 73}
70EXPORT_SYMBOL_GPL(rpc_lookup_machine_cred); 74EXPORT_SYMBOL_GPL(rpc_lookup_machine_cred);
71 75
@@ -110,6 +114,7 @@ generic_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags, g
110 gcred->acred.uid = acred->uid; 114 gcred->acred.uid = acred->uid;
111 gcred->acred.gid = acred->gid; 115 gcred->acred.gid = acred->gid;
112 gcred->acred.group_info = acred->group_info; 116 gcred->acred.group_info = acred->group_info;
117 gcred->acred.cred = gcred->gc_base.cr_cred;
113 gcred->acred.ac_flags = 0; 118 gcred->acred.ac_flags = 0;
114 if (gcred->acred.group_info != NULL) 119 if (gcred->acred.group_info != NULL)
115 get_group_info(gcred->acred.group_info); 120 get_group_info(gcred->acred.group_info);
@@ -132,6 +137,7 @@ generic_free_cred(struct rpc_cred *cred)
132 dprintk("RPC: generic_free_cred %p\n", gcred); 137 dprintk("RPC: generic_free_cred %p\n", gcred);
133 if (gcred->acred.group_info != NULL) 138 if (gcred->acred.group_info != NULL)
134 put_group_info(gcred->acred.group_info); 139 put_group_info(gcred->acred.group_info);
140 put_cred(cred->cr_cred);
135 kfree(gcred); 141 kfree(gcred);
136} 142}
137 143
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index ba765473d1f0..56604b259f2c 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1343,6 +1343,7 @@ gss_destroy_nullcred(struct rpc_cred *cred)
1343 struct gss_cl_ctx *ctx = rcu_dereference_protected(gss_cred->gc_ctx, 1); 1343 struct gss_cl_ctx *ctx = rcu_dereference_protected(gss_cred->gc_ctx, 1);
1344 1344
1345 RCU_INIT_POINTER(gss_cred->gc_ctx, NULL); 1345 RCU_INIT_POINTER(gss_cred->gc_ctx, NULL);
1346 put_cred(cred->cr_cred);
1346 call_rcu(&cred->cr_rcu, gss_free_cred_callback); 1347 call_rcu(&cred->cr_rcu, gss_free_cred_callback);
1347 if (ctx) 1348 if (ctx)
1348 gss_put_ctx(ctx); 1349 gss_put_ctx(ctx);
@@ -1608,6 +1609,7 @@ static int gss_renew_cred(struct rpc_task *task)
1608 struct rpc_auth *auth = oldcred->cr_auth; 1609 struct rpc_auth *auth = oldcred->cr_auth;
1609 struct auth_cred acred = { 1610 struct auth_cred acred = {
1610 .uid = oldcred->cr_uid, 1611 .uid = oldcred->cr_uid,
1612 .cred = oldcred->cr_cred,
1611 .principal = gss_cred->gc_principal, 1613 .principal = gss_cred->gc_principal,
1612 .machine_cred = (gss_cred->gc_principal != NULL ? 1 : 0), 1614 .machine_cred = (gss_cred->gc_principal != NULL ? 1 : 0),
1613 }; 1615 };
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index 4c1c7e56288f..36e01384f082 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -97,6 +97,7 @@ static void
97unx_free_cred(struct unx_cred *unx_cred) 97unx_free_cred(struct unx_cred *unx_cred)
98{ 98{
99 dprintk("RPC: unx_free_cred %p\n", unx_cred); 99 dprintk("RPC: unx_free_cred %p\n", unx_cred);
100 put_cred(unx_cred->uc_base.cr_cred);
100 kfree(unx_cred); 101 kfree(unx_cred);
101} 102}
102 103