From: syzbot <syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] nfsd: fix percpu_ref leak when nfsd_net_up is false
Date: Tue, 16 Dec 2025 02:22:33 -0800 [thread overview]
Message-ID: <694132e9.a70a0220.33cd7b.0138.GAE@google.com> (raw)
In-Reply-To: <69410b4b.a70a0220.104cf0.0347.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] nfsd: fix percpu_ref leak when nfsd_net_up is false
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
When nfsd_destroy_serv() is called without any threads being started,
nfsd_startup_net() was never invoked, so nfsd_net_up remains false.
In this case, nfsd_shutdown_net() returns early without calling
percpu_ref_exit() to free the percpu reference initialized in
nfsd_create_serv().
This causes two memory leaks per call:
- 8 bytes of percpu memory (the reference counter)
- 64 bytes of slab memory (the percpu_ref_data structure)
Fix this by calling percpu_ref_exit() in the early return path when
nfsd_net_up is false.
Reported-by: syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
Fixes: 47e988147f40 ("nfsd: add nfsd_serv_try_get and nfsd_serv_put")
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/nfsd/nfssvc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index b08ae85d53ef..00c6a0c96885 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -406,8 +406,10 @@ static void nfsd_shutdown_net(struct net *net)
{
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
- if (!nn->nfsd_net_up)
+ if (!nn->nfsd_net_up) {
+ percpu_ref_exit(&nn->nfsd_net_ref);
return;
+ }
percpu_ref_kill_and_confirm(&nn->nfsd_net_ref, nfsd_net_done);
wait_for_completion(&nn->nfsd_net_confirm_done);
--
2.43.0
next prev parent reply other threads:[~2025-12-16 10:22 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 ` syzbot [this message]
2025-12-16 10:27 ` [PATCH] NFSD: net ref data still needs to be freed even if net hasn't startup Edward Adam Davis
2025-12-16 16:02 ` 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=694132e9.a70a0220.33cd7b.0138.GAE@google.com \
--to=syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.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