syzbot


possible deadlock in nbd_open

Status: upstream: reported C repro on 2022/11/24 00:35
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+1499b08ad22121686f59@syzkaller.appspotmail.com
First crash: 743d, last: 640d

Sample crash report:
block nbd1: shutting down sockets
block nbd0: shutting down sockets
block nbd4: shutting down sockets
block nbd2: shutting down sockets
======================================================
WARNING: possible circular locking dependency detected
4.19.211-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor228/8129 is trying to acquire lock:
00000000da7025a4 ((wq_completion)"knbd%d-recv"nbd->index){+.+.}, at: flush_workqueue+0xe8/0x13e0 kernel/workqueue.c:2658

but task is already holding lock:
000000003a5537cb (&nbd->config_lock){+.+.}, at: refcount_dec_and_mutex_lock lib/refcount.c:311 [inline]
000000003a5537cb (&nbd->config_lock){+.+.}, at: refcount_dec_and_mutex_lock+0x4a/0x80 lib/refcount.c:306

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #10 (&nbd->config_lock){+.+.}:
       nbd_open+0x2e2/0x6f0 drivers/block/nbd.c:1428
       __blkdev_get+0x372/0x1480 fs/block_dev.c:1494
       blkdev_get+0xb0/0x940 fs/block_dev.c:1627
       blkdev_open+0x202/0x290 fs/block_dev.c:1788
       do_dentry_open+0x4aa/0x1160 fs/open.c:796
       do_last fs/namei.c:3421 [inline]
       path_openat+0x793/0x2df0 fs/namei.c:3537
       do_filp_open+0x18c/0x3f0 fs/namei.c:3567
       do_sys_open+0x3b3/0x520 fs/open.c:1085
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #9 (nbd_index_mutex){+.+.}:
       nbd_open+0x73/0x6f0 drivers/block/nbd.c:1415
       __blkdev_get+0x372/0x1480 fs/block_dev.c:1494
       blkdev_get+0xb0/0x940 fs/block_dev.c:1627
       blkdev_open+0x202/0x290 fs/block_dev.c:1788
       do_dentry_open+0x4aa/0x1160 fs/open.c:796
       do_last fs/namei.c:3421 [inline]
       path_openat+0x793/0x2df0 fs/namei.c:3537
       do_filp_open+0x18c/0x3f0 fs/namei.c:3567
       do_sys_open+0x3b3/0x520 fs/open.c:1085
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #8 (&bdev->bd_mutex){+.+.}:
       blkdev_put+0x30/0x520 fs/block_dev.c:1839
       btrfs_close_bdev fs/btrfs/volumes.c:1033 [inline]
       btrfs_close_one_device fs/btrfs/volumes.c:1057 [inline]
       close_fs_devices.part.0+0x24d/0x8e0 fs/btrfs/volumes.c:1085
       close_fs_devices fs/btrfs/volumes.c:1117 [inline]
       btrfs_close_devices+0x95/0x1f0 fs/btrfs/volumes.c:1103
       close_ctree+0x3c8/0x850 fs/btrfs/disk-io.c:4047
       generic_shutdown_super+0x144/0x370 fs/super.c:456
       kill_anon_super+0x36/0x60 fs/super.c:1032
       btrfs_kill_super+0x49/0x550 fs/btrfs/super.c:2221
       deactivate_locked_super+0x94/0x160 fs/super.c:329
       deactivate_super+0x174/0x1a0 fs/super.c:360
       cleanup_mnt+0x1a8/0x290 fs/namespace.c:1098
       task_work_run+0x148/0x1c0 kernel/task_work.c:113
       tracehook_notify_resume include/linux/tracehook.h:193 [inline]
       exit_to_usermode_loop+0x251/0x2a0 arch/x86/entry/common.c:167
       prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
       syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
       do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #7 (&fs_devs->device_list_mutex){+.+.}:
       btrfs_run_dev_stats+0xbb/0xa80 fs/btrfs/volumes.c:7111
       commit_cowonly_roots+0x1ce/0xc30 fs/btrfs/transaction.c:1172
       btrfs_commit_transaction+0x94a/0x2480 fs/btrfs/transaction.c:2218
       btrfs_clear_free_space_tree+0x69d/0xa50 fs/btrfs/free-space-tree.c:1255
       open_ctree.cold+0x30/0xc3d fs/btrfs/disk-io.c:3203
       btrfs_fill_super fs/btrfs/super.c:1209 [inline]
       btrfs_mount_root+0x12e5/0x1830 fs/btrfs/super.c:1613
       mount_fs+0xa3/0x310 fs/super.c:1261
       vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
       vfs_kern_mount+0x3c/0x60 fs/namespace.c:951
       btrfs_mount+0x23a/0xaa0 fs/btrfs/super.c:1681
       mount_fs+0xa3/0x310 fs/super.c:1261
       vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
       vfs_kern_mount fs/namespace.c:951 [inline]
       do_new_mount fs/namespace.c:2492 [inline]
       do_mount+0x115c/0x2f50 fs/namespace.c:2822
       ksys_mount+0xcf/0x130 fs/namespace.c:3038
       __do_sys_mount fs/namespace.c:3052 [inline]
       __se_sys_mount fs/namespace.c:3049 [inline]
       __x64_sys_mount+0xba/0x150 fs/namespace.c:3049
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #6 (&fs_info->tree_log_mutex){+.+.}:
       btrfs_commit_transaction+0x8c2/0x2480 fs/btrfs/transaction.c:2176
       btrfs_clear_free_space_tree+0x69d/0xa50 fs/btrfs/free-space-tree.c:1255
       open_ctree.cold+0x30/0xc3d fs/btrfs/disk-io.c:3203
       btrfs_fill_super fs/btrfs/super.c:1209 [inline]
       btrfs_mount_root+0x12e5/0x1830 fs/btrfs/super.c:1613
       mount_fs+0xa3/0x310 fs/super.c:1261
       vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
       vfs_kern_mount+0x3c/0x60 fs/namespace.c:951
       btrfs_mount+0x23a/0xaa0 fs/btrfs/super.c:1681
       mount_fs+0xa3/0x310 fs/super.c:1261
       vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
       vfs_kern_mount fs/namespace.c:951 [inline]
       do_new_mount fs/namespace.c:2492 [inline]
       do_mount+0x115c/0x2f50 fs/namespace.c:2822
       ksys_mount+0xcf/0x130 fs/namespace.c:3038
       __do_sys_mount fs/namespace.c:3052 [inline]
       __se_sys_mount fs/namespace.c:3049 [inline]
       __x64_sys_mount+0xba/0x150 fs/namespace.c:3049
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #5 (&fs_info->reloc_mutex){+.+.}:
       btrfs_commit_transaction+0x80b/0x2480 fs/btrfs/transaction.c:2120
       btrfs_clear_free_space_tree+0x69d/0xa50 fs/btrfs/free-space-tree.c:1255
       open_ctree.cold+0x30/0xc3d fs/btrfs/disk-io.c:3203
       btrfs_fill_super fs/btrfs/super.c:1209 [inline]
       btrfs_mount_root+0x12e5/0x1830 fs/btrfs/super.c:1613
       mount_fs+0xa3/0x310 fs/super.c:1261
       vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
       vfs_kern_mount+0x3c/0x60 fs/namespace.c:951
       btrfs_mount+0x23a/0xaa0 fs/btrfs/super.c:1681
       mount_fs+0xa3/0x310 fs/super.c:1261
       vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
       vfs_kern_mount fs/namespace.c:951 [inline]
       do_new_mount fs/namespace.c:2492 [inline]
       do_mount+0x115c/0x2f50 fs/namespace.c:2822
       ksys_mount+0xcf/0x130 fs/namespace.c:3038
       __do_sys_mount fs/namespace.c:3052 [inline]
       __se_sys_mount fs/namespace.c:3049 [inline]
       __x64_sys_mount+0xba/0x150 fs/namespace.c:3049
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #4 (sb_internal#2){.+.+}:
       sb_start_intwrite include/linux/fs.h:1626 [inline]
       start_transaction+0xa37/0xf90 fs/btrfs/transaction.c:528
       btrfs_dirty_inode+0xe3/0x210 fs/btrfs/inode.c:6165
       btrfs_update_time+0x33b/0x3d0 fs/btrfs/inode.c:6207
       update_time fs/inode.c:1675 [inline]
       touch_atime+0x23c/0x2a0 fs/inode.c:1746
       file_accessed include/linux/fs.h:2123 [inline]
       btrfs_file_mmap+0x11b/0x160 fs/btrfs/file.c:2274
       call_mmap include/linux/fs.h:1826 [inline]
       mmap_region+0xc94/0x16b0 mm/mmap.c:1757
       do_mmap+0x8e8/0x1080 mm/mmap.c:1530
       do_mmap_pgoff include/linux/mm.h:2329 [inline]
       vm_mmap_pgoff+0x197/0x200 mm/util.c:357
       ksys_mmap_pgoff+0x298/0x5a0 mm/mmap.c:1580
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #3 (&mm->mmap_sem){++++}:
       _copy_to_iter+0x3d0/0xea0 lib/iov_iter.c:564
       copy_to_iter include/linux/uio.h:106 [inline]
       skb_copy_datagram_iter+0x469/0x9e0 net/core/datagram.c:431
       skb_copy_datagram_msg include/linux/skbuff.h:3347 [inline]
       unix_stream_read_actor+0x78/0xc0 net/unix/af_unix.c:2489
       unix_stream_read_generic+0x8b9/0x1a40 net/unix/af_unix.c:2410
       unix_stream_recvmsg+0xb1/0xf0 net/unix/af_unix.c:2505
       sock_recvmsg_nosec net/socket.c:859 [inline]
       sock_recvmsg net/socket.c:866 [inline]
       sock_recvmsg net/socket.c:862 [inline]
       sock_read_iter+0x339/0x470 net/socket.c:944
       call_read_iter include/linux/fs.h:1815 [inline]
       new_sync_read fs/read_write.c:406 [inline]
       __vfs_read+0x518/0x750 fs/read_write.c:418
       vfs_read+0x194/0x3c0 fs/read_write.c:452
       ksys_read+0x12b/0x2a0 fs/read_write.c:579
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #2 (&u->iolock){+.+.}:
       unix_stream_read_generic+0x2de/0x1a40 net/unix/af_unix.c:2322
       unix_stream_recvmsg+0xb1/0xf0 net/unix/af_unix.c:2505
       sock_recvmsg_nosec net/socket.c:859 [inline]
       sock_recvmsg net/socket.c:866 [inline]
       sock_recvmsg+0xca/0x110 net/socket.c:862
       sock_xmit+0x37d/0x5c0 drivers/block/nbd.c:439
       nbd_read_stat drivers/block/nbd.c:633 [inline]
       recv_work+0x1e9/0x1100 drivers/block/nbd.c:732
       process_one_work+0x864/0x1570 kernel/workqueue.c:2153
       worker_thread+0x64c/0x1130 kernel/workqueue.c:2296
       kthread+0x33f/0x460 kernel/kthread.c:259
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:415

