2022-11-14 03:24:32

by syzbot

[permalink] [raw]
Subject: [syzbot] possible deadlock in virtual_nci_close

Hello,

syzbot found the following issue on:

HEAD commit: af7a05689189 Merge tag 'mips-fixes_6.1_1' of git://git.ker..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13d30249880000
kernel config: https://syzkaller.appspot.com/x/.config?x=9d1d2dd6d424a076
dashboard link: https://syzkaller.appspot.com/bug?extid=8040d16d30c215f821de
compiler: aarch64-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
userspace arch: arm64

Unfortunately, I don't have any reproducer for this issue yet.

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email protected]

nci: __nci_request: wait_for_completion_interruptible_timeout failed 0
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc4-syzkaller-00372-gaf7a05689189 #0 Not tainted
------------------------------------------------------
syz-executor.1/8551 is trying to acquire lock:
ffff80000e6854c8 (nci_mutex){+.+.}-{3:3}, at: virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44

but task is already holding lock:
ffff000030115350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&ndev->req_lock){+.+.}-{3:3}:
__mutex_lock_common kernel/locking/mutex.c:603 [inline]
__mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
nci_request net/nfc/nci/core.c:148 [inline]
nci_set_local_general_bytes net/nfc/nci/core.c:774 [inline]
nci_start_poll+0x36c/0x624 net/nfc/nci/core.c:838
nfc_start_poll+0x114/0x270 net/nfc/core.c:225
nfc_genl_start_poll+0x154/0x3b0 net/nfc/netlink.c:828
genl_family_rcv_msg_doit+0x1b8/0x2a0 net/netlink/genetlink.c:756
genl_family_rcv_msg net/netlink/genetlink.c:833 [inline]
genl_rcv_msg+0x2f8/0x594 net/netlink/genetlink.c:850
netlink_rcv_skb+0x180/0x330 net/netlink/af_netlink.c:2540
genl_rcv+0x38/0x50 net/netlink/genetlink.c:861
netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
netlink_unicast+0x3ec/0x684 net/netlink/af_netlink.c:1345
netlink_sendmsg+0x690/0xb1c net/netlink/af_netlink.c:1921
sock_sendmsg_nosec net/socket.c:714 [inline]
sock_sendmsg+0xc0/0xf4 net/socket.c:734
____sys_sendmsg+0x534/0x6b0 net/socket.c:2482
___sys_sendmsg+0xf0/0x174 net/socket.c:2536
__sys_sendmsg+0xc4/0x154 net/socket.c:2565
__do_sys_sendmsg net/socket.c:2574 [inline]
__se_sys_sendmsg net/socket.c:2572 [inline]
__arm64_sys_sendmsg+0x70/0xa0 net/socket.c:2572
__invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
invoke_syscall+0x6c/0x260 arch/arm64/kernel/syscall.c:52
el0_svc_common.constprop.0+0xc4/0x254 arch/arm64/kernel/syscall.c:142
do_el0_svc+0x50/0x14c arch/arm64/kernel/syscall.c:206
el0_svc+0x54/0x140 arch/arm64/kernel/entry-common.c:637
el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581

-> #2 (&genl_data->genl_data_mutex){+.+.}-{3:3}:
__mutex_lock_common kernel/locking/mutex.c:603 [inline]
__mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
nfc_urelease_event_work+0x118/0x270 net/nfc/netlink.c:1811
process_one_work+0x780/0x184c kernel/workqueue.c:2289
worker_thread+0x3cc/0xc40 kernel/workqueue.c:2436
kthread+0x23c/0x2a0 kernel/kthread.c:376
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:860

