From: Edward Adam Davis <eadavis@qq.com>
To: syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com
Cc: Dai.Ngo@oracle.com, chuck.lever@oracle.com, jlayton@kernel.org,
linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org,
neil@brown.name, okorniev@redhat.com,
syzkaller-bugs@googlegroups.com, tom@talpey.com
Subject: [PATCH] NFSD: net ref data still needs to be freed even if net hasn't startup
Date: Tue, 16 Dec 2025 18:27:37 +0800 [thread overview]
Message-ID: <tencent_4DA6D7B3792370296083BAC4525778776405@qq.com> (raw)
In-Reply-To: <69410b4b.a70a0220.104cf0.0347.GAE@google.com>
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]
BUG: memory leak
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
Reported-by: syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
fs/nfsd/nfssvc.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index b08ae85d53ef..e2b2cf0dd013 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -406,26 +406,26 @@ static void nfsd_shutdown_net(struct net *net)
{
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
- if (!nn->nfsd_net_up)
- return;
-
- percpu_ref_kill_and_confirm(&nn->nfsd_net_ref, nfsd_net_done);
- wait_for_completion(&nn->nfsd_net_confirm_done);
-
- nfsd_export_flush(net);
- nfs4_state_shutdown_net(net);
- nfsd_reply_cache_shutdown(nn);
- nfsd_file_cache_shutdown_net(net);
- if (nn->lockd_up) {
- lockd_down(net);
- nn->lockd_up = false;
+ if (nn->nfsd_net_up) {
+ percpu_ref_kill_and_confirm(&nn->nfsd_net_ref, nfsd_net_done);
+ wait_for_completion(&nn->nfsd_net_confirm_done);
+
+ nfsd_export_flush(net);
+ nfs4_state_shutdown_net(net);
+ nfsd_reply_cache_shutdown(nn);
+ nfsd_file_cache_shutdown_net(net);
+ if (nn->lockd_up) {
+ lockd_down(net);
+ nn->lockd_up = false;
+ }
+ wait_for_completion(&nn->nfsd_net_free_done);
}
- wait_for_completion(&nn->nfsd_net_free_done);
percpu_ref_exit(&nn->nfsd_net_ref);
+ if (nn->nfsd_net_up)
+ nfsd_shutdown_generic();
nn->nfsd_net_up = false;
- nfsd_shutdown_generic();
}
static DEFINE_SPINLOCK(nfsd_notifier_lock);
--
2.43.0
next prev parent reply other threads:[~2025-12-16 10:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 7:33 [syzbot] [nfs?] memory leak in percpu_ref_init syzbot
2025-12-16 8:02 ` Forwarded: [PATCH] nfsd: fix memory leak in nfsd_create_serv error paths syzbot
2025-12-16 10:22 ` Forwarded: [PATCH] nfsd: fix percpu_ref leak when nfsd_net_up is false syzbot
2025-12-16 10:27 ` Edward Adam Davis [this message]
2025-12-16 16:02 ` [PATCH] NFSD: net ref data still needs to be freed even if net hasn't startup Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_4DA6D7B3792370296083BAC4525778776405@qq.com \
--to=eadavis@qq.com \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®