Skip to content

Commit b422df9

Browse files
trondmyamschuma-ntap
authored andcommitted
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>
1 parent 3b7eb5e commit b422df9

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
6363
host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen,
6464
nlm_init->protocol, nlm_version,
6565
nlm_init->hostname, nlm_init->noresvport,
66-
nlm_init->net);
66+
nlm_init->net, nlm_init->cred);
6767
if (host == NULL)
6868
goto out_nohost;
6969
if (host->h_rpcclnt == NULL && nlm_bind_host(host) == NULL)

‎fs/lockd/host.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct nlm_lookup_host_info {
6060
const size_t hostname_len; /* it's length */
6161
const int noresvport; /* use non-priv port */
6262
struct net *net; /* network namespace to bind */
63+
const struct cred *cred;
6364
};
6465

6566
/*
@@ -162,6 +163,7 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
162163
host->h_nsmhandle = nsm;
163164
host->h_addrbuf = nsm->sm_addrbuf;
164165
host->net = ni->net;
166+
host->h_cred = get_cred(ni->cred),
165167
strlcpy(host->nodename, utsname()->nodename, sizeof(host->nodename));
166168

167169
out:
@@ -188,6 +190,7 @@ static void nlm_destroy_host_locked(struct nlm_host *host)
188190
clnt = host->h_rpcclnt;
189191
if (clnt != NULL)
190192
rpc_shutdown_client(clnt);
193+
put_cred(host->h_cred);
191194
kfree(host);
192195

193196
ln->nrhosts--;
@@ -202,6 +205,8 @@ static void nlm_destroy_host_locked(struct nlm_host *host)
202205
* @version: NLM protocol version
203206
* @hostname: '\0'-terminated hostname of server
204207
* @noresvport: 1 if non-privileged port should be used
208+
* @net: pointer to net namespace
209+
* @cred: pointer to cred
205210
*
206211
* Returns an nlm_host structure that matches the passed-in
207212
* [server address, transport protocol, NLM version, server hostname].
@@ -214,7 +219,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
214219
const u32 version,
215220
const char *hostname,
216221
int noresvport,
217-
struct net *net)
222+
struct net *net,
223+
const struct cred *cred)
218224
{
219225
struct nlm_lookup_host_info ni = {
220226
.server = 0,
@@ -226,6 +232,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
226232
.hostname_len = strlen(hostname),
227233
.noresvport = noresvport,
228234
.net = net,
235+
.cred = cred,
229236
};
230237
struct hlist_head *chain;
231238
struct nlm_host *host;
@@ -458,7 +465,7 @@ nlm_bind_host(struct nlm_host *host)
458465
.authflavor = RPC_AUTH_UNIX,
459466
.flags = (RPC_CLNT_CREATE_NOPING |
460467
RPC_CLNT_CREATE_AUTOBIND),
461-
.cred = current_cred(),
468+
.cred = host->h_cred,
462469
};
463470

464471
/*

‎include/linux/lockd/bind.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct nlmclnt_initdata {
4646
int noresvport;
4747
struct net *net;
4848
const struct nlmclnt_operations *nlmclnt_ops;
49+
const struct cred *cred;
4950
};
5051

5152
/*

‎include/linux/lockd/lockd.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct nlm_host {
7070
struct nsm_handle *h_nsmhandle; /* NSM status handle */
7171
char *h_addrbuf; /* address eyecatcher */
7272
struct net *net; /* host net */
73+
const struct cred *h_cred;
7374
char nodename[UNX_MAXNODENAME + 1];
7475
const struct nlmclnt_operations *h_nlmclnt_ops; /* Callback ops for NLM users */
7576
};
@@ -229,7 +230,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
229230
const u32 version,
230231
const char *hostname,
231232
int noresvport,
232-
struct net *net);
233+
struct net *net,
234+
const struct cred *cred);
233235
void nlmclnt_release_host(struct nlm_host *);
234236
struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
235237
const char *hostname,

0 commit comments

Comments
 (0)