From: syzbot <syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] nfsd: fix memory leak in nfsd_create_serv error paths
Date: Tue, 16 Dec 2025 00:02:21 -0800 [thread overview]
Message-ID: <6941120d.a70a0220.104cf0.0348.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 memory leak in nfsd_create_serv error paths
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
When svc_create_pooled() or svc_bind() fails, nfsd_create_serv() returns
an error without calling percpu_ref_exit() to clean up the percpu
reference that was initialized earlier in the function.
This causes two memory leaks per failed call:
- 8 bytes of percpu memory (the reference counter)
- 64 bytes of slab memory (the percpu_ref_data structure)
Fix this by adding an error label that calls percpu_ref_exit() before
returning.
Reported-by: syzbot+6ee3b889bdeada0a6226@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/nfsd/nfssvc.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index b08ae85d53ef..49fd77c8f98d 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -615,13 +615,14 @@ int nfsd_create_serv(struct net *net)
serv = svc_create_pooled(nfsd_programs, ARRAY_SIZE(nfsd_programs),
&nn->nfsd_svcstats,
nfsd_max_blksize, nfsd);
- if (serv == NULL)
- return -ENOMEM;
-
+ if (serv == NULL) {
+ error = -ENOMEM;
+ goto err_percpu;
+ }
error = svc_bind(serv, net);
if (error < 0) {
svc_destroy(&serv);
- return error;
+ goto err_percpu;
}
spin_lock(&nfsd_notifier_lock);
nn->nfsd_serv = serv;
@@ -636,6 +637,9 @@ int nfsd_create_serv(struct net *net)
}
nfsd_reset_write_verifier(nn);
return 0;
+err_percpu:
+ percpu_ref_exit(&nn->nfsd_net_ref);
+ return error;
}
int nfsd_nrpools(struct net *net)
--
2.43.0
next prev parent reply other threads:[~2025-12-16 8:02 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 ` syzbot [this message]
2025-12-16 10:22 ` Forwarded: [PATCH] nfsd: fix percpu_ref leak when nfsd_net_up is false syzbot
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=6941120d.a70a0220.104cf0.0348.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.