diff options
author | Trond Myklebust <trondmy@gmail.com> | 2019-04-24 17:46:50 -0400 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2019-04-26 17:51:23 -0400 |
commit | b422df915cef80333d7a1732e6ed81f41db12b79 (patch) | |
tree | fefeaf3f1ff40381b9b7cdbd0a20d994920c9c22 | |
parent | 3b7eb5e35d0f55541452e91ca66798c16a81ad4a (diff) |
lockd: Store the lockd client credential in struct nlm_host
When we create a new lockd client, we want to be able to pass the
correct credential of the process that created the struct nlm_host.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
-rw-r--r-- | fs/lockd/clntlock.c | 2 | ||||
-rw-r--r-- | fs/lockd/host.c | 11 | ||||
-rw-r--r-- | include/linux/lockd/bind.h | 1 | ||||
-rw-r--r-- | include/linux/lockd/lockd.h | 4 |
4 files changed, 14 insertions, 4 deletions
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c index c2a128678e6e..70f520b41a19 100644 --- a/fs/lockd/clntlock.c +++ b/fs/lockd/clntlock.c | |||
@@ -63,7 +63,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init) | |||
63 | host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen, | 63 | host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen, |
64 | nlm_init->protocol, nlm_version, | 64 | nlm_init->protocol, nlm_version, |
65 | nlm_init->hostname, nlm_init->noresvport, | 65 | nlm_init->hostname, nlm_init->noresvport, |
66 | nlm_init->net); | 66 | nlm_init->net, nlm_init->cred); |
67 | if (host == NULL) | 67 | if (host == NULL) |
68 | goto out_nohost; | 68 | goto out_nohost; |
69 | if (host->h_rpcclnt == NULL && nlm_bind_host(host) == NULL) | 69 | if (host->h_rpcclnt == NULL && nlm_bind_host(host) == NULL) |
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index d46081123f7c..7d46fafdbbe5 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
@@ -60,6 +60,7 @@ struct nlm_lookup_host_info { | |||
60 | const size_t hostname_len; /* it's length */ | 60 | const size_t hostname_len; /* it's length */ |
61 | const int noresvport; /* use non-priv port */ | 61 | const int noresvport; /* use non-priv port */ |
62 | struct net *net; /* network namespace to bind */ | 62 | struct net *net; /* network namespace to bind */ |
63 | const struct cred *cred; | ||
63 | }; | 64 | }; |
64 | 65 | ||
65 | /* | 66 | /* |
@@ -162,6 +163,7 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni, | |||
162 | host->h_nsmhandle = nsm; | 163 | host->h_nsmhandle = nsm; |
163 | host->h_addrbuf = nsm->sm_addrbuf; | 164 | host->h_addrbuf = nsm->sm_addrbuf; |
164 | host->net = ni->net; | 165 | host->net = ni->net; |
166 | host->h_cred = get_cred(ni->cred), | ||
165 | strlcpy(host->nodename, utsname()->nodename, sizeof(host->nodename)); | 167 | strlcpy(host->nodename, utsname()->nodename, sizeof(host->nodename)); |
166 | 168 | ||
167 | out: | 169 | out: |
@@ -188,6 +190,7 @@ static void nlm_destroy_host_locked(struct nlm_host *host) | |||
188 | clnt = host->h_rpcclnt; | 190 | clnt = host->h_rpcclnt; |
189 | if (clnt != NULL) | 191 | if (clnt != NULL) |
190 | rpc_shutdown_client(clnt); | 192 | rpc_shutdown_client(clnt); |
193 | put_cred(host->h_cred); | ||
191 | kfree(host); | 194 | kfree(host); |
192 | 195 | ||
193 | ln->nrhosts--; | 196 | ln->nrhosts--; |
@@ -202,6 +205,8 @@ static void nlm_destroy_host_locked(struct nlm_host *host) | |||
202 | * @version: NLM protocol version | 205 | * @version: NLM protocol version |
203 | * @hostname: '\0'-terminated hostname of server | 206 | * @hostname: '\0'-terminated hostname of server |
204 | * @noresvport: 1 if non-privileged port should be used | 207 | * @noresvport: 1 if non-privileged port should be used |
208 | * @net: pointer to net namespace | ||
209 | * @cred: pointer to cred | ||
205 | * | 210 | * |
206 | * Returns an nlm_host structure that matches the passed-in | 211 | * Returns an nlm_host structure that matches the passed-in |
207 | * [server address, transport protocol, NLM version, server hostname]. | 212 | * [server address, transport protocol, NLM version, server hostname]. |
@@ -214,7 +219,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, | |||
214 | const u32 version, | 219 | const u32 version, |
215 | const char *hostname, | 220 | const char *hostname, |
216 | int noresvport, | 221 | int noresvport, |
217 | struct net *net) | 222 | struct net *net, |
223 | const struct cred *cred) | ||
218 | { | 224 | { |
219 | struct nlm_lookup_host_info ni = { | 225 | struct nlm_lookup_host_info ni = { |
220 | .server = 0, | 226 | .server = 0, |
@@ -226,6 +232,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, | |||
226 | .hostname_len = strlen(hostname), | 232 | .hostname_len = strlen(hostname), |
227 | .noresvport = noresvport, | 233 | .noresvport = noresvport, |
228 | .net = net, | 234 | .net = net, |
235 | .cred = cred, | ||
229 | }; | 236 | }; |
230 | struct hlist_head *chain; | 237 | struct hlist_head *chain; |
231 | struct nlm_host *host; | 238 | struct nlm_host *host; |
@@ -458,7 +465,7 @@ nlm_bind_host(struct nlm_host *host) | |||
458 | .authflavor = RPC_AUTH_UNIX, | 465 | .authflavor = RPC_AUTH_UNIX, |
459 | .flags = (RPC_CLNT_CREATE_NOPING | | 466 | .flags = (RPC_CLNT_CREATE_NOPING | |
460 | RPC_CLNT_CREATE_AUTOBIND), | 467 | RPC_CLNT_CREATE_AUTOBIND), |
461 | .cred = current_cred(), | 468 | .cred = host->h_cred, |
462 | }; | 469 | }; |
463 | 470 | ||
464 | /* | 471 | /* |
diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h index 053a4ef3d431..8c0cf1059443 100644 --- a/include/linux/lockd/bind.h +++ b/include/linux/lockd/bind.h | |||
@@ -46,6 +46,7 @@ struct nlmclnt_initdata { | |||
46 | int noresvport; | 46 | int noresvport; |
47 | struct net *net; | 47 | struct net *net; |
48 | const struct nlmclnt_operations *nlmclnt_ops; | 48 | const struct nlmclnt_operations *nlmclnt_ops; |
49 | const struct cred *cred; | ||
49 | }; | 50 | }; |
50 | 51 | ||
51 | /* | 52 | /* |
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h index b065ef406770..c9b422dde542 100644 --- a/include/linux/lockd/lockd.h +++ b/include/linux/lockd/lockd.h | |||
@@ -70,6 +70,7 @@ struct nlm_host { | |||
70 | struct nsm_handle *h_nsmhandle; /* NSM status handle */ | 70 | struct nsm_handle *h_nsmhandle; /* NSM status handle */ |
71 | char *h_addrbuf; /* address eyecatcher */ | 71 | char *h_addrbuf; /* address eyecatcher */ |
72 | struct net *net; /* host net */ | 72 | struct net *net; /* host net */ |
73 | const struct cred *h_cred; | ||
73 | char nodename[UNX_MAXNODENAME + 1]; | 74 | char nodename[UNX_MAXNODENAME + 1]; |
74 | const struct nlmclnt_operations *h_nlmclnt_ops; /* Callback ops for NLM users */ | 75 | const struct nlmclnt_operations *h_nlmclnt_ops; /* Callback ops for NLM users */ |
75 | }; | 76 | }; |
@@ -229,7 +230,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, | |||
229 | const u32 version, | 230 | const u32 version, |
230 | const char *hostname, | 231 | const char *hostname, |
231 | int noresvport, | 232 | int noresvport, |
232 | struct net *net); | 233 | struct net *net, |
234 | const struct cred *cred); | ||
233 | void nlmclnt_release_host(struct nlm_host *); | 235 | void nlmclnt_release_host(struct nlm_host *); |
234 | struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, | 236 | struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, |
235 | const char *hostname, | 237 | const char *hostname, |