Skip to content

Commit e3f70ea

Browse files
Stanislav KinsburskyJ. Bruce Fields
authored andcommitted
Lockd: pass network namespace to creation and destruction routines
v2: dereference of most probably already released nlm_host removed in nlmclnt_done() and reclaimer(). These routines are called from locks reclaimer() kernel thread. This thread works in "init_net" network context and currently relays on persence on lockd thread and it's per-net resources. Thus lockd_up() and lockd_down() can't relay on current network context. So let's pass corrent one into them. Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent f890edb commit e3f70ea

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
5656
u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4;
5757
int status;
5858

59-
status = lockd_up();
59+
status = lockd_up(nlm_init->net);
6060
if (status < 0)
6161
return ERR_PTR(status);
6262

@@ -65,7 +65,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
6565
nlm_init->hostname, nlm_init->noresvport,
6666
nlm_init->net);
6767
if (host == NULL) {
68-
lockd_down();
68+
lockd_down(nlm_init->net);
6969
return ERR_PTR(-ENOLCK);
7070
}
7171

@@ -80,8 +80,10 @@ EXPORT_SYMBOL_GPL(nlmclnt_init);
8080
*/
8181
void nlmclnt_done(struct nlm_host *host)
8282
{
83+
struct net *net = host->net;
84+
8385
nlmclnt_release_host(host);
84-
lockd_down();
86+
lockd_down(net);
8587
}
8688
EXPORT_SYMBOL_GPL(nlmclnt_done);
8789

@@ -220,11 +222,12 @@ reclaimer(void *ptr)
220222
struct nlm_wait *block;
221223
struct file_lock *fl, *next;
222224
u32 nsmstate;
225+
struct net *net = host->net;
223226

224227
allow_signal(SIGKILL);
225228

226229
down_write(&host->h_rwsem);
227-
lockd_up(); /* note: this cannot fail as lockd is already running */
230+
lockd_up(net); /* note: this cannot fail as lockd is already running */
228231

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

@@ -275,6 +278,6 @@ reclaimer(void *ptr)
275278

276279
/* Release host handle after use */
277280
nlmclnt_release_host(host);
278-
lockd_down();
281+
lockd_down(net);
279282
return 0;
280283
}

‎fs/lockd/svc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,10 @@ static void lockd_down_net(struct net *net)
295295
/*
296296
* Bring up the lockd process if it's not already up.
297297
*/
298-
int lockd_up(void)
298+
int lockd_up(struct net *net)
299299
{
300300
struct svc_serv *serv;
301301
int error = 0;
302-
struct net *net = current->nsproxy->net_ns;
303302

304303
mutex_lock(&nlmsvc_mutex);
305304
/*
@@ -378,12 +377,12 @@ EXPORT_SYMBOL_GPL(lockd_up);
378377
* Decrement the user count and bring down lockd if we're the last.
379378
*/
380379
void
381-
lockd_down(void)
380+
lockd_down(struct net *net)
382381
{
383382
mutex_lock(&nlmsvc_mutex);
384383
if (nlmsvc_users) {
385384
if (--nlmsvc_users) {
386-
lockd_down_net(current->nsproxy->net_ns);
385+
lockd_down_net(net);
387386
goto out;
388387
}
389388
} else {

‎fs/nfsd/nfssvc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int nfsd_startup(unsigned short port, int nrservs)
220220
ret = nfsd_init_socks(port);
221221
if (ret)
222222
goto out_racache;
223-
ret = lockd_up();
223+
ret = lockd_up(&init_net);
224224
if (ret)
225225
goto out_racache;
226226
ret = nfs4_state_start();
@@ -229,7 +229,7 @@ static int nfsd_startup(unsigned short port, int nrservs)
229229
nfsd_up = true;
230230
return 0;
231231
out_lockd:
232-
lockd_down();
232+
lockd_down(&init_net);
233233
out_racache:
234234
nfsd_racache_shutdown();
235235
return ret;
@@ -246,7 +246,7 @@ static void nfsd_shutdown(void)
246246
if (!nfsd_up)
247247
return;
248248
nfs4_state_shutdown();
249-
lockd_down();
249+
lockd_down(&init_net);
250250
nfsd_racache_shutdown();
251251
nfsd_up = false;
252252
}

‎include/linux/lockd/bind.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern void nlmclnt_done(struct nlm_host *host);
5454

5555
extern int nlmclnt_proc(struct nlm_host *host, int cmd,
5656
struct file_lock *fl);
57-
extern int lockd_up(void);
58-
extern void lockd_down(void);
57+
extern int lockd_up(struct net *net);
58+
extern void lockd_down(struct net *net);
5959

6060
#endif /* LINUX_LOCKD_BIND_H */

0 commit comments

Comments
 (0)