-> #1 (nfc_devlist_mutex){+.+.}-{3:3}:
__mutex_lock_common kernel/locking/mutex.c:603 [inline]
__mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
nfc_register_device+0x34/0x320 net/nfc/core.c:1116
nci_register_device+0x604/0x8c0 net/nfc/nci/core.c:1256
virtual_ncidev_open+0x64/0xe0 drivers/nfc/virtual_ncidev.c:146
misc_open+0x294/0x394 drivers/char/misc.c:143
chrdev_open+0x1c0/0x54c fs/char_dev.c:414
do_dentry_open+0x3c4/0xf40 fs/open.c:882
vfs_open+0x90/0xd0 fs/open.c:1013
do_open fs/namei.c:3557 [inline]
path_openat+0x1030/0x1fe0 fs/namei.c:3713
do_filp_open+0x154/0x330 fs/namei.c:3740
do_sys_openat2+0x124/0x390 fs/open.c:1310
do_sys_open fs/open.c:1326 [inline]
__do_sys_openat fs/open.c:1342 [inline]
__se_sys_openat fs/open.c:1337 [inline]
__arm64_sys_openat+0x130/0x1c0 fs/open.c:1337
__invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
invoke_syscall+0x6c/0x260 arch/arm64/kernel/syscall.c:52
el0_svc_common.constprop.0+0xc4/0x254 arch/arm64/kernel/syscall.c:142
do_el0_svc+0x50/0x14c arch/arm64/kernel/syscall.c:206
el0_svc+0x54/0x140 arch/arm64/kernel/entry-common.c:637
el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581

-> #0 (nci_mutex){+.+.}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3097 [inline]
check_prevs_add kernel/locking/lockdep.c:3216 [inline]
validate_chain kernel/locking/lockdep.c:3831 [inline]
__lock_acquire+0x2788/0x56d0 kernel/locking/lockdep.c:5055
lock_acquire kernel/locking/lockdep.c:5668 [inline]
lock_acquire+0x58c/0x9a0 kernel/locking/lockdep.c:5633
__mutex_lock_common kernel/locking/mutex.c:603 [inline]
__mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44
nci_close_device+0x200/0x360 net/nfc/nci/core.c:592
nci_unregister_device+0x40/0x280 net/nfc/nci/core.c:1291
virtual_ncidev_close+0x70/0x90 drivers/nfc/virtual_ncidev.c:166
__fput+0x1ac/0x860 fs/file_table.c:320
____fput+0x10/0x1c fs/file_table.c:348
task_work_run+0x12c/0x220 kernel/task_work.c:179
resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
do_notify_resume+0x920/0x2840 arch/arm64/kernel/signal.c:1127
prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
el0_svc+0x11c/0x140 arch/arm64/kernel/entry-common.c:638
el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581

other info that might help us debug this:

Chain exists of:
nci_mutex --> &genl_data->genl_data_mutex --> &ndev->req_lock

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&ndev->req_lock);
lock(&genl_data->genl_data_mutex);
lock(&ndev->req_lock);
lock(nci_mutex);

*** DEADLOCK ***

1 lock held by syz-executor.1/8551:
#0: ffff000030115350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560

stack backtrace:
CPU: 1 PID: 8551 Comm: syz-executor.1 Not tainted 6.1.0-rc4-syzkaller-00372-gaf7a05689189 #0
Hardware name: linux,dummy-virt (DT)
Call trace:
dump_backtrace+0xe0/0x140 arch/arm64/kernel/stacktrace.c:156
show_stack+0x18/0x40 arch/arm64/kernel/stacktrace.c:163
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x9c/0xd8 lib/dump_stack.c:106
dump_stack+0x1c/0x38 lib/dump_stack.c:113
print_circular_bug+0x2d4/0x2ec kernel/locking/lockdep.c:2055
check_noncircular+0x26c/0x2e0 kernel/locking/lockdep.c:2177
check_prev_add kernel/locking/lockdep.c:3097 [inline]
check_prevs_add kernel/locking/lockdep.c:3216 [inline]
validate_chain kernel/locking/lockdep.c:3831 [inline]
__lock_acquire+0x2788/0x56d0 kernel/locking/lockdep.c:5055
lock_acquire kernel/locking/lockdep.c:5668 [inline]
lock_acquire+0x58c/0x9a0 kernel/locking/lockdep.c:5633
__mutex_lock_common kernel/locking/mutex.c:603 [inline]
__mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44
nci_close_device+0x200/0x360 net/nfc/nci/core.c:592
nci_unregister_device+0x40/0x280 net/nfc/nci/core.c:1291
virtual_ncidev_close+0x70/0x90 drivers/nfc/virtual_ncidev.c:166
__fput+0x1ac/0x860 fs/file_table.c:320
____fput+0x10/0x1c fs/file_table.c:348
task_work_run+0x12c/0x220 kernel/task_work.c:179
resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
do_notify_resume+0x920/0x2840 arch/arm64/kernel/signal.c:1127
prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
el0_svc+0x11c/0x140 arch/arm64/kernel/entry-common.c:638
el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581