-> #1 ((work_completion)(&args->work)){+.+.}:
       worker_thread+0x64c/0x1130 kernel/workqueue.c:2296
       kthread+0x33f/0x460 kernel/kthread.c:259
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:415

-> #0 ((wq_completion)"knbd%d-recv"nbd->index){+.+.}:
       flush_workqueue+0x117/0x13e0 kernel/workqueue.c:2661
       drain_workqueue+0x1a5/0x460 kernel/workqueue.c:2826
       destroy_workqueue+0x75/0x790 kernel/workqueue.c:4183
       nbd_config_put+0x3c5/0x870 drivers/block/nbd.c:1175
       nbd_release+0xf4/0x170 drivers/block/nbd.c:1461
       __blkdev_put+0x636/0x870 fs/block_dev.c:1819
       blkdev_close+0x86/0xb0 fs/block_dev.c:1888
       __fput+0x2ce/0x890 fs/file_table.c:278
       task_work_run+0x148/0x1c0 kernel/task_work.c:113
       exit_task_work include/linux/task_work.h:22 [inline]
       do_exit+0xbf3/0x2be0 kernel/exit.c:870
       do_group_exit+0x125/0x310 kernel/exit.c:967
       get_signal+0x3f2/0x1f70 kernel/signal.c:2589
       do_signal+0x8f/0x1670 arch/x86/kernel/signal.c:799
       exit_to_usermode_loop+0x204/0x2a0 arch/x86/entry/common.c:163
       prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
       syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
       do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

