syzbot


possible deadlock in ext4_setattr

Status: fixed on 2023/07/01 16:05
Subsystems: ext4
[Documentation on labels]
Reported-by: syzbot+cbb68193bdb95af4340a@syzkaller.appspotmail.com
Fix commit: b3e6bcb94590 ext4: add EA_INODE checking to ext4_iget()
First crash: 505d, last: 382d
Cause bisection: introduced by (bisect log) :
commit a3c06ae158dd6fa8336157c31d9234689d068d02
Author: Parav Pandit <parav@nvidia.com>
Date: Tue Jan 5 10:32:03 2021 +0000

  vdpa_sim_net: Add support for user supported devices

Crash: possible deadlock in ext4_xattr_set_handle (log)
Repro: C syz .config
  
Discussions (2)
Title Replies (including bot) Last reply
[PATCH 0/4] ext4: clean up ea_inode handling 5 (5) 2023/05/24 03:49
[syzbot] [ext4?] possible deadlock in ext4_setattr 3 (5) 2023/05/15 01:15
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 possible deadlock in ext4_setattr 6 433d 438d 0/3 auto-obsoleted due to no activity on 2023/07/21 04:14
Last patch testing requests (11)
Created Duration User Patch Repo Result
2023/05/22 18:43 21m tytso@mit.edu git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git test OK log
2023/05/22 17:20 21m tytso@mit.edu patch git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git test OK log
2023/05/22 16:18 13m tytso@mit.edu patch git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git test report log
2023/05/22 14:46 13m tytso@mit.edu git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git test report log
2023/05/22 03:14 15m tytso@mit.edu git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git test report log
2023/05/22 02:18 0m tytso@mit.edu https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git test error OK
2023/05/21 17:38 0m tytso@mit.edu https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git test error OK
2023/05/15 16:18 13m tytso@mit.edu patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git v6.4-rc2 report log
2023/05/15 04:25 13m tytso@mit.edu patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git v6.4-rc2 report log
2023/05/15 01:38 13m tytso@mit.edu https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git v6.4-rc2 report log
2023/05/15 01:30 13m tytso@mit.edu https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git v6.4-rc1 report log

Sample crash report:
EXT4-fs error (device loop0): ext4_xattr_block_set:2241: inode #12: comm syz-executor377: bad block 0
======================================================
WARNING: possible circular locking dependency detected
6.4.0-rc1-next-20230512-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor377/5019 is trying to acquire lock:
ffff8880787f73a0 (mapping.invalidate_lock){++++}-{3:3}, at: filemap_invalidate_lock include/linux/fs.h:820 [inline]
ffff8880787f73a0 (mapping.invalidate_lock){++++}-{3:3}, at: ext4_setattr+0x68f/0x26c0 fs/ext4/inode.c:5359

