syzbot


possible deadlock in nci_close_device

Status: fixed on 2023/02/24 13:50
Subsystems: net nfc
[Documentation on labels]
Fix commit: b2e44aac91b2 NFC: nci: Allow to create multiple virtual nci devices
First crash: 713d, last: 699d
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-6.1 possible deadlock in nci_close_device 1 215d 215d 0/3 auto-obsoleted due to no activity on 2024/07/12 04:08
linux-5.15 possible deadlock in nci_close_device 1 393d 393d 0/3 auto-obsoleted due to no activity on 2024/01/16 04:06

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc8-syzkaller-00003-gbce9332220bd #0 Not tainted
------------------------------------------------------
syz-executor.1/6911 is trying to acquire lock:
ffff000015dce350 (&ndev->req_lock){+.+.}-{3:3}, at: nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560

but task is already holding lock:
ffff80000f4789c8 (rfkill_global_mutex){+.+.}-{3:3}, at: rfkill_fop_write+0x12c/0x4cc net/rfkill/core.c:1278

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (rfkill_global_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
       rfkill_register+0x44/0x860 net/rfkill/core.c:1057
       nfc_register_device+0xec/0x320 net/nfc/core.c:1132
       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:3714
       do_filp_open+0x154/0x330 fs/namei.c:3741
       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

-> #1 (nci_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
       virtual_nci_close+0x2c/0x60 drivers/nfc/virtual_ncidev.c:44
       nci_open_device net/nfc/nci/core.c:544 [inline]
       nci_dev_up+0x41c/0x520 net/nfc/nci/core.c:631
       nfc_dev_up+0x11c/0x2b4 net/nfc/core.c:118
       nfc_genl_dev_up+0x88/0xe0 net/nfc/netlink.c:770
       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

-> #0 (&ndev->req_lock){+.+.}-{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
       nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560
       nci_dev_down+0x34/0x50 net/nfc/nci/core.c:638
       nfc_dev_down+0x114/0x23c net/nfc/core.c:161
       nfc_rfkill_set_block+0x28/0xc0 net/nfc/core.c:179
       rfkill_set_block+0x160/0x3c4 net/rfkill/core.c:345
       rfkill_fop_write+0x214/0x4cc net/rfkill/core.c:1286
       vfs_write+0x1bc/0x740 fs/read_write.c:582
       ksys_write+0x188/0x1d0 fs/read_write.c:637
       __do_sys_write fs/read_write.c:649 [inline]
       __se_sys_write fs/read_write.c:646 [inline]
       __arm64_sys_write+0x6c/0xa0 fs/read_write.c:646
       __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

other info that might help us debug this:

Chain exists of:
  &ndev->req_lock --> nci_mutex --> rfkill_global_mutex

 Possible unsafe locking scenario:

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

 *** DEADLOCK ***

2 locks held by syz-executor.1/6911:
 #0: ffff80000f4789c8 (rfkill_global_mutex){+.+.}-{3:3}, at: rfkill_fop_write+0x12c/0x4cc net/rfkill/core.c:1278
 #1: ffff000015dcc100 (&dev->mutex){....}-{3:3}, at: device_lock include/linux/device.h:835 [inline]
 #1: ffff000015dcc100 (&dev->mutex){....}-{3:3}, at: nfc_dev_down+0x2c/0x23c net/nfc/core.c:143

stack backtrace:
CPU: 1 PID: 6911 Comm: syz-executor.1 Not tainted 6.1.0-rc8-syzkaller-00003-gbce9332220bd #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
 nci_close_device+0x5c/0x360 net/nfc/nci/core.c:560
 nci_dev_down+0x34/0x50 net/nfc/nci/core.c:638
 nfc_dev_down+0x114/0x23c net/nfc/core.c:161
 nfc_rfkill_set_block+0x28/0xc0 net/nfc/core.c:179
 rfkill_set_block+0x160/0x3c4 net/rfkill/core.c:345
 rfkill_fop_write+0x214/0x4cc net/rfkill/core.c:1286
 vfs_write+0x1bc/0x740 fs/read_write.c:582
 ksys_write+0x188/0x1d0 fs/read_write.c:637
 __do_sys_write fs/read_write.c:649 [inline]
 __se_sys_write fs/read_write.c:646 [inline]
 __arm64_sys_write+0x6c/0xa0 fs/read_write.c:646
 __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

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/12/06 08:48 upstream bce9332220bd 045cbb84 .config console log report info ci-qemu2-arm64 possible deadlock in nci_close_device
2022/11/22 12:04 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a77d28d13789 1c576c23 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in nci_close_device
* Struck through repros no longer work on HEAD.