---
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 [email protected].

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


2022-11-14 10:48:01

by Dmitry Vyukov

[permalink] [raw]
Subject: Re: [syzbot] possible deadlock in virtual_nci_close

On Mon, 14 Nov 2022 at 04:11, syzbot
<[email protected]> wrote:
>
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: af7a05689189 Merge tag 'mips-fixes_6.1_1' of git://git.ker..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=13d30249880000
> kernel config: https://syzkaller.appspot.com/x/.config?x=9d1d2dd6d424a076
> dashboard link: https://syzkaller.appspot.com/bug?extid=8040d16d30c215f821de
> compiler: aarch64-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> userspace arch: arm64
>
> Unfortunately, I don't have any reproducer for this issue yet.
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: [email protected]

This should be fixed by the following commit when/if it's merged. The
commit removes nci_mutex.

nfc: Allow to create multiple virtual nci devices
https://lore.kernel.org/all/[email protected]/


> nci: __nci_request: wait_for_completion_interruptible_timeout failed 0
> ======================================================
> WARNING: possible circular locking dependency detected
> 6.1.0-rc4-syzkaller-00372-gaf7a05689189 #0 Not tainted
> ------------------------------------------------------
> syz-executor.1/8551 is trying to acquire lock:
> ffff80000e6854c8 (nci_mutex){+.+.}-{3:3}, at: virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44
>
> but task is already holding lock:
> ffff000030115350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560
>
> which lock already depends on the new lock.
>
>
> the existing dependency chain (in reverse order) is:
>
> -> #3 (&ndev->req_lock){+.+.}-{3:3}:
> __mutex_lock_common kernel/locking/mutex.c:603 [inline]
> __mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
> mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
> nci_request net/nfc/nci/core.c:148 [inline]
> nci_set_local_general_bytes net/nfc/nci/core.c:774 [inline]
> nci_start_poll+0x36c/0x624 net/nfc/nci/core.c:838
> nfc_start_poll+0x114/0x270 net/nfc/core.c:225
> nfc_genl_start_poll+0x154/0x3b0 net/nfc/netlink.c:828
> genl_family_rcv_msg_doit+0x1b8/0x2a0 net/netlink/genetlink.c:756
> genl_family_rcv_msg net/netlink/genetlink.c:833 [inline]
> genl_rcv_msg+0x2f8/0x594 net/netlink/genetlink.c:850
> netlink_rcv_skb+0x180/0x330 net/netlink/af_netlink.c:2540
> genl_rcv+0x38/0x50 net/netlink/genetlink.c:861
> netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
> netlink_unicast+0x3ec/0x684 net/netlink/af_netlink.c:1345
> netlink_sendmsg+0x690/0xb1c net/netlink/af_netlink.c:1921
> sock_sendmsg_nosec net/socket.c:714 [inline]
> sock_sendmsg+0xc0/0xf4 net/socket.c:734
> ____sys_sendmsg+0x534/0x6b0 net/socket.c:2482
> ___sys_sendmsg+0xf0/0x174 net/socket.c:2536
> __sys_sendmsg+0xc4/0x154 net/socket.c:2565
> __do_sys_sendmsg net/socket.c:2574 [inline]
> __se_sys_sendmsg net/socket.c:2572 [inline]
> __arm64_sys_sendmsg+0x70/0xa0 net/socket.c:2572
> __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
> invoke_syscall+0x6c/0x260 arch/arm64/kernel/syscall.c:52
> el0_svc_common.constprop.0+0xc4/0x254 arch/arm64/kernel/syscall.c:142
> do_el0_svc+0x50/0x14c arch/arm64/kernel/syscall.c:206
> el0_svc+0x54/0x140 arch/arm64/kernel/entry-common.c:637
> el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
> el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581
>
> -> #2 (&genl_data->genl_data_mutex){+.+.}-{3:3}:
> __mutex_lock_common kernel/locking/mutex.c:603 [inline]
> __mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
> mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
> nfc_urelease_event_work+0x118/0x270 net/nfc/netlink.c:1811
> process_one_work+0x780/0x184c kernel/workqueue.c:2289
> worker_thread+0x3cc/0xc40 kernel/workqueue.c:2436
> kthread+0x23c/0x2a0 kernel/kthread.c:376
> ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:860
>
> -> #1 (nfc_devlist_mutex){+.+.}-{3:3}:
> __mutex_lock_common kernel/locking/mutex.c:603 [inline]
> __mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
> mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
> nfc_register_device+0x34/0x320 net/nfc/core.c:1116
> nci_register_device+0x604/0x8c0 net/nfc/nci/core.c:1256
> virtual_ncidev_open+0x64/0xe0 drivers/nfc/virtual_ncidev.c:146
> misc_open+0x294/0x394 drivers/char/misc.c:143
> chrdev_open+0x1c0/0x54c fs/char_dev.c:414
> do_dentry_open+0x3c4/0xf40 fs/open.c:882
> vfs_open+0x90/0xd0 fs/open.c:1013
> do_open fs/namei.c:3557 [inline]
> path_openat+0x1030/0x1fe0 fs/namei.c:3713
> do_filp_open+0x154/0x330 fs/namei.c:3740
> do_sys_openat2+0x124/0x390 fs/open.c:1310
> do_sys_open fs/open.c:1326 [inline]
> __do_sys_openat fs/open.c:1342 [inline]
> __se_sys_openat fs/open.c:1337 [inline]
> __arm64_sys_openat+0x130/0x1c0 fs/open.c:1337
> __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
> invoke_syscall+0x6c/0x260 arch/arm64/kernel/syscall.c:52
> el0_svc_common.constprop.0+0xc4/0x254 arch/arm64/kernel/syscall.c:142
> do_el0_svc+0x50/0x14c arch/arm64/kernel/syscall.c:206
> el0_svc+0x54/0x140 arch/arm64/kernel/entry-common.c:637
> el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
> el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581
>
> -> #0 (nci_mutex){+.+.}-{3:3}:
> check_prev_add kernel/locking/lockdep.c:3097 [inline]
> check_prevs_add kernel/locking/lockdep.c:3216 [inline]
> validate_chain kernel/locking/lockdep.c:3831 [inline]
> __lock_acquire+0x2788/0x56d0 kernel/locking/lockdep.c:5055
> lock_acquire kernel/locking/lockdep.c:5668 [inline]
> lock_acquire+0x58c/0x9a0 kernel/locking/lockdep.c:5633
> __mutex_lock_common kernel/locking/mutex.c:603 [inline]
> __mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
> mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
> virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44
> nci_close_device+0x200/0x360 net/nfc/nci/core.c:592
> nci_unregister_device+0x40/0x280 net/nfc/nci/core.c:1291
> virtual_ncidev_close+0x70/0x90 drivers/nfc/virtual_ncidev.c:166
> __fput+0x1ac/0x860 fs/file_table.c:320
> ____fput+0x10/0x1c fs/file_table.c:348
> task_work_run+0x12c/0x220 kernel/task_work.c:179
> resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
> do_notify_resume+0x920/0x2840 arch/arm64/kernel/signal.c:1127
> prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
> exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
> el0_svc+0x11c/0x140 arch/arm64/kernel/entry-common.c:638
> el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
> el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581
>
> other info that might help us debug this:
>
> Chain exists of:
> nci_mutex --> &genl_data->genl_data_mutex --> &ndev->req_lock
>
> Possible unsafe locking scenario:
>
> CPU0 CPU1
> ---- ----
> lock(&ndev->req_lock);
> lock(&genl_data->genl_data_mutex);
> lock(&ndev->req_lock);
> lock(nci_mutex);
>
> *** DEADLOCK ***
>
> 1 lock held by syz-executor.1/8551:
> #0: ffff000030115350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560
>
> stack backtrace:
> CPU: 1 PID: 8551 Comm: syz-executor.1 Not tainted 6.1.0-rc4-syzkaller-00372-gaf7a05689189 #0
> Hardware name: linux,dummy-virt (DT)
> Call trace:
> dump_backtrace+0xe0/0x140 arch/arm64/kernel/stacktrace.c:156
> show_stack+0x18/0x40 arch/arm64/kernel/stacktrace.c:163
> __dump_stack lib/dump_stack.c:88 [inline]
> dump_stack_lvl+0x9c/0xd8 lib/dump_stack.c:106
> dump_stack+0x1c/0x38 lib/dump_stack.c:113
> print_circular_bug+0x2d4/0x2ec kernel/locking/lockdep.c:2055
> check_noncircular+0x26c/0x2e0 kernel/locking/lockdep.c:2177
> check_prev_add kernel/locking/lockdep.c:3097 [inline]
> check_prevs_add kernel/locking/lockdep.c:3216 [inline]
> validate_chain kernel/locking/lockdep.c:3831 [inline]
> __lock_acquire+0x2788/0x56d0 kernel/locking/lockdep.c:5055
> lock_acquire kernel/locking/lockdep.c:5668 [inline]
> lock_acquire+0x58c/0x9a0 kernel/locking/lockdep.c:5633
> __mutex_lock_common kernel/locking/mutex.c:603 [inline]
> __mutex_lock+0x124/0x83c kernel/locking/mutex.c:747
> mutex_lock_nested+0x2c/0x40 kernel/locking/mutex.c:799
> virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44
> nci_close_device+0x200/0x360 net/nfc/nci/core.c:592
> nci_unregister_device+0x40/0x280 net/nfc/nci/core.c:1291
> virtual_ncidev_close+0x70/0x90 drivers/nfc/virtual_ncidev.c:166
> __fput+0x1ac/0x860 fs/file_table.c:320
> ____fput+0x10/0x1c fs/file_table.c:348
> task_work_run+0x12c/0x220 kernel/task_work.c:179
> resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
> do_notify_resume+0x920/0x2840 arch/arm64/kernel/signal.c:1127
> prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
> exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
> el0_svc+0x11c/0x140 arch/arm64/kernel/entry-common.c:638
> el0t_64_sync_handler+0xb8/0xc0 arch/arm64/kernel/entry-common.c:655
> el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581
>
>
> ---
> 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 [email protected].
>
> syzbot will keep track of this issue. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
>
> --
> You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/000000000000cceef005ed659943%40google.com.

