nci: __nci_request: wait_for_completion_interruptible_timeout failed 0
======================================================
WARNING: possible circular locking dependency detected
6.1.32-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor346/3551 is trying to acquire lock:
ffffffff8d7cd688 (nci_mutex){+.+.}-{3:3}, at: virtual_nci_close+0x13/0x40 drivers/nfc/virtual_ncidev.c:44

but task is already holding lock:
ffff888020dfd350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x106/0x5f0 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}:
       lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5669
       __mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 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+0x59f/0xf20 net/nfc/nci/core.c:838
       nfc_start_poll+0x184/0x2f0 net/nfc/core.c:225
       nfc_genl_start_poll+0x1e7/0x350 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+0xc1a/0xf70 net/netlink/genetlink.c:850
       netlink_rcv_skb+0x1cd/0x410 net/netlink/af_netlink.c:2524
       genl_rcv+0x24/0x40 net/netlink/genetlink.c:861
       netlink_unicast_kernel net/netlink/af_netlink.c:1328 [inline]
       netlink_unicast+0x7bf/0x990 net/netlink/af_netlink.c:1354
       netlink_sendmsg+0xa26/0xd60 net/netlink/af_netlink.c:1902
       sock_sendmsg_nosec net/socket.c:716 [inline]
       sock_sendmsg net/socket.c:736 [inline]
       ____sys_sendmsg+0x59e/0x8f0 net/socket.c:2482
       ___sys_sendmsg net/socket.c:2536 [inline]
       __sys_sendmsg+0x2a9/0x390 net/socket.c:2565
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #2 (&genl_data->genl_data_mutex){+.+.}-{3:3}:
       lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5669
       __mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       nfc_urelease_event_work+0x113/0x2f0 net/nfc/netlink.c:1839
       process_one_work+0x8aa/0x11f0 kernel/workqueue.c:2289
       worker_thread+0xa5f/0x1210 kernel/workqueue.c:2436
       kthread+0x26e/0x300 kernel/kthread.c:376
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

-> #1 (nfc_devlist_mutex){+.+.}-{3:3}:
       lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5669
       __mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       nfc_register_device+0x38/0x310 net/nfc/core.c:1116
       nci_register_device+0x7be/0x900 net/nfc/nci/core.c:1256
       virtual_ncidev_open+0x55/0xc0 drivers/nfc/virtual_ncidev.c:146
       misc_open+0x304/0x380 drivers/char/misc.c:143
       chrdev_open+0x54a/0x630 fs/char_dev.c:414
       do_dentry_open+0x7f9/0x10f0 fs/open.c:882
       do_open fs/namei.c:3557 [inline]
       path_openat+0x2644/0x2e60 fs/namei.c:3714
       do_filp_open+0x230/0x480 fs/namei.c:3741
       do_sys_openat2+0x13b/0x500 fs/open.c:1318
       do_sys_open fs/open.c:1334 [inline]
       __do_sys_openat fs/open.c:1350 [inline]
       __se_sys_openat fs/open.c:1345 [inline]
       __x64_sys_openat+0x243/0x290 fs/open.c:1345
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (nci_mutex){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3098 [inline]
       check_prevs_add kernel/locking/lockdep.c:3217 [inline]
       validate_chain+0x1667/0x58e0 kernel/locking/lockdep.c:3832
       __lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5056
       lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5669
       __mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       virtual_nci_close+0x13/0x40 drivers/nfc/virtual_ncidev.c:44
       nci_close_device+0x3a8/0x5f0 net/nfc/nci/core.c:592
       nci_unregister_device+0x3c/0x230 net/nfc/nci/core.c:1291
       virtual_ncidev_close+0x55/0x90 drivers/nfc/virtual_ncidev.c:166
       __fput+0x3b7/0x890 fs/file_table.c:320
       task_work_run+0x246/0x300 kernel/task_work.c:179
       resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
       exit_to_user_mode_loop+0xd9/0x100 kernel/entry/common.c:171
       exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:204
       __syscall_exit_to_user_mode_work kernel/entry/common.c:286 [inline]
       syscall_exit_to_user_mode+0x60/0x270 kernel/entry/common.c:297
       do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

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-executor346/3551:
 #0: ffff888020dfd350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x106/0x5f0 net/nfc/nci/core.c:560

stack backtrace:
CPU: 1 PID: 3551 Comm: syz-executor346 Not tainted 6.1.32-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/25/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
 check_noncircular+0x2fa/0x3b0 kernel/locking/lockdep.c:2178
 check_prev_add kernel/locking/lockdep.c:3098 [inline]
 check_prevs_add kernel/locking/lockdep.c:3217 [inline]
 validate_chain+0x1667/0x58e0 kernel/locking/lockdep.c:3832
 __lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5056
 lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5669
 __mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
 __mutex_lock kernel/locking/mutex.c:747 [inline]
 mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
 virtual_nci_close+0x13/0x40 drivers/nfc/virtual_ncidev.c:44
 nci_close_device+0x3a8/0x5f0 net/nfc/nci/core.c:592
 nci_unregister_device+0x3c/0x230 net/nfc/nci/core.c:1291
 virtual_ncidev_close+0x55/0x90 drivers/nfc/virtual_ncidev.c:166
 __fput+0x3b7/0x890 fs/file_table.c:320
 task_work_run+0x246/0x300 kernel/task_work.c:179
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop+0xd9/0x100 kernel/entry/common.c:171
 exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:204
 __syscall_exit_to_user_mode_work kernel/entry/common.c:286 [inline]
 syscall_exit_to_user_mode+0x60/0x270 kernel/entry/common.c:297
 do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f72dec890bb
Code: 0f 05 48 3d 00 f0 ff ff 77 45 c3 0f 1f 40 00 48 83 ec 18 89 7c 24 0c e8 63 fc ff ff 8b 7c 24 0c 41 89 c0 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 35 44 89 c7 89 44 24 0c e8 a1 fc ff ff 8b 44
RSP: 002b:00007ffc07a05bb0 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000004 RCX: 00007f72dec890bb
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 0000000000000032 R08: 0000000000000000 R09: 0000000000000010
R10: 0000000000000000 R11: 0000000000000293 R12: 0000000000000009
R13: 00007ffc07a05c20 R14: 00007ffc07a05cc0 R15: 00007f72ded514fc
 </TASK>