Skip to content

Commit 0b88bfa

Browse files
ea1davischucklever
authored andcommitted
NFSD: net ref data still needs to be freed even if net hasn't startup
When the NFSD instance doesn't to startup, the net ref data memory is not properly reclaimed, which triggers the memory leak issue reported by syzbot [1]. To avoid the problem reported in [1], the net ref data memory reclamation action is moved outside of nfsd_net_up when the net is shutdown. [1] unreferenced object 0xffff88812a39dfc0 (size 64): backtrace (crc a2262fc6): percpu_ref_init+0x94/0x1e0 lib/percpu-refcount.c:76 nfsd_create_serv+0xbe/0x260 fs/nfsd/nfssvc.c:605 nfsd_nl_listener_set_doit+0x62/0xb00 fs/nfsd/nfsctl.c:1882 genl_family_rcv_msg_doit+0x11e/0x190 net/netlink/genetlink.c:1115 genl_family_rcv_msg net/netlink/genetlink.c:1195 [inline] genl_rcv_msg+0x2fd/0x440 net/netlink/genetlink.c:1210 BUG: memory leak Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226 Fixes: 3997249 ("nfsd: update percpu_ref to manage references on nfsd_net") Cc: [email protected] Signed-off-by: Edward Adam Davis <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent d042406 commit 0b88bfa

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

fs/nfsd/nfssvc.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -406,26 +406,26 @@ static void nfsd_shutdown_net(struct net *net)
406406
{
407407
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
408408

409-
if (!nn->nfsd_net_up)
410-
return;
411-
412-
percpu_ref_kill_and_confirm(&nn->nfsd_net_ref, nfsd_net_done);
413-
wait_for_completion(&nn->nfsd_net_confirm_done);
414-
415-
nfsd_export_flush(net);
416-
nfs4_state_shutdown_net(net);
417-
nfsd_reply_cache_shutdown(nn);
418-
nfsd_file_cache_shutdown_net(net);
419-
if (nn->lockd_up) {
420-
lockd_down(net);
421-
nn->lockd_up = false;
409+
if (nn->nfsd_net_up) {
410+
percpu_ref_kill_and_confirm(&nn->nfsd_net_ref, nfsd_net_done);
411+
wait_for_completion(&nn->nfsd_net_confirm_done);
412+
413+
nfsd_export_flush(net);
414+
nfs4_state_shutdown_net(net);
415+
nfsd_reply_cache_shutdown(nn);
416+
nfsd_file_cache_shutdown_net(net);
417+
if (nn->lockd_up) {
418+
lockd_down(net);
419+
nn->lockd_up = false;
420+
}
421+
wait_for_completion(&nn->nfsd_net_free_done);
422422
}
423423

424-
wait_for_completion(&nn->nfsd_net_free_done);
425424
percpu_ref_exit(&nn->nfsd_net_ref);
426425

426+
if (nn->nfsd_net_up)
427+
nfsd_shutdown_generic();
427428
nn->nfsd_net_up = false;
428-
nfsd_shutdown_generic();
429429
}
430430

431431
static DEFINE_SPINLOCK(nfsd_notifier_lock);

0 commit comments

Comments
 (0)