2022-11-14 15:24:24

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] possible deadlock in virtual_nci_close

syzbot has found a reproducer for the following issue on:

HEAD commit: 1621b6eaebf7 Merge branch 'for-next/fixes' into for-kernelci
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci
console output: https://syzkaller.appspot.com/x/log.txt?x=108bcd85880000
kernel config: https://syzkaller.appspot.com/x/.config?x=606e57fd25c5c6cc
dashboard link: https://syzkaller.appspot.com/bug?extid=8040d16d30c215f821de
compiler: Debian clang version 13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU Binutils for Debian) 2.35.2
userspace arch: arm64
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11b08dd1880000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14fcee02880000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/82aa7741098d/disk-1621b6ea.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/f6be08c4e4c2/vmlinux-1621b6ea.xz
kernel image: https://storage.googleapis.com/syzbot-assets/296b6946258a/Image-1621b6ea.gz.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email protected]

nci: nci_start_poll: failed to set local general bytes
nci: __nci_request: wait_for_completion_interruptible_timeout failed 0
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc4-syzkaller-31872-g1621b6eaebf7 #0 Not tainted
------------------------------------------------------
syz-executor424/3032 is trying to acquire lock:
ffff80000d5fac10 (nci_mutex){+.+.}-{3:3}, at: virtual_nci_close+0x28/0x58 drivers/nfc/virtual_ncidev.c:44