Chain exists of:
  (wq_completion)"knbd%d-recv"nbd->index --> nbd_index_mutex --> &nbd->config_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&nbd->config_lock);
                               lock(nbd_index_mutex);
                               lock(&nbd->config_lock);
  lock((wq_completion)"knbd%d-recv"nbd->index);

 *** DEADLOCK ***

2 locks held by syz-executor228/8129:
 #0: 000000001d3ce4bb (&bdev->bd_mutex){+.+.}, at: __blkdev_put+0xfc/0x870 fs/block_dev.c:1806
 #1: 000000003a5537cb (&nbd->config_lock){+.+.}, at: refcount_dec_and_mutex_lock lib/refcount.c:311 [inline]
 #1: 000000003a5537cb (&nbd->config_lock){+.+.}, at: refcount_dec_and_mutex_lock+0x4a/0x80 lib/refcount.c:306

stack backtrace:
CPU: 1 PID: 8129 Comm: syz-executor228 Not tainted 4.19.211-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1fc/0x2ef lib/dump_stack.c:118
 print_circular_bug.constprop.0.cold+0x2d7/0x41e kernel/locking/lockdep.c:1222
 check_prev_add kernel/locking/lockdep.c:1866 [inline]
 check_prevs_add kernel/locking/lockdep.c:1979 [inline]
 validate_chain kernel/locking/lockdep.c:2420 [inline]
 __lock_acquire+0x30c9/0x3ff0 kernel/locking/lockdep.c:3416
 lock_acquire+0x170/0x3c0 kernel/locking/lockdep.c:3908
 flush_workqueue+0x117/0x13e0 kernel/workqueue.c:2661
 drain_workqueue+0x1a5/0x460 kernel/workqueue.c:2826
 destroy_workqueue+0x75/0x790 kernel/workqueue.c:4183
 nbd_config_put+0x3c5/0x870 drivers/block/nbd.c:1175
 nbd_release+0xf4/0x170 drivers/block/nbd.c:1461
 __blkdev_put+0x636/0x870 fs/block_dev.c:1819
 blkdev_close+0x86/0xb0 fs/block_dev.c:1888
 __fput+0x2ce/0x890 fs/file_table.c:278
 task_work_run+0x148/0x1c0 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
 do_exit+0xbf3/0x2be0 kernel/exit.c:870
 do_group_exit+0x125/0x310 kernel/exit.c:967
 get_signal+0x3f2/0x1f70 kernel/signal.c:2589
 do_signal+0x8f/0x1670 arch/x86/kernel/signal.c:799
 exit_to_usermode_loop+0x204/0x2a0 arch/x86/entry/common.c:163
 prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
 do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f64923ffc99
