nfsd: Fix cred refcount leak.
Subsystems (2)
cover nfsd: Fix cred refcount leak.
get_current_cred() is misused in nfsd_nl_listener_set_doit() and nfsd_nl_threads_set_doit(), leaking the cred refcount.
Patch 1 & 2 fixes the leak in each function.
Kuniyuki Iwashima (2):
nfsd: Fix cred ref leak in nfsd_nl_threads_set_doit().
nfsd: Fix cred ref leak in nfsd_nl_listener_set_doit().
fs/nfsd/nfsctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0.457.g6b5491de43-goog
PATCH 1/2 nfsd: Fix cred ref leak in nfsd_nl_threads_set_doit().
syzbot reported memory leak of struct cred. [0]
nfsd_nl_threads_set_doit() passes get_current_cred() to nfsd_svc(), but put_cred() is not called after that.
The cred is finally passed down to _svc_xprt_create(), which calls get_cred() with the cred for struct svc_xprt.
The ownership of the refcount by get_current_cred() is not transferred to anywhere and is just leaked.
nfsd_svc() is also called from write_threads(), but it does not bump file->f_cred there.
nfsd_nl_threads_set_doit() is called from sendmsg() and current->cred does not go away.
Let's use current_cred() in nfsd_nl_threads_set_doit().
[0]:
BUG: memory leak
unreferenced object 0xffff888108b89480 (size 184):
comm "syz-executor", pid 5994, jiffies 4294943386
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc 369454a7):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4958 [inline]
slab_alloc_node mm/slub.c:5263 [inline]
kmem_cache_alloc_noprof+0x412/0x580 mm/slub.c:5270
prepare_creds+0x22/0x600 kernel/cred.c:185
copy_creds+0x44/0x290 kernel/cred.c:286
copy_process+0x7a7/0x2870 kernel/fork.c:2086
kernel_clone+0xac/0x6e0 kernel/fork.c:2651
__do_sys_clone+0x7f/0xb0 kernel/fork.c:2792
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xa4/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f--- fs/nfsd/nfsctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsctl.c +1 -1
@@ -1642,7 +1642,7 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info) scope =nla_data (attr); } - ret =nfsd_svc (nrpools, nthreads, net,get_current_cred (), scope); + ret =nfsd_svc (nrpools, nthreads, net,current_cred (), scope);if (ret >0 ) ret =0 ; out_unlock:
Signature · 1 line
2.52.0.457.g6b5491de43-goog
PATCH 2/2 nfsd: Fix cred ref leak in nfsd_nl_listener_set_doit().
In reply to Kuniyuki Iwashimanfsd_nl_listener_set_doit() uses get_current_cred() without put_cred().
As we can see from other callers, svc_xprt_create_from_sa() does not require the extra refcount.
nfsd_nl_listener_set_doit() is always in the process context, sendmsg(), and current->cred does not go away.
Let's use current_cred() in nfsd_nl_listener_set_doit().
--- fs/nfsd/nfsctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsctl.c +1 -1
@@ -1993,7 +1993,7 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info) } ret =svc_xprt_create_from_sa (serv, xcl_name, net, sa,0 , -get_current_cred ()); +current_cred ());/* always save the latest error */ if (ret <0 ) err = ret;
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Quoted 6 lines · Kuniyuki Iwashima
get_current_cred()is misused innfsd_nl_listener_set_doit()andnfsd_nl_threads_set_doit(), leaking the cred refcount.Patch 1 & 2 fixes the leak in each function.
Quoted 6 lines
Kuniyuki Iwashima (2):
nfsd: Fix cred ref leak innfsd_nl_threads_set_doit().
nfsd: Fix cred ref leak innfsd_nl_listener_set_doit().fs/nfsd/nfsctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Nice catch.
Chuck Lever
maintainerFrom: Chuck Lever <[email protected]>
Quoted 11 lines · Kuniyuki Iwashima
get_current_cred()is misused innfsd_nl_listener_set_doit()andnfsd_nl_threads_set_doit(), leaking the cred refcount.Patch 1 & 2 fixes the leak in each function.
Kuniyuki Iwashima (2):
nfsd: Fix cred ref leak innfsd_nl_threads_set_doit().
nfsd: Fix cred ref leak innfsd_nl_listener_set_doit().[...]
Applied to nfsd-testing, thanks!
[1/2] nfsd: Fix cred ref leak in nfsd_nl_threads_set_doit().
commit: c14b0c3b5966a1e2cf6a7f219c4f4b3fafeb89d0
[2/2] nfsd: Fix cred ref leak in nfsd_nl_listener_set_doit().
commit: 687b9b69fcda9de606e998fd2edccb8a14406e19--
Chuck Lever
Hi Chuck,
From: Chuck Lever <[email protected]>
Date: Sat, 24 Jan 2026 22:21:05 -0500
Quoted 13 lines
From: Chuck Lever <[email protected]>
Quoted 10 lines · Kuniyuki Iwashima
get_current_cred()is misused innfsd_nl_listener_set_doit()andnfsd_nl_threads_set_doit(), leaking the cred refcount.Patch 1 & 2 fixes the leak in each function.
Kuniyuki Iwashima (2):
nfsd: Fix cred ref leak innfsd_nl_threads_set_doit().
nfsd: Fix cred ref leak innfsd_nl_listener_set_doit().
Quoted 8 lines
Quoted 1 line
[...]
Applied to nfsd-testing, thanks!
[1/2] nfsd: Fix cred ref leak in
nfsd_nl_threads_set_doit().commit: c14b0c3b5966a1e2cf6a7f219c4f4b3fafeb89d0 [2/2] nfsd: Fix cred ref leak in nfsd_nl_listener_set_doit(). commit: 687b9b69fcda9de606e998fd2edccb8a14406e19
While rebasing my local branch, I just noticed both patches are not in the mainline and I couldn't find both SHA1 in your tree.
Could you double check ?
Thanks !
Chuck Lever
maintainerQuoted 26 lines · Kuniyuki Iwashima
Hi Chuck,
From: Chuck Lever <[email protected]>
Date: Sat, 24 Jan 2026 22:21:05 -0500Quoted 13 lines
From: Chuck Lever <[email protected]>
Quoted 10 lines · Kuniyuki Iwashima
get_current_cred()is misused innfsd_nl_listener_set_doit()andnfsd_nl_threads_set_doit(), leaking the cred refcount.Patch 1 & 2 fixes the leak in each function.
Kuniyuki Iwashima (2):
nfsd: Fix cred ref leak innfsd_nl_threads_set_doit().
nfsd: Fix cred ref leak innfsd_nl_listener_set_doit().Quoted 8 lines
Quoted 1 line
[...]
Applied to nfsd-testing, thanks!
[1/2] nfsd: Fix cred ref leak in
nfsd_nl_threads_set_doit().commit: c14b0c3b5966a1e2cf6a7f219c4f4b3fafeb89d0 [2/2] nfsd: Fix cred ref leak in nfsd_nl_listener_set_doit(). commit: 687b9b69fcda9de606e998fd2edccb8a14406e19
Quoted 7 lines
While rebasing my local branch, I just noticed both patches are not in the mainline and I couldn't find both SHA1 in your tree.
Could you double check ?
The patches are in my nfsd-fixes branch. I'm planning to submit them soon for 7.0-rc .
Signature · 1 line
Chuck Lever
Quoted 32 lines · Chuck Lever
Quoted 30 lines · Kuniyuki Iwashima
Hi Chuck,
From: Chuck Lever <[email protected]>
Date: Sat, 24 Jan 2026 22:21:05 -0500Quoted 13 lines
From: Chuck Lever <[email protected]>
Quoted 10 lines · Kuniyuki Iwashima
get_current_cred()is misused innfsd_nl_listener_set_doit()andnfsd_nl_threads_set_doit(), leaking the cred refcount.Patch 1 & 2 fixes the leak in each function.
Kuniyuki Iwashima (2):
nfsd: Fix cred ref leak innfsd_nl_threads_set_doit().
nfsd: Fix cred ref leak innfsd_nl_listener_set_doit().Quoted 8 lines
Quoted 1 line
[...]
Applied to nfsd-testing, thanks!
[1/2] nfsd: Fix cred ref leak in
nfsd_nl_threads_set_doit().commit: c14b0c3b5966a1e2cf6a7f219c4f4b3fafeb89d0 [2/2] nfsd: Fix cred ref leak in nfsd_nl_listener_set_doit(). commit: 687b9b69fcda9de606e998fd2edccb8a14406e19While rebasing my local branch, I just noticed both patches are not in the mainline and I couldn't find both SHA1 in your tree.
Quoted 6 lines
Quoted 3 lines
Could you double check ?
The patches are in my nfsd-fixes branch. I'm planning to submit them soon for 7.0-rc .
Sounds good, sorry for bothering you, and thank you for checking !