but task is already holding lock:
ffff0000cb900350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x74/0x2b4 net/nfc/nci/core.c:560

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&ndev->req_lock){+.+.}-{3:3}:
__mutex_lock_common+0xd4/0xca8 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
nci_request net/nfc/nci/core.c:148 [inline]
nci_set_local_general_bytes+0xbc/0x480 net/nfc/nci/core.c:774
nci_start_poll+0x1e8/0x474 net/nfc/nci/core.c:838
nfc_start_poll+0xfc/0x170 net/nfc/core.c:225
nfc_genl_start_poll+0xd4/0x174 net/nfc/netlink.c:828
genl_family_rcv_msg_doit net/netlink/genetlink.c:756 [inline]
genl_family_rcv_msg net/netlink/genetlink.c:833 [inline]
genl_rcv_msg+0x458/0x4f4 net/netlink/genetlink.c:850
netlink_rcv_skb+0xe8/0x1d4 net/netlink/af_netlink.c:2540
genl_rcv+0x38/0x50 net/netlink/genetlink.c:861
netlink_unicast_kernel+0xfc/0x1dc net/netlink/af_netlink.c:1319
netlink_unicast+0x164/0x248 net/netlink/af_netlink.c:1345
netlink_sendmsg+0x484/0x584 net/netlink/af_netlink.c:1921
sock_sendmsg_nosec net/socket.c:714 [inline]
sock_sendmsg net/socket.c:734 [inline]
____sys_sendmsg+0x2f8/0x440 net/socket.c:2482
___sys_sendmsg net/socket.c:2536 [inline]
__sys_sendmsg+0x1ac/0x228 net/socket.c:2565
__do_sys_sendmsg net/socket.c:2574 [inline]
__se_sys_sendmsg net/socket.c:2572 [inline]
__arm64_sys_sendmsg+0x2c/0x3c net/socket.c:2572
__invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
invoke_syscall arch/arm64/kernel/syscall.c:52 [inline]
el0_svc_common+0x138/0x220 arch/arm64/kernel/syscall.c:142
do_el0_svc+0x48/0x164 arch/arm64/kernel/syscall.c:206
el0_svc+0x58/0x150 arch/arm64/kernel/entry-common.c:637
el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:584

