Re: memory leak in fasync_helper

From: Eric Dumazet
Date: Sun Dec 08 2019 - 00:51:56 EST




On 12/7/19 9:45 PM, syzbot wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit:ÂÂÂ bf929479 Merge branch 'for-linus' of git://git.kernel.org/..
> git tree:ÂÂÂÂÂÂ upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=123e91e2e00000
> kernel config:Â https://syzkaller.appspot.com/x/.config?x=874c75a332209d41
> dashboard link: https://syzkaller.appspot.com/bug?extid=4b1fe8105f8044a26162
> compiler:ÂÂÂÂÂÂ gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:ÂÂÂÂÂ https://syzkaller.appspot.com/x/repro.syz?x=120faee2e00000
> C reproducer:ÂÂ https://syzkaller.appspot.com/x/repro.c?x=178a0ef6e00000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+4b1fe8105f8044a26162@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> BUG: memory leak
> unreferenced object 0xffff88812a4082a0 (size 48):
> Â comm "syz-executor670", pid 6989, jiffies 4294952355 (age 19.520s)
> Â hex dump (first 32 bytes):
> ÂÂÂ 00 00 00 00 00 00 00 00 01 46 00 00 03 00 00 00Â .........F......
>  00 00 00 00 00 00 00 00 00 6b 05 1f 81 88 ff ff .........k......
> Â backtrace:
> ÂÂÂ [<000000002a74b343>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
> ÂÂÂ [<000000002a74b343>] slab_post_alloc_hook mm/slab.h:586 [inline]
> ÂÂÂ [<000000002a74b343>] slab_alloc mm/slab.c:3319 [inline]
> ÂÂÂ [<000000002a74b343>] kmem_cache_alloc+0x13f/0x2c0 mm/slab.c:3483
> ÂÂÂ [<00000000fa370506>] fasync_alloc fs/fcntl.c:895 [inline]
> ÂÂÂ [<00000000fa370506>] fasync_add_entry fs/fcntl.c:953 [inline]
> ÂÂÂ [<00000000fa370506>] fasync_helper+0x37/0xa9 fs/fcntl.c:982
> ÂÂÂ [<000000006c3eaaf1>] sock_fasync+0x4d/0xa0 net/socket.c:1293
> ÂÂÂ [<0000000098076f55>] ioctl_fioasync fs/ioctl.c:550 [inline]
> ÂÂÂ [<0000000098076f55>] do_vfs_ioctl+0x409/0x810 fs/ioctl.c:655
> ÂÂÂ [<00000000df24d2b9>] ksys_ioctl+0x86/0xb0 fs/ioctl.c:713
> ÂÂÂ [<000000003fec9c80>] __do_sys_ioctl fs/ioctl.c:720 [inline]
> ÂÂÂ [<000000003fec9c80>] __se_sys_ioctl fs/ioctl.c:718 [inline]
> ÂÂÂ [<000000003fec9c80>] __x64_sys_ioctl+0x1e/0x30 fs/ioctl.c:718
> ÂÂÂ [<000000002bebbfe6>] do_syscall_64+0x73/0x1f0 arch/x86/entry/common.c:290
> ÂÂÂ [<00000000722d8431>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
> BUG: memory leak
> unreferenced object 0xffff888128cdf240 (size 48):
> Â comm "syz-executor670", pid 6990, jiffies 4294952942 (age 13.650s)
> Â hex dump (first 32 bytes):
> ÂÂÂ 00 00 00 00 00 00 00 00 01 46 00 00 03 00 00 00Â .........F......
>  00 00 00 00 00 00 00 00 00 d8 02 19 81 88 ff ff ................
> Â backtrace:
> ÂÂÂ [<000000002a74b343>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
> ÂÂÂ [<000000002a74b343>] slab_post_alloc_hook mm/slab.h:586 [inline]
> ÂÂÂ [<000000002a74b343>] slab_alloc mm/slab.c:3319 [inline]
> ÂÂÂ [<000000002a74b343>] kmem_cache_alloc+0x13f/0x2c0 mm/slab.c:3483
> ÂÂÂ [<00000000fa370506>] fasync_alloc fs/fcntl.c:895 [inline]
> ÂÂÂ [<00000000fa370506>] fasync_add_entry fs/fcntl.c:953 [inline]
> ÂÂÂ [<00000000fa370506>] fasync_helper+0x37/0xa9 fs/fcntl.c:982
> ÂÂÂ [<000000006c3eaaf1>] sock_fasync+0x4d/0xa0 net/socket.c:1293
> ÂÂÂ [<0000000098076f55>] ioctl_fioasync fs/ioctl.c:550 [inline]
> ÂÂÂ [<0000000098076f55>] do_vfs_ioctl+0x409/0x810 fs/ioctl.c:655
> ÂÂÂ [<00000000df24d2b9>] ksys_ioctl+0x86/0xb0 fs/ioctl.c:713
> ÂÂÂ [<000000003fec9c80>] __do_sys_ioctl fs/ioctl.c:720 [inline]
> ÂÂÂ [<000000003fec9c80>] __se_sys_ioctl fs/ioctl.c:718 [inline]
> ÂÂÂ [<000000003fec9c80>] __x64_sys_ioctl+0x1e/0x30 fs/ioctl.c:718
> ÂÂÂ [<000000002bebbfe6>] do_syscall_64+0x73/0x1f0 arch/x86/entry/common.c:290
> ÂÂÂ [<00000000722d8431>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
> BUG: memory leak
> unreferenced object 0xffff888128cdff60 (size 48):
> Â comm "syz-executor670", pid 6991, jiffies 4294953529 (age 7.780s)
> Â hex dump (first 32 bytes):
> ÂÂÂ 00 00 00 00 00 00 00 00 01 46 00 00 03 00 00 00Â .........F......
>  00 00 00 00 00 00 00 00 00 63 05 1f 81 88 ff ff .........c......
> Â backtrace:
> ÂÂÂ [<000000002a74b343>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
> ÂÂÂ [<000000002a74b343>] slab_post_alloc_hook mm/slab.h:586 [inline]
> ÂÂÂ [<000000002a74b343>] slab_alloc mm/slab.c:3319 [inline]
> ÂÂÂ [<000000002a74b343>] kmem_cache_alloc+0x13f/0x2c0 mm/slab.c:3483
> ÂÂÂ [<00000000fa370506>] fasync_alloc fs/fcntl.c:895 [inline]
> ÂÂÂ [<00000000fa370506>] fasync_add_entry fs/fcntl.c:953 [inline]
> ÂÂÂ [<00000000fa370506>] fasync_helper+0x37/0xa9 fs/fcntl.c:982
> ÂÂÂ [<000000006c3eaaf1>] sock_fasync+0x4d/0xa0 net/socket.c:1293
> ÂÂÂ [<0000000098076f55>] ioctl_fioasync fs/ioctl.c:550 [inline]
> ÂÂÂ [<0000000098076f55>] do_vfs_ioctl+0x409/0x810 fs/ioctl.c:655
> ÂÂÂ [<00000000df24d2b9>] ksys_ioctl+0x86/0xb0 fs/ioctl.c:713
> ÂÂÂ [<000000003fec9c80>] __do_sys_ioctl fs/ioctl.c:720 [inline]
> ÂÂÂ [<000000003fec9c80>] __se_sys_ioctl fs/ioctl.c:718 [inline]
> ÂÂÂ [<000000003fec9c80>] __x64_sys_ioctl+0x1e/0x30 fs/ioctl.c:718
> ÂÂÂ [<000000002bebbfe6>] do_syscall_64+0x73/0x1f0 arch/x86/entry/common.c:290
> ÂÂÂ [<00000000722d8431>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
>
>
> ---
> This bug 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 syzkaller@xxxxxxxxxxxxxxxxx
>
> syzbot will keep track of this bug report. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
> syzbot can test patches for this bug, for details see:
> https://goo.gl/tpsmEJ#testing-patche


AF_SMC bug it seems....

Repro does essentially :

socket(AF_SMC, SOCK_STREAM, SMCPROTO_SMC) = 3
ioctl(3, FIOASYNC, [-1]) = 0
sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=NULL, msg_iovlen=0, msg_controllen=0, msg_flags=0}, MSG_FASTOPEN)


console logs :

__sock_release: fasync list not empty!