Skip to content

Commit

Permalink
lockd: Pass the user cred from knfsd when starting the lockd server
Browse files Browse the repository at this point in the history
When starting up a new knfsd server, pass the user cred to the
supporting lockd server.

Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: J. Bruce Fields <[email protected]>
  • Loading branch information
trondmy authored and J. Bruce Fields committed Apr 24, 2019
1 parent 1237d35 commit 40373b1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions fs/lockd/clntlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4;
int status;

status = lockd_up(nlm_init->net);
status = lockd_up(nlm_init->net, nlm_init->cred);
if (status < 0)
return ERR_PTR(status);

Expand Down Expand Up @@ -241,7 +241,7 @@ reclaimer(void *ptr)
allow_signal(SIGKILL);

down_write(&host->h_rwsem);
lockd_up(net); /* note: this cannot fail as lockd is already running */
lockd_up(net, NULL); /* note: this cannot fail as lockd is already running */

dprintk("lockd: reclaiming locks for host %s\n", host->h_name);

Expand Down
28 changes: 16 additions & 12 deletions fs/lockd/svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ lockd(void *vrqstp)

static int create_lockd_listener(struct svc_serv *serv, const char *name,
struct net *net, const int family,
const unsigned short port)
const unsigned short port,
const struct cred *cred)
{
const struct cred *cred = current_cred();
struct svc_xprt *xprt;

xprt = svc_find_xprt(serv, name, net, family, 0);
Expand All @@ -202,15 +202,17 @@ static int create_lockd_listener(struct svc_serv *serv, const char *name,
}

static int create_lockd_family(struct svc_serv *serv, struct net *net,
const int family)
const int family, const struct cred *cred)
{
int err;

err = create_lockd_listener(serv, "udp", net, family, nlm_udpport);
err = create_lockd_listener(serv, "udp", net, family, nlm_udpport,
cred);
if (err < 0)
return err;

return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport);
return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport,
cred);
}

/*
Expand All @@ -223,16 +225,17 @@ static int create_lockd_family(struct svc_serv *serv, struct net *net,
* Returns zero if all listeners are available; otherwise a
* negative errno value is returned.
*/
static int make_socks(struct svc_serv *serv, struct net *net)
static int make_socks(struct svc_serv *serv, struct net *net,
const struct cred *cred)
{
static int warned;
int err;

err = create_lockd_family(serv, net, PF_INET);
err = create_lockd_family(serv, net, PF_INET, cred);
if (err < 0)
goto out_err;

err = create_lockd_family(serv, net, PF_INET6);
err = create_lockd_family(serv, net, PF_INET6, cred);
if (err < 0 && err != -EAFNOSUPPORT)
goto out_err;

Expand All @@ -247,7 +250,8 @@ static int make_socks(struct svc_serv *serv, struct net *net)
return err;
}

static int lockd_up_net(struct svc_serv *serv, struct net *net)
static int lockd_up_net(struct svc_serv *serv, struct net *net,
const struct cred *cred)
{
struct lockd_net *ln = net_generic(net, lockd_net_id);
int error;
Expand All @@ -259,7 +263,7 @@ static int lockd_up_net(struct svc_serv *serv, struct net *net)
if (error)
goto err_bind;

error = make_socks(serv, net);
error = make_socks(serv, net, cred);
if (error < 0)
goto err_bind;
set_grace_period(net);
Expand Down Expand Up @@ -462,7 +466,7 @@ static struct svc_serv *lockd_create_svc(void)
/*
* Bring up the lockd process if it's not already up.
*/
int lockd_up(struct net *net)
int lockd_up(struct net *net, const struct cred *cred)
{
struct svc_serv *serv;
int error;
Expand All @@ -475,7 +479,7 @@ int lockd_up(struct net *net)
goto err_create;
}

error = lockd_up_net(serv, net);
error = lockd_up_net(serv, net, cred);
if (error < 0) {
lockd_unregister_notifiers();
goto err_put;
Expand Down
1 change: 1 addition & 0 deletions fs/nfs/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ static int nfs_start_lockd(struct nfs_server *server)
1 : 0,
.net = clp->cl_net,
.nlmclnt_ops = clp->cl_nfs_mod->rpc_ops->nlmclnt_ops,
.cred = current_cred(),
};

if (nlm_init.nfs_version > 3)
Expand Down
2 changes: 1 addition & 1 deletion fs/nfsd/nfssvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
goto out_socks;

if (nfsd_needs_lockd(nn) && !nn->lockd_up) {
ret = lockd_up(net);
ret = lockd_up(net, cred);
if (ret)
goto out_socks;
nn->lockd_up = 1;
Expand Down
3 changes: 2 additions & 1 deletion include/linux/lockd/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct nlmclnt_initdata {
int noresvport;
struct net *net;
const struct nlmclnt_operations *nlmclnt_ops;
const struct cred *cred;
};

/*
Expand Down Expand Up @@ -75,7 +76,7 @@ struct nlmclnt_operations {
};

extern int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl, void *data);
extern int lockd_up(struct net *net);
extern int lockd_up(struct net *net, const struct cred *cred);
extern void lockd_down(struct net *net);

#endif /* LINUX_LOCKD_BIND_H */

0 comments on commit 40373b1

Please sign in to comment.