-> #2 (&genl_data->genl_data_mutex){+.+.}-{3:3}:
__mutex_lock_common+0xd4/0xca8 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
nfc_urelease_event_work+0x88/0x16c net/nfc/netlink.c:1811
process_one_work+0x2d8/0x504 kernel/workqueue.c:2289
worker_thread+0x340/0x610 kernel/workqueue.c:2436
kthread+0x12c/0x158 kernel/kthread.c:376
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:863

-> #1 (nfc_devlist_mutex){+.+.}-{3:3}:
__mutex_lock_common+0xd4/0xca8 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
nfc_register_device+0x34/0x208 net/nfc/core.c:1116
nci_register_device+0x338/0x3b0 net/nfc/nci/core.c:1256
virtual_ncidev_open+0x6c/0xd8 drivers/nfc/virtual_ncidev.c:146
misc_open+0x1b8/0x200 drivers/char/misc.c:143
chrdev_open+0x2b4/0x2e8 fs/char_dev.c:414
do_dentry_open+0x364/0x748 fs/open.c:882
vfs_open+0x38/0x48 fs/open.c:1013
do_open fs/namei.c:3557 [inline]
path_openat+0xe34/0x11c4 fs/namei.c:3713
do_filp_open+0xdc/0x1b8 fs/namei.c:3740
do_sys_openat2+0xb8/0x22c fs/open.c:1310
do_sys_open fs/open.c:1326 [inline]
__do_sys_openat fs/open.c:1342 [inline]
__se_sys_openat fs/open.c:1337 [inline]
__arm64_sys_openat+0xb0/0xe0 fs/open.c:1337
__invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
invoke_syscall arch/arm64/kernel/syscall.c:52 [inline]
el0_svc_common+0x138/0x220 arch/arm64/kernel/syscall.c:142
do_el0_svc+0x48/0x164 arch/arm64/kernel/syscall.c:206
el0_svc+0x58/0x150 arch/arm64/kernel/entry-common.c:637
el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:584

