[syzbot] [nfs?] memory leak in percpu_ref_init

6 views
Skip to first unread message

syzbot

unread,
2:33 AMĀ (10 hours ago)Ā 2:33 AM
to Dai...@oracle.com, chuck...@oracle.com, jla...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, ne...@brown.name, okor...@redhat.com, syzkall...@googlegroups.com, t...@talpey.com
Hello,

syzbot found the following issue on:

HEAD commit: d358e5254674 Merge tag 'for-6.19/dm-changes' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=176f561a580000
kernel config: https://syzkaller.appspot.com/x/.config?x=9a0268003e02068d
dashboard link: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
compiler: gcc (Debian 12.2.0-14+deb12u1) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15a6661a580000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11d4a1b4580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/e79f317bb571/disk-d358e525.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/cf9e2849af10/vmlinux-d358e525.xz
kernel image: https://storage.googleapis.com/syzbot-assets/73d80a967038/bzImage-d358e525.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+6ee3b8...@syzkaller.appspotmail.com

BUG: memory leak
unreferenced object (percpu) 0x607e4d6bd360 (size 8):
comm "syz.0.17", pid 6093, jiffies 4294942369
hex dump (first 8 bytes on cpu 0):
00 00 00 00 00 00 00 00 ........
backtrace (crc 0):
pcpu_alloc_noprof+0x82c/0xd60 mm/percpu.c:1890
percpu_ref_init+0x36/0x1e0 lib/percpu-refcount.c:72
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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object 0xffff88812a39dfc0 (size 64):
comm "syz.0.17", pid 6093, jiffies 4294942369
hex dump (first 32 bytes):
01 00 00 00 00 00 00 80 80 59 d7 81 ff ff ff ff .........Y......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc a2262fc6):
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]
__kmalloc_cache_noprof+0x3b2/0x570 mm/slub.c:5771
kmalloc_noprof include/linux/slab.h:957 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object (percpu) 0x607e4d6bd368 (size 8):
comm "syz.0.18", pid 6095, jiffies 4294942370
hex dump (first 8 bytes on cpu 0):
00 00 00 00 00 00 00 00 ........
backtrace (crc 0):
pcpu_alloc_noprof+0x82c/0xd60 mm/percpu.c:1890
percpu_ref_init+0x36/0x1e0 lib/percpu-refcount.c:72
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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object 0xffff88812833c840 (size 64):
comm "syz.0.18", pid 6095, jiffies 4294942370
hex dump (first 32 bytes):
01 00 00 00 00 00 00 80 80 59 d7 81 ff ff ff ff .........Y......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc a2262fc6):
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]
__kmalloc_cache_noprof+0x3b2/0x570 mm/slub.c:5771
kmalloc_noprof include/linux/slab.h:957 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

connection error: failed to recv *flatrpc.ExecutorMessageRawT: read tcp 127.0.0.1:36571->127.0.0.1:45172: read: connection reset by peer


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

syzbot

unread,
3:02 AMĀ (10 hours ago)Ā 3:02 AM
to linux-...@vger.kernel.org, syzkall...@googlegroups.com
For archival purposes, forwarding an incoming command email to
linux-...@vger.kernel.org, syzkall...@googlegroups.com.

***

Subject: [PATCH] nfsd: fix memory leak in nfsd_create_serv error paths
Author: karti...@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+6ee3b8...@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
Signed-off-by: Deepanshu Kartikey <karti...@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

syzbot

unread,
3:18 AMĀ (9 hours ago)Ā 3:18 AM
to karti...@gmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in percpu_ref_init