Code: Bad RIP value.
RSP: 002b:00007fffe684ab58 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: fffffffffffffe00 RBX: 0000000000000000 RCX: 00007f64923ffc99
RDX: 0000000000000000 RSI: 000000000000ab03 RDI: 0000000000000004
RBP: 0000000000000000 R08: 00007fffe684ab80 R09: 00007fffe684ab80
R10: 00007fffe684ab80 R11: 0000000000000246 R12: 00007f64923beab0
R13: 00007fffe684abb0 R14: 00007fffe684ab90 R15: 0000000000000000
BTRFS warning (device <unknown>): duplicate device /dev/loop3 devid 1 generation 8 scanned by syz-executor228 (8670)
btrfs_printk: 26 callbacks suppressed
BTRFS info (device loop1): enabling inode map caching
BTRFS warning (device <unknown>): duplicate device /dev/loop3 devid 1 generation 8 scanned by systemd-udevd (8680)
BTRFS info (device loop1): force clearing of disk cache
BTRFS warning (device <unknown>): duplicate device /dev/loop4 devid 1 generation 8 scanned by syz-executor228 (8686)
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS warning (device <unknown>): duplicate device /dev/loop0 devid 1 generation 8 scanned by syz-executor228 (8682)
BTRFS warning (device <unknown>): duplicate device /dev/loop0 devid 1 generation 8 scanned by systemd-udevd (8677)
BTRFS warning (device <unknown>): duplicate device /dev/loop4 devid 1 generation 8 scanned by systemd-udevd (8692)
BTRFS warning (device <unknown>): duplicate device /dev/loop5 devid 1 generation 8 scanned by systemd-udevd (8708)
BTRFS warning (device <unknown>): duplicate device /dev/loop2 devid 1 generation 8 scanned by syz-executor228 (8685)
BTRFS warning (device <unknown>): duplicate device /dev/loop2 devid 1 generation 8 scanned by systemd-udevd (8699)
BTRFS warning (device <unknown>): duplicate device /dev/loop5 devid 1 generation 8 scanned by syz-executor228 (8684)
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
BTRFS info (device loop1): force clearing of disk cache
BTRFS info (device loop1): disabling free space tree
BTRFS info (device loop1): setting 8 feature flag
BTRFS info (device loop1): use lzo compression, level 0
BTRFS info (device loop1): has skinny extents
BTRFS info (device loop1): clearing free space tree
BTRFS info (device loop1): clearing 1 ro feature flag
BTRFS info (device loop1): clearing 2 ro feature flag
BTRFS info (device loop1): enabling inode map caching
block nbd3: shutting down sockets
==================================================================
BUG: KASAN: use-after-free in btrfs_search_slot+0x1cca/0x1ee0 fs/btrfs/ctree.c:2793
Read of size 8 at addr ffff8880abe0c770 by task btrfs-ino-cache/9337