-> #0 (nci_mutex){+.+.}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3097 [inline]
check_prevs_add kernel/locking/lockdep.c:3216 [inline]
validate_chain kernel/locking/lockdep.c:3831 [inline]
__lock_acquire+0x1530/0x3084 kernel/locking/lockdep.c:5055
lock_acquire+0x100/0x1f8 kernel/locking/lockdep.c:5668
__mutex_lock_common+0xd4/0xca8 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
virtual_nci_close+0x28/0x58 drivers/nfc/virtual_ncidev.c:44
nci_close_device+0x188/0x2b4 net/nfc/nci/core.c:592
nci_unregister_device+0x3c/0x100 net/nfc/nci/core.c:1291
virtual_ncidev_close+0x70/0xb0 drivers/nfc/virtual_ncidev.c:166
__fput+0x198/0x3e4 fs/file_table.c:320
____fput+0x20/0x30 fs/file_table.c:348
task_work_run+0x100/0x148 kernel/task_work.c:179
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0x2dc/0xcac kernel/exit.c:820
do_group_exit+0x98/0xcc kernel/exit.c:950
get_signal+0xabc/0xb2c kernel/signal.c:2858
do_signal+0x128/0x438 arch/arm64/kernel/signal.c:1071
do_notify_resume+0xc0/0x1f0 arch/arm64/kernel/signal.c:1124
prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
el0_svc+0x9c/0x150 arch/arm64/kernel/entry-common.c:638
el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:584

other info that might help us debug this:

Chain exists of:
nci_mutex --> &genl_data->genl_data_mutex --> &ndev->req_lock

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&ndev->req_lock);
lock(&genl_data->genl_data_mutex);
lock(&ndev->req_lock);
lock(nci_mutex);

*** DEADLOCK ***

1 lock held by syz-executor424/3032:
#0: ffff0000cb900350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x74/0x2b4 net/nfc/nci/core.c:560

