syzbot


possible deadlock in btrfs_search_slot

Status: fixed on 2023/08/10 11:21
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+c06034aecf9f5eab1ac1@syzkaller.appspotmail.com
Fix commit: b740d8061669 btrfs: free btrfs_path before copying root refs to userspace
First crash: 622d, last: 347d
Cause bisection: failed (error log, bisect log)
  
Fix bisection: fixed by (bisect log) :
commit b740d806166979488e798e41743aaec051f2443f
Author: Josef Bacik <josef@toxicpanda.com>
Date: Mon Nov 7 16:44:51 2022 +0000

  btrfs: free btrfs_path before copying root refs to userspace

  
Discussions (4)
Title Replies (including bot) Last reply
[syzbot] possible deadlock in btrfs_search_slot 1 (4) 2023/08/02 14:17
[syzbot] Monthly btrfs report (Jun 2023) 0 (1) 2023/06/29 10:14
[syzbot] Monthly btrfs report (May 2023) 0 (1) 2023/05/30 08:21
[syzbot] Monthly btrfs report (Apr 2023) 0 (1) 2023/04/27 10:13
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in btrfs_search_slot (2) btrfs C error 2 335d 331d 25/27 fixed on 2023/12/21 03:45
Last patch testing requests (1)
Created Duration User Patch Repo Result
2022/11/23 23:57 26m hdanton@sina.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git eb7081409f94 OK log

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc6-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor338/3631 is trying to acquire lock:
ffff888077fa2598 (&mm->mmap_lock#2){++++}-{3:3}, at: __might_fault+0x8f/0x110 mm/memory.c:5645

but task is already holding lock:
ffff88807e7ba4d8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock fs/btrfs/locking.c:134 [inline]
ffff88807e7ba4d8 (btrfs-root-00){++++}-{3:3}, at: btrfs_tree_read_lock fs/btrfs/locking.c:140 [inline]
ffff88807e7ba4d8 (btrfs-root-00){++++}-{3:3}, at: btrfs_read_lock_root_node+0x2b4/0x400 fs/btrfs/locking.c:279

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 (btrfs-root-00){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read_nested+0x3c/0x50 kernel/locking/rwsem.c:1634
       __btrfs_tree_read_lock fs/btrfs/locking.c:134 [inline]
       btrfs_tree_read_lock fs/btrfs/locking.c:140 [inline]
       btrfs_read_lock_root_node+0x2b4/0x400 fs/btrfs/locking.c:279
       btrfs_search_slot_get_root fs/btrfs/ctree.c:1665 [inline]
       btrfs_search_slot+0x495/0x2fe0 fs/btrfs/ctree.c:1985
       btrfs_update_root+0xf0/0xc60 fs/btrfs/root-tree.c:132
       commit_fs_roots+0x4d3/0x710 fs/btrfs/transaction.c:1441
       btrfs_commit_transaction+0x147f/0x3760 fs/btrfs/transaction.c:2353
       flush_space+0x97c/0xbc0 fs/btrfs/space-info.c:810
       btrfs_async_reclaim_data_space+0x2a6/0x520 fs/btrfs/space-info.c:1315
       process_one_work+0x877/0xdb0 kernel/workqueue.c:2289
       worker_thread+0xb14/0x1330 kernel/workqueue.c:2436
       kthread+0x266/0x300 kernel/kthread.c:376
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

-> #3 (&fs_info->reloc_mutex){+.+.}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __mutex_lock_common+0x1bd/0x26e0 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       btrfs_record_root_in_trans+0x153/0x180 fs/btrfs/transaction.c:484
       start_transaction+0x3af/0x1180 fs/btrfs/transaction.c:721
       btrfs_create_common+0x2c6/0x420 fs/btrfs/inode.c:6633
       lookup_open fs/namei.c:3413 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x12d0/0x2df0 fs/namei.c:3710
       do_filp_open+0x264/0x4f0 fs/namei.c:3740
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_creat fs/open.c:1402 [inline]
       __se_sys_creat fs/open.c:1396 [inline]
       __x64_sys_creat+0x11f/0x160 fs/open.c:1396
       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 (btrfs_trans_num_extwriters){++++}-{0:0}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       join_transaction+0x19f/0xe60 fs/btrfs/transaction.c:299
       start_transaction+0x6fb/0x1180 fs/btrfs/transaction.c:658
       btrfs_create_common+0x2c6/0x420 fs/btrfs/inode.c:6633
       lookup_open fs/namei.c:3413 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x12d0/0x2df0 fs/namei.c:3710
       do_filp_open+0x264/0x4f0 fs/namei.c:3740
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_creat fs/open.c:1402 [inline]
       __se_sys_creat fs/open.c:1396 [inline]
       __x64_sys_creat+0x11f/0x160 fs/open.c:1396
       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

-> #1 (btrfs_trans_num_writers){++++}-{0:0}:
       reacquire_held_locks+0x386/0x650 kernel/locking/lockdep.c:5193
       __lock_release kernel/locking/lockdep.c:5382 [inline]
       lock_release+0x2e2/0x820 kernel/locking/lockdep.c:5688
       percpu_up_read include/linux/percpu-rwsem.h:99 [inline]
       __sb_end_write include/linux/fs.h:1821 [inline]
       sb_end_intwrite+0x1e/0x1a0 include/linux/fs.h:1877
       __btrfs_end_transaction+0x388/0x790 fs/btrfs/transaction.c:995
       btrfs_dirty_inode+0x177/0x1c0 fs/btrfs/inode.c:6099
       inode_update_time fs/inode.c:1871 [inline]
       touch_atime+0x315/0x630 fs/inode.c:1944
       file_accessed include/linux/fs.h:2521 [inline]
       btrfs_file_mmap+0xbb/0x120 fs/btrfs/file.c:2333
       call_mmap include/linux/fs.h:2196 [inline]
       mmap_region+0xfe6/0x1e20 mm/mmap.c:2625
       do_mmap+0x8d9/0xf30 mm/mmap.c:1412
       vm_mmap_pgoff+0x19e/0x2b0 mm/util.c:520
       ksys_mmap_pgoff+0x48c/0x6d0 mm/mmap.c:1458
       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 (&mm->mmap_lock#2){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3097 [inline]
       check_prevs_add kernel/locking/lockdep.c:3216 [inline]
       validate_chain+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
       __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __might_fault+0xb2/0x110 mm/memory.c:5646
       _copy_to_user+0x26/0x130 lib/usercopy.c:29
       copy_to_user include/linux/uaccess.h:169 [inline]
       btrfs_ioctl_get_subvol_rootref+0x8cf/0xa90 fs/btrfs/ioctl.c:3203
       btrfs_ioctl+0xb7c/0xc10 fs/btrfs/ioctl.c:5556
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:870 [inline]
       __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:856
       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

other info that might help us debug this:

Chain exists of:
  &mm->mmap_lock#2 --> &fs_info->reloc_mutex --> btrfs-root-00

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(btrfs-root-00);
                               lock(&fs_info->reloc_mutex);
                               lock(btrfs-root-00);
  lock(&mm->mmap_lock#2);

 *** DEADLOCK ***

1 lock held by syz-executor338/3631:
 #0: ffff88807e7ba4d8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock fs/btrfs/locking.c:134 [inline]
 #0: ffff88807e7ba4d8 (btrfs-root-00){++++}-{3:3}, at: btrfs_tree_read_lock fs/btrfs/locking.c:140 [inline]
 #0: ffff88807e7ba4d8 (btrfs-root-00){++++}-{3:3}, at: btrfs_read_lock_root_node+0x2b4/0x400 fs/btrfs/locking.c:279

stack backtrace:
CPU: 1 PID: 3631 Comm: syz-executor338 Not tainted 6.1.0-rc6-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
 check_noncircular+0x2cc/0x390 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+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
 __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
 lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
 __might_fault+0xb2/0x110 mm/memory.c:5646
 _copy_to_user+0x26/0x130 lib/usercopy.c:29
 copy_to_user include/linux/uaccess.h:169 [inline]
 btrfs_ioctl_get_subvol_rootref+0x8cf/0xa90 fs/btrfs/ioctl.c:3203
 btrfs_ioctl+0xb7c/0xc10 fs/btrfs/ioctl.c:5556
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:856
 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
RIP: 0033:0x7fedeabbefb9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 51 14 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd63c463b8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007ffd63c463c8 RCX: 00007fedeabbefb9
RDX: 000000002005de40 RSI: 00000000d000943d RDI: 0000000000000006
RBP: 00007ffd63c463c0 R08: 00007ffd63c463c0 R09: 00007fedeab7c570
R10: 00007ffd63c463c0 R11: 0000000000000246 R12: 000000

Crashes (188):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/11/23 21:11 upstream eb7081409f94 52fdf57a .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/08/09 06:12 upstream 13b937206866 8ad1a287 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/06/22 20:00 upstream dad9774deaf1 79782afc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/06/06 09:14 upstream f8dba31b0a82 a4ae4f42 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/05/24 21:09 upstream 9d646009f65d 4bce1a3e .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/05/23 19:37 upstream ae8373a5add4 4bce1a3e .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/05/12 02:05 upstream 105131df9c3b adb9a3cd .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_search_slot
2023/04/28 11:20 upstream 91ec4b0d11fe 70a605de .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/22 15:06 upstream 8e41e0a57566 2b32bd34 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/21 19:40 upstream 2af3e53a4dc0 2b32bd34 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/16 00:00 upstream a7a55e27ad72 ec410564 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/12 22:07 upstream 0bcc40255504 82d5e53e .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/12 16:59 upstream e62252bc55b6 1a1596b6 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/11 21:53 upstream e62252bc55b6 49faf98d .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/04/09 03:47 upstream a79d5c76f705 71147e29 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/03/30 11:31 upstream ffe78bbd5121 f325deb0 .config console log report info ci-upstream-kasan-gce-selinux-root possible deadlock in btrfs_search_slot
2023/03/24 16:35 upstream 1e760fa3596e 9700afae .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/02/28 13:56 upstream ae3419fbac84 95aee97a .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/02/16 18:59 upstream 033c40a89f55 38b317a7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/02/03 00:42 upstream e7368fd30165 16d19e30 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/01/21 23:17 upstream f883675bf652 cc0f9968 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2023/01/12 17:00 upstream e8f60cd7db24 96166539 .config console log report info ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/24 07:35 upstream a27405b2ed9c 9da18ae8 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_search_slot
2022/12/23 15:24 upstream 8395ae05cb5a 9da18ae8 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/19 11:48 upstream f9ff5644bcc0 05494336 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/15 16:37 upstream 041fae9c105a 6f9c033e .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/15 04:55 upstream 6f1f5caed5bf b18f0a64 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_search_slot
2022/12/11 22:21 upstream 4cee37b3a4e6 67be1ae7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/09 19:38 upstream 0d1409e4ff08 67be1ae7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/03 21:17 upstream 97ee9d1c1696 e080de16 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/02 23:29 upstream a4412fdd49dc e080de16 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_search_slot
2022/11/28 18:21 upstream b7b275e60bcd 247de55b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/27 14:56 upstream faf68e3523c2 74a66371 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root possible deadlock in btrfs_search_slot
2022/11/27 06:52 upstream 644e9524388a f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 14:22 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 12:49 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 11:40 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 10:56 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 09:46 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 08:38 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 07:24 upstream 0b1dcc2cf55a 74a66371 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root possible deadlock in btrfs_search_slot
2022/11/26 06:23 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 05:11 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 04:48 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 03:38 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 02:24 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/26 01:14 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/25 22:55 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/25 21:52 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/25 20:50 upstream 08ad43d554ba f4470a7b .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/25 17:46 upstream c3eb11fbb826 74a66371 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/11/07 12:03 upstream f0c4d9fc9cc9 6d752409 .config console log report info ci2-upstream-fs possible deadlock in btrfs_search_slot
2022/12/12 01:54 linux-next 591cd61541b9 67be1ae7 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in btrfs_search_slot
2023/06/22 05:21 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 42234a752679 09ffe269 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in btrfs_search_slot
2023/04/06 00:19 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 59caa87f9dfb 8b834965 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in btrfs_search_slot
2023/03/01 03:58 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 2ebd1fbb946d 95aee97a .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 possible deadlock in btrfs_search_slot
* Struck through repros no longer work on HEAD.