but task is already holding lock:
ffff8880787f7200 (&ea_inode->i_rwsem#8/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:775 [inline]
ffff8880787f7200 (&ea_inode->i_rwsem#8/1){+.+.}-{3:3}, at: do_truncate+0x131/0x200 fs/open.c:64

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&ea_inode->i_rwsem#8/1){+.+.}-{3:3}:
       down_write+0x92/0x200 kernel/locking/rwsem.c:1573
       inode_lock include/linux/fs.h:775 [inline]
       ext4_xattr_inode_create fs/ext4/xattr.c:1524 [inline]
       ext4_xattr_inode_lookup_create fs/ext4/xattr.c:1607 [inline]
       ext4_xattr_set_entry+0x2b19/0x39e0 fs/ext4/xattr.c:1736
       ext4_xattr_block_set+0xcb7/0x3030 fs/ext4/xattr.c:2042
       ext4_xattr_set_handle+0xd8a/0x1510 fs/ext4/xattr.c:2457
       ext4_xattr_set+0x144/0x360 fs/ext4/xattr.c:2559
       __vfs_setxattr+0x173/0x1e0 fs/xattr.c:201
       __vfs_setxattr_noperm+0x129/0x5f0 fs/xattr.c:235
       __vfs_setxattr_locked+0x1d3/0x260 fs/xattr.c:296
       vfs_setxattr+0x143/0x340 fs/xattr.c:322
       do_setxattr+0x147/0x190 fs/xattr.c:630
       setxattr+0x146/0x160 fs/xattr.c:653
       path_setxattr+0x197/0x1c0 fs/xattr.c:672
       __do_sys_setxattr fs/xattr.c:688 [inline]
       __se_sys_setxattr fs/xattr.c:684 [inline]
       __x64_sys_setxattr+0xc4/0x160 fs/xattr.c:684
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #2 (&ei->xattr_sem){++++}-{3:3}:
       down_write+0x92/0x200 kernel/locking/rwsem.c:1573
       ext4_write_lock_xattr fs/ext4/xattr.h:155 [inline]
       ext4_xattr_set_handle+0x160/0x1510 fs/ext4/xattr.c:2372
       ext4_xattr_set+0x144/0x360 fs/ext4/xattr.c:2559
       __vfs_setxattr+0x173/0x1e0 fs/xattr.c:201
       __vfs_setxattr_noperm+0x129/0x5f0 fs/xattr.c:235
       __vfs_setxattr_locked+0x1d3/0x260 fs/xattr.c:296
       vfs_setxattr+0x143/0x340 fs/xattr.c:322
       do_setxattr+0x147/0x190 fs/xattr.c:630
       setxattr+0x146/0x160 fs/xattr.c:653
       path_setxattr+0x197/0x1c0 fs/xattr.c:672
       __do_sys_setxattr fs/xattr.c:688 [inline]
       __se_sys_setxattr fs/xattr.c:684 [inline]
       __x64_sys_setxattr+0xc4/0x160 fs/xattr.c:684
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #1 (jbd2_handle){++++}-{0:0}:
       start_this_handle+0xfe7/0x14e0 fs/jbd2/transaction.c:463
       jbd2__journal_start+0x38a/0x6b0 fs/jbd2/transaction.c:520
       __ext4_journal_start_sb+0x411/0x5d0 fs/ext4/ext4_jbd2.c:111
       __ext4_journal_start fs/ext4/ext4_jbd2.h:326 [inline]
       ext4_truncate+0x54f/0x1340 fs/ext4/inode.c:4126
       ext4_setattr+0x1ac1/0x26c0 fs/ext4/inode.c:5436
       notify_change+0xb2c/0x1180 fs/attr.c:483
       do_truncate+0x143/0x200 fs/open.c:66
       do_sys_ftruncate+0x53a/0x770 fs/open.c:194
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (mapping.invalidate_lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3113 [inline]
       check_prevs_add kernel/locking/lockdep.c:3232 [inline]
       validate_chain kernel/locking/lockdep.c:3847 [inline]
       __lock_acquire+0x2fcd/0x5f30 kernel/locking/lockdep.c:5088
       lock_acquire.part.0+0x11c/0x370 kernel/locking/lockdep.c:5705
       down_write+0x92/0x200 kernel/locking/rwsem.c:1573
       filemap_invalidate_lock include/linux/fs.h:820 [inline]
       ext4_setattr+0x68f/0x26c0 fs/ext4/inode.c:5359
       notify_change+0xb2c/0x1180 fs/attr.c:483
       do_truncate+0x143/0x200 fs/open.c:66
       handle_truncate fs/namei.c:3295 [inline]
       do_open fs/namei.c:3640 [inline]
       path_openat+0x2083/0x2750 fs/namei.c:3791
       do_filp_open+0x1ba/0x410 fs/namei.c:3818
       do_sys_openat2+0x16d/0x4c0 fs/open.c:1356
       do_sys_open fs/open.c:1372 [inline]
       __do_sys_openat fs/open.c:1388 [inline]
       __se_sys_openat fs/open.c:1383 [inline]
       __x64_sys_openat+0x143/0x1f0 fs/open.c:1383
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/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:
  mapping.invalidate_lock --> &ei->xattr_sem --> &ea_inode->i_rwsem#8/1

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&ea_inode->i_rwsem#8/1);
                               lock(&ei->xattr_sem);
                               lock(&ea_inode->i_rwsem#8/1);
  lock(mapping.invalidate_lock);

 *** DEADLOCK ***

2 locks held by syz-executor377/5019:
 #0: ffff888021c64460 (sb_writers#4){.+.+}-{0:0}, at: do_open fs/namei.c:3629 [inline]
 #0: ffff888021c64460 (sb_writers#4){.+.+}-{0:0}, at: path_openat+0x19a4/0x2750 fs/namei.c:3791
 #1: ffff8880787f7200 (&ea_inode->i_rwsem#8/1){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:775 [inline]
 #1: ffff8880787f7200 (&ea_inode->i_rwsem#8/1){+.+.}-{3:3}, at: do_truncate+0x131/0x200 fs/open.c:64

stack backtrace:
CPU: 0 PID: 5019 Comm: syz-executor377 Not tainted 6.4.0-rc1-next-20230512-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/28/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2188
 check_prev_add kernel/locking/lockdep.c:3113 [inline]
 check_prevs_add kernel/locking/lockdep.c:3232 [inline]
 validate_chain kernel/locking/lockdep.c:3847 [inline]
 __lock_acquire+0x2fcd/0x5f30 kernel/locking/lockdep.c:5088
 lock_acquire.part.0+0x11c/0x370 kernel/locking/lockdep.c:5705
 down_write+0x92/0x200 kernel/locking/rwsem.c:1573
 filemap_invalidate_lock include/linux/fs.h:820 [inline]
 ext4_setattr+0x68f/0x26c0 fs/ext4/inode.c:5359
 notify_change+0xb2c/0x1180 fs/attr.c:483
 do_truncate+0x143/0x200 fs/open.c:66
 handle_truncate fs/namei.c:3295 [inline]
 do_open fs/namei.c:3640 [inline]
 path_openat+0x2083/0x2750 fs/namei.c:3791
 do_filp_open+0x1ba/0x410 fs/namei.c:3818
 do_sys_openat2+0x16d/0x4c0 fs/open.c:1356
 do_sys_open fs/open.c:1372 [inline]
 __do_sys_openat fs/open.c:1388 [inline]
 __se_sys_openat fs/open.c:1383 [inline]
 __x64_sys_openat+0x143/0x1f0 fs/open.c:1383
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fdbd832a659
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 71 15 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:00007fdbd82d62f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007fdbd83af780 RCX: 00007fdbd832a659
RDX: 0000000000028200 RSI: 00000000200000c0 RDI: ffffffffffffff9c
RBP: 0030656c69662f2e R08: 0000000000000000 R09: 0000000000000000
R10: 000000000000002d R11: 0000000000000246 R12: 00007fdbd837c0c0
R13: 95ac780a7f2d2eef R14: 2f30656c69662f2e R15: 00007fdbd83af788
 </TASK>

Crashes (7):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/05/13 12:56 linux-next e922ba281a8d 2b9ba477 .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro #1] [mounted in repro #2] ci-upstream-linux-next-kasan-gce-root possible deadlock in ext4_setattr
2023/01/10 07:49 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 358a161a6a9e 1dac8c7a .config console log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci-upstream-gce-arm64 possible deadlock in ext4_setattr
2023/03/18 03:27 upstream 8d3c682a5e3d 7939252e .config console log report info ci-upstream-kasan-gce-selinux-root possible deadlock in ext4_setattr
2023/03/18 02:26 upstream 8d3c682a5e3d 7939252e .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in ext4_setattr
2023/03/18 09:50 upstream 478a351ce0d6 7939252e .config console log report info ci-qemu-upstream-386 possible deadlock in ext4_setattr
2023/03/18 00:30 upstream cb80b960ce44 7939252e .config console log report info ci-qemu-upstream-386 possible deadlock in ext4_setattr
2023/04/15 10:03 linux-next d3f2cd248191 ec410564 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root possible deadlock in ext4_setattr
* Struck through repros no longer work on HEAD.