CPU: 0 PID: 9337 Comm: btrfs-ino-cache Not tainted 4.19.211-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1fc/0x2ef lib/dump_stack.c:118
 print_address_description.cold+0x54/0x219 mm/kasan/report.c:256
 kasan_report_error.cold+0x8a/0x1b9 mm/kasan/report.c:354
 kasan_report mm/kasan/report.c:412 [inline]
 __asan_report_load8_noabort+0x88/0x90 mm/kasan/report.c:433
 btrfs_search_slot+0x1cca/0x1ee0 fs/btrfs/ctree.c:2793
 caching_kthread+0x275/0x970 fs/btrfs/inode-map.c:61
 kthread+0x33f/0x460 kernel/kthread.c:259
 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:415

Allocated by task 9306:
 kmem_cache_alloc_trace+0x12f/0x380 mm/slab.c:3625
 kmalloc include/linux/slab.h:515 [inline]
 kzalloc include/linux/slab.h:709 [inline]
 btrfs_alloc_root fs/btrfs/disk-io.c:1220 [inline]
 btrfs_read_tree_root+0x94/0x560 fs/btrfs/disk-io.c:1421
 btrfs_read_fs_root fs/btrfs/disk-io.c:1467 [inline]
 btrfs_get_fs_root+0x239/0x890 fs/btrfs/disk-io.c:1601
 btrfs_read_fs_root_no_name fs/btrfs/disk-io.h:80 [inline]
 open_ctree+0x469c/0x61e0 fs/btrfs/disk-io.c:3181
 btrfs_fill_super fs/btrfs/super.c:1209 [inline]
 btrfs_mount_root+0x12e5/0x1830 fs/btrfs/super.c:1613
 mount_fs+0xa3/0x310 fs/super.c:1261
 vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
 vfs_kern_mount+0x3c/0x60 fs/namespace.c:951
 btrfs_mount+0x23a/0xaa0 fs/btrfs/super.c:1681
 mount_fs+0xa3/0x310 fs/super.c:1261
 vfs_kern_mount.part.0+0x68/0x470 fs/namespace.c:961
 vfs_kern_mount fs/namespace.c:951 [inline]
 do_new_mount fs/namespace.c:2492 [inline]
 do_mount+0x115c/0x2f50 fs/namespace.c:2822
 ksys_mount+0xcf/0x130 fs/namespace.c:3038
 __do_sys_mount fs/namespace.c:3052 [inline]
 __se_sys_mount fs/namespace.c:3049 [inline]
 __x64_sys_mount+0xba/0x150 fs/namespace.c:3049
 do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 8123:
 __cache_free mm/slab.c:3503 [inline]
 kfree+0xcc/0x210 mm/slab.c:3822
 btrfs_put_fs_root fs/btrfs/disk-io.h:111 [inline]
 btrfs_free_fs_root+0x1e6/0x260 fs/btrfs/disk-io.c:3861
 btrfs_free_fs_roots+0x2ef/0x4d0 fs/btrfs/disk-io.c:2092
 close_ctree+0x306/0x850 fs/btrfs/disk-io.c:4017
 generic_shutdown_super+0x144/0x370 fs/super.c:456
 kill_anon_super+0x36/0x60 fs/super.c:1032
 btrfs_kill_super+0x49/0x550 fs/btrfs/super.c:2221
 deactivate_locked_super+0x94/0x160 fs/super.c:329
 deactivate_super+0x174/0x1a0 fs/super.c:360
 cleanup_mnt+0x1a8/0x290 fs/namespace.c:1098
 task_work_run+0x148/0x1c0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:193 [inline]
 exit_to_usermode_loop+0x251/0x2a0 arch/x86/entry/common.c:167
 prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
 do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff8880abe0c580
 which belongs to the cache kmalloc-4096 of size 4096