stack backtrace:
CPU: 0 PID: 3032 Comm: syz-executor424 Not tainted 6.1.0-rc4-syzkaller-31872-g1621b6eaebf7 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/30/2022
Call trace:
dump_backtrace+0x1c4/0x1f0 arch/arm64/kernel/stacktrace.c:156
show_stack+0x2c/0x54 arch/arm64/kernel/stacktrace.c:163
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x104/0x16c lib/dump_stack.c:106
dump_stack+0x1c/0x58 lib/dump_stack.c:113
print_circular_bug+0x2c4/0x2c8 kernel/locking/lockdep.c:2055
check_noncircular+0x14c/0x154 kernel/locking/lockdep.c:2177
check_prev_add kernel/locking/lockdep.c:3097 [inline]
check_prevs_add kernel/locking/lockdep.c:3216 [inline]
validate_chain kernel/locking/lockdep.c:3831 [inline]
__lock_acquire+0x1530/0x3084 kernel/locking/lockdep.c:5055
lock_acquire+0x100/0x1f8 kernel/locking/lockdep.c:5668
__mutex_lock_common+0xd4/0xca8 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
virtual_nci_close+0x28/0x58 drivers/nfc/virtual_ncidev.c:44
nci_close_device+0x188/0x2b4 net/nfc/nci/core.c:592
nci_unregister_device+0x3c/0x100 net/nfc/nci/core.c:1291
virtual_ncidev_close+0x70/0xb0 drivers/nfc/virtual_ncidev.c:166
__fput+0x198/0x3e4 fs/file_table.c:320
____fput+0x20/0x30 fs/file_table.c:348
task_work_run+0x100/0x148 kernel/task_work.c:179
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0x2dc/0xcac kernel/exit.c:820
do_group_exit+0x98/0xcc kernel/exit.c:950
get_signal+0xabc/0xb2c kernel/signal.c:2858
do_signal+0x128/0x438 arch/arm64/kernel/signal.c:1071
do_notify_resume+0xc0/0x1f0 arch/arm64/kernel/signal.c:1124
prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
el0_svc+0x9c/0x150 arch/arm64/kernel/entry-common.c:638
el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:584


2022-11-15 10:57:10

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] possible deadlock in virtual_nci_close

Hello,

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

Reported-and-tested-by: [email protected]

Tested on:

commit: 1621b6ea Merge branch 'for-next/fixes' into for-kernelci
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=120ddf69880000
kernel config: https://syzkaller.appspot.com/x/.config?x=9aff35d9bd592994
dashboard link: https://syzkaller.appspot.com/bug?extid=8040d16d30c215f821de
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=11685d35880000

Note: testing is done by a robot and is best-effort only.

2022-11-16 06:51:06

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] possible deadlock in virtual_nci_close

syzbot has bisected this issue to:

commit e624e6c3e777fb3dfed036b9da4d433aee3608a5
Author: Bongsu Jeon <[email protected]>
Date: Wed Jan 27 13:08:28 2021 +0000

nfc: Add a virtual nci device driver

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=1093fb59880000
start commit: 094226ad94f4 Linux 6.1-rc5
git tree: upstream
final oops: https://syzkaller.appspot.com/x/report.txt?x=1293fb59880000
console output: https://syzkaller.appspot.com/x/log.txt?x=1493fb59880000
kernel config: https://syzkaller.appspot.com/x/.config?x=7d516a992a8757b5
dashboard link: https://syzkaller.appspot.com/bug?extid=8040d16d30c215f821de
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1360e2f1880000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14a95659880000

Reported-by: [email protected]
Fixes: e624e6c3e777 ("nfc: Add a virtual nci device driver")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

2022-11-22 13:24:24

by Dmitry Vyukov

[permalink] [raw]
Subject: Re: [syzbot] possible deadlock in virtual_nci_close

On Wed, 16 Nov 2022 at 06:58, syzbot
<[email protected]> wrote:
>
> syzbot has bisected this issue to:
>
> commit e624e6c3e777fb3dfed036b9da4d433aee3608a5
> Author: Bongsu Jeon <[email protected]>
> Date: Wed Jan 27 13:08:28 2021 +0000
>
> nfc: Add a virtual nci device driver
>
> bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=1093fb59880000
> start commit: 094226ad94f4 Linux 6.1-rc5
> git tree: upstream
> final oops: https://syzkaller.appspot.com/x/report.txt?x=1293fb59880000
> console output: https://syzkaller.appspot.com/x/log.txt?x=1493fb59880000
> kernel config: https://syzkaller.appspot.com/x/.config?x=7d516a992a8757b5
> dashboard link: https://syzkaller.appspot.com/bug?extid=8040d16d30c215f821de
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1360e2f1880000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14a95659880000
>
> Reported-by: [email protected]
> Fixes: e624e6c3e777 ("nfc: Add a virtual nci device driver")
>
> For information about bisection process see: https://goo.gl/tpsmEJ#bisection

#syz fix: NFC: nci: Allow to create multiple virtual nci devices