syzbot


possible deadlock in btrfs_add_qgroup_relation

Status: upstream: reported on 2022/12/19 18:47
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+beaef9139479177cd347@syzkaller.appspotmail.com
First crash: 465d, last: 454d

Sample crash report:
BTRFS info (device loop3): has skinny extents
IPVS: ftp: loaded support on port[0] = 21
kauditd_printk_skb: 1 callbacks suppressed
audit: type=1800 audit(1672417804.152:231): pid=21197 uid=0 auid=4294967295 ses=4294967295 subj==unconfined op=collect_data cause=failed(directio) comm="syz-executor.3" name=".pending_reads" dev="loop3" ino=263 res=0
======================================================
WARNING: possible circular locking dependency detected
4.19.211-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.3/21197 is trying to acquire lock:
0000000021499ef2 (&fs_info->qgroup_ioctl_lock){+.+.}, at: btrfs_add_qgroup_relation+0xa7/0x740 fs/btrfs/qgroup.c:1264

but task is already holding lock:
00000000efc5ef0f (sb_internal#2){.+.+}, at: sb_start_intwrite include/linux/fs.h:1626 [inline]
00000000efc5ef0f (sb_internal#2){.+.+}, at: start_transaction+0xa37/0xf90 fs/btrfs/transaction.c:528

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (sb_internal#2){.+.+}:
       sb_start_intwrite include/linux/fs.h:1626 [inline]
       start_transaction+0xa37/0xf90 fs/btrfs/transaction.c:528
       btrfs_quota_enable+0x169/0x10b0 fs/btrfs/qgroup.c:905
       btrfs_ioctl_quota_ctl fs/btrfs/ioctl.c:5233 [inline]
       btrfs_ioctl+0x622c/0x76d0 fs/btrfs/ioctl.c:6021
       vfs_ioctl fs/ioctl.c:46 [inline]
       file_ioctl fs/ioctl.c:501 [inline]
       do_vfs_ioctl+0xcdb/0x12e0 fs/ioctl.c:688
       ksys_ioctl+0x9b/0xc0 fs/ioctl.c:705
       __do_sys_ioctl fs/ioctl.c:712 [inline]
       __se_sys_ioctl fs/ioctl.c:710 [inline]
       __x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:710
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #0 (&fs_info->qgroup_ioctl_lock){+.+.}:
       __mutex_lock_common kernel/locking/mutex.c:937 [inline]
       __mutex_lock+0xd7/0x1190 kernel/locking/mutex.c:1078
       btrfs_add_qgroup_relation+0xa7/0x740 fs/btrfs/qgroup.c:1264
       btrfs_ioctl_qgroup_assign fs/btrfs/ioctl.c:5280 [inline]
       btrfs_ioctl+0x3a05/0x76d0 fs/btrfs/ioctl.c:6023
       vfs_ioctl fs/ioctl.c:46 [inline]
       file_ioctl fs/ioctl.c:501 [inline]
       do_vfs_ioctl+0xcdb/0x12e0 fs/ioctl.c:688
       ksys_ioctl+0x9b/0xc0 fs/ioctl.c:705
       __do_sys_ioctl fs/ioctl.c:712 [inline]
       __se_sys_ioctl fs/ioctl.c:710 [inline]
       __x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:710
       do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(sb_internal#2);
                               lock(&fs_info->qgroup_ioctl_lock);
                               lock(sb_internal#2);
  lock(&fs_info->qgroup_ioctl_lock);

 *** DEADLOCK ***

2 locks held by syz-executor.3/21197:
 #0: 000000001a12e11d (sb_writers#14){.+.+}, at: sb_start_write include/linux/fs.h:1579 [inline]
 #0: 000000001a12e11d (sb_writers#14){.+.+}, at: mnt_want_write_file+0x63/0x1d0 fs/namespace.c:418
 #1: 00000000efc5ef0f (sb_internal#2){.+.+}, at: sb_start_intwrite include/linux/fs.h:1626 [inline]
 #1: 00000000efc5ef0f (sb_internal#2){.+.+}, at: start_transaction+0xa37/0xf90 fs/btrfs/transaction.c:528

stack backtrace:
CPU: 0 PID: 21197 Comm: syz-executor.3 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
 __mutex_lock_common kernel/locking/mutex.c:937 [inline]
 __mutex_lock+0xd7/0x1190 kernel/locking/mutex.c:1078
 btrfs_add_qgroup_relation+0xa7/0x740 fs/btrfs/qgroup.c:1264
 btrfs_ioctl_qgroup_assign fs/btrfs/ioctl.c:5280 [inline]
 btrfs_ioctl+0x3a05/0x76d0 fs/btrfs/ioctl.c:6023
 vfs_ioctl fs/ioctl.c:46 [inline]
 file_ioctl fs/ioctl.c:501 [inline]
 do_vfs_ioctl+0xcdb/0x12e0 fs/ioctl.c:688
 ksys_ioctl+0x9b/0xc0 fs/ioctl.c:705
 __do_sys_ioctl fs/ioctl.c:712 [inline]
 __se_sys_ioctl fs/ioctl.c:710 [inline]
 __x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:710
 do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7faa329ce0a9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007faa30f40168 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007faa32aedf80 RCX: 00007faa329ce0a9
RDX: 0000000020000280 RSI: 0000000040189429 RDI: 0000000000000005
RBP: 00007faa32a29ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffda155ce2f R14: 00007faa30f40300 R15: 0000000000022000
IPVS: ftp: loaded support on port[0] = 21
audit: type=1800 audit(1672417805.642:232): pid=21426 uid=0 auid=4294967295 ses=4294967295 subj==unconfined op=collect_data cause=failed(directio) comm="syz-executor.3" name=".pending_reads" dev="sda1" ino=14999 res=0
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
BTRFS info (device loop3): using free space tree
BTRFS info (device loop3): has skinny extents
audit: type=1800 audit(1672417807.882:233): pid=21483 uid=0 auid=4294967295 ses=4294967295 subj==unconfined op=collect_data cause=failed(directio) comm="syz-executor.3" name=".pending_reads" dev="loop3" ino=263 res=0
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 ©,í…×: Selected rate control algorithm 'minstrel_ht'
ieee80211 phy26: Selected rate control algorithm 'minstrel_ht'

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/12/30 16:30 linux-4.19.y 3f8a27f9e27b 44712fbc .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in btrfs_add_qgroup_relation
2022/12/30 03:01 linux-4.19.y 3f8a27f9e27b 44712fbc .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in btrfs_add_qgroup_relation
2022/12/30 02:42 linux-4.19.y 3f8a27f9e27b 44712fbc .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in btrfs_add_qgroup_relation
2022/12/20 17:54 linux-4.19.y 3f8a27f9e27b d3e76707 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in btrfs_add_qgroup_relation
2022/12/19 18:47 linux-4.19.y 3f8a27f9e27b 05494336 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 possible deadlock in btrfs_add_qgroup_relation
* Struck through repros no longer work on HEAD.