The buggy address is located 496 bytes inside of
 4096-byte region [ffff8880abe0c580, ffff8880abe0d580)
The buggy address belongs to the page:
page:ffffea0002af8300 count:1 mapcount:0 mapping:ffff88813bff0dc0 index:0x0 compound_mapcount: 0
flags: 0xfff00000008100(slab|head)
raw: 00fff00000008100 ffffea000251f888 ffffea000254dd08 ffff88813bff0dc0
raw: 0000000000000000 ffff8880abe0c580 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8880abe0c600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880abe0c680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880abe0c700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                             ^
 ffff8880abe0c780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880abe0c800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (26):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/01/07 15:01 linux-4.19.y 3f8a27f9e27b 1dac8c7a .config console log report syz C [disk image] [vmlinux] [mounted in repro] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/04 13:15 linux-4.19.y 3f8a27f9e27b e080de16 .config console log report syz [disk image] [vmlinux] [mounted in repro] ci2-linux-4-19 possible deadlock in nbd_open
2023/03/07 00:29 linux-4.19.y 3f8a27f9e27b f8902b57 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/03/06 06:25 linux-4.19.y 3f8a27f9e27b f8902b57 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/02/20 12:46 linux-4.19.y 3f8a27f9e27b bcdf85f8 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/02/16 19:40 linux-4.19.y 3f8a27f9e27b 38b317a7 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/02/15 11:34 linux-4.19.y 3f8a27f9e27b e62ba3c1 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/02/10 07:38 linux-4.19.y 3f8a27f9e27b 07980f9d .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/02/08 03:56 linux-4.19.y 3f8a27f9e27b 15c3d445 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/02/01 07:49 linux-4.19.y 3f8a27f9e27b b68fb8d6 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/01/31 10:32 linux-4.19.y 3f8a27f9e27b b68fb8d6 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/01/29 19:14 linux-4.19.y 3f8a27f9e27b 9dfcf09c .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/01/09 14:18 linux-4.19.y 3f8a27f9e27b 1dac8c7a .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/01/09 05:54 linux-4.19.y 3f8a27f9e27b 1dac8c7a .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/01/07 14:15 linux-4.19.y 3f8a27f9e27b 1dac8c7a .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2023/01/04 06:10 linux-4.19.y 3f8a27f9e27b f0036e18 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/30 11:29 linux-4.19.y 3f8a27f9e27b 44712fbc .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/26 13:06 linux-4.19.y 3f8a27f9e27b 9da18ae8 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/11 15:32 linux-4.19.y 3f8a27f9e27b 67be1ae7 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/11 10:11 linux-4.19.y 3f8a27f9e27b 67be1ae7 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/09 15:44 linux-4.19.y 3f8a27f9e27b 67be1ae7 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/08 02:53 linux-4.19.y 3f8a27f9e27b d88f3abb .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/05 13:11 linux-4.19.y 3f8a27f9e27b e080de16 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/04 07:01 linux-4.19.y 3f8a27f9e27b e080de16 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/12/02 12:43 linux-4.19.y 3f8a27f9e27b e080de16 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
2022/11/24 00:34 linux-4.19.y 3f8a27f9e27b 52fdf57a .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in nbd_open
* Struck through repros no longer work on HEAD.