2025/12/16 08:16:45 executed programs: 5
BUG: memory leak
unreferenced object (percpu) 0x607e4d6bf800 (size 8):
comm "syz.0.17", pid 6716, jiffies 4294946723
hex dump (first 8 bytes on cpu 0):
00 00 00 00 00 00 00 00 ........
backtrace (crc 0):
pcpu_alloc_noprof+0x82c/0xd60 mm/percpu.c:1890
percpu_ref_init+0x36/0x1e0 lib/percpu-refcount.c:72
nfsd_create_serv+0xc5/0x270 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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object 0xffff88811b287b80 (size 64):
comm "syz.0.17", pid 6716, jiffies 4294946723
hex dump (first 32 bytes):
01 00 00 00 00 00 00 80 40 68 d7 81 ff ff ff ff ........@h......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc a8b59ccf):
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]
__kmalloc_cache_noprof+0x3b2/0x570 mm/slub.c:5771
kmalloc_noprof include/linux/slab.h:957 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
percpu_ref_init+0x94/0x1e0 lib/percpu-refcount.c:76
nfsd_create_serv+0xc5/0x270 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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object (percpu) 0x607e4d6c0e48 (size 8):
comm "syz.0.18", pid 6721, jiffies 4294946724
hex dump (first 8 bytes on cpu 0):
00 00 00 00 00 00 00 00 ........
backtrace (crc 0):
pcpu_alloc_noprof+0x82c/0xd60 mm/percpu.c:1890
percpu_ref_init+0x36/0x1e0 lib/percpu-refcount.c:72
nfsd_create_serv+0xc5/0x270 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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object 0xffff88810a3af280 (size 64):
comm "syz.0.18", pid 6721, jiffies 4294946724
hex dump (first 32 bytes):
01 00 00 00 00 00 00 80 40 68 d7 81 ff ff ff ff ........@h......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc a8b59ccf):
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]
__kmalloc_cache_noprof+0x3b2/0x570 mm/slub.c:5771
kmalloc_noprof include/linux/slab.h:957 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
percpu_ref_init+0x94/0x1e0 lib/percpu-refcount.c:76
nfsd_create_serv+0xc5/0x270 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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

BUG: memory leak
unreferenced object (percpu) 0x607e4d6c0e50 (size 8):
comm "syz.0.19", pid 6726, jiffies 4294946725
hex dump (first 8 bytes on cpu 0):
00 00 00 00 00 00 00 00 ........
backtrace (crc 0):
pcpu_alloc_noprof+0x82c/0xd60 mm/percpu.c:1890
percpu_ref_init+0x36/0x1e0 lib/percpu-refcount.c:72
nfsd_create_serv+0xc5/0x270 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
netlink_rcv_skb+0x93/0x1d0 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1219
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x3a3/0x4f0 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x335/0x6b0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg net/socket.c:742 [inline]
____sys_sendmsg+0x562/0x5a0 net/socket.c:2592
___sys_sendmsg+0xc8/0x130 net/socket.c:2646
__sys_sendmsg+0xc7/0x140 net/socket.c:2678
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

connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF


Tested on:

commit: 8f0b4cce Linux 6.19-rc1
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=152c231a580000
kernel config: https://syzkaller.appspot.com/x/.config?x=d60836e327fd6756
dashboard link: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
compiler: gcc (Debian 12.2.0-14+deb12u1) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=1489e184580000

syzbot

unread,
5:22 AMĀ (7 hours ago)Ā 5:22 AM
to linux-...@vger.kernel.org, syzkall...@googlegroups.com
For archival purposes, forwarding an incoming command email to
linux-...@vger.kernel.org, syzkall...@googlegroups.com.

***

Subject: [PATCH] nfsd: fix percpu_ref leak when nfsd_net_up is false
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.
Fixes: 47e988147f40 ("nfsd: add nfsd_serv_try_get and nfsd_serv_put")
Signed-off-by: Deepanshu Kartikey <karti...@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

Edward Adam Davis

unread,
5:27 AMĀ (7 hours ago)Ā 5:27 AM
to syzbot+6ee3b8...@syzkaller.appspotmail.com, Dai...@oracle.com, chuck...@oracle.com, jla...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, ne...@brown.name, okor...@redhat.com, syzkall...@googlegroups.com, t...@talpey.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

Signed-off-by: Edward Adam Davis <ead...@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

syzbot

unread,
6:48 AMĀ (6 hours ago)Ā 6:48 AM
to karti...@gmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+6ee3b8...@syzkaller.appspotmail.com
Tested-by: syzbot+6ee3b8...@syzkaller.appspotmail.com

Tested on:

commit: 40fbbd64 Merge tag 'pull-fixes' of git://git.kernel.or..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13a32a60580000
kernel config: https://syzkaller.appspot.com/x/.config?x=d60836e327fd6756
dashboard link: https://syzkaller.appspot.com/bug?extid=6ee3b889bdeada0a6226
compiler: gcc (Debian 12.2.0-14+deb12u1) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=1262231a580000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages