[v6.1] possible deadlock in ntfs_set_state

0 views
Skip to first unread message

syzbot

unread,
Mar 20, 2023, 9:37:47 PM3/20/23
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 7eaef76fbc46 Linux 6.1.20
git tree: linux-6.1.y
console output: https://syzkaller.appspot.com/x/log.txt?x=1374406ac80000
kernel config: https://syzkaller.appspot.com/x/.config?x=28c36fe4d02f8c88
dashboard link: https://syzkaller.appspot.com/bug?extid=93a13140a96de3ffd18c
compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/610a00ba4375/disk-7eaef76f.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/57c1310f9a30/vmlinux-7eaef76f.xz
kernel image: https://storage.googleapis.com/syzbot-assets/81999f717d3b/bzImage-7eaef76f.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+93a131...@syzkaller.appspotmail.com

======================================================
WARNING: possible circular locking dependency detected
6.1.20-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.5/6605 is trying to acquire lock:
ffff8880802aefa0 (&ni->ni_lock){+.+.}-{3:3}, at: ntfs_set_state+0x217/0x6f0 fs/ntfs3/fsntfs.c:920

but task is already holding lock:
ffff8880802acb70 (&ni->file.run_lock#2){++++}-{3:3}, at: ntfs_extend_mft+0x15c/0x4b0 fs/ntfs3/fsntfs.c:482

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&ni->file.run_lock#2){++++}-{3:3}:
lock_acquire+0x23a/0x630 kernel/locking/lockdep.c:5669
down_read+0x39/0x50 kernel/locking/rwsem.c:1520
mi_read+0x175/0x560 fs/ntfs3/record.c:129
mi_format_new+0x1a7/0x5c0 fs/ntfs3/record.c:373
ni_add_subrecord+0xde/0x430 fs/ntfs3/frecord.c:371
ntfs_look_free_mft+0x874/0x10c0 fs/ntfs3/fsntfs.c:686
ni_create_attr_list+0xa13/0x1510 fs/ntfs3/frecord.c:873
ni_ins_attr_ext+0x330/0xbf0 fs/ntfs3/frecord.c:968
ni_insert_attr fs/ntfs3/frecord.c:1135 [inline]
ni_insert_resident fs/ntfs3/frecord.c:1519 [inline]
ni_add_name+0x619/0xc30 fs/ntfs3/frecord.c:3031
ni_rename+0xbe/0x1e0 fs/ntfs3/frecord.c:3071
ntfs_rename+0x74a/0xd10 fs/ntfs3/namei.c:308
vfs_rename+0xd8f/0x1190 fs/namei.c:4779
do_renameat2+0xb97/0x13b0 fs/namei.c:4930
__do_sys_rename fs/namei.c:4976 [inline]
__se_sys_rename fs/namei.c:4974 [inline]
__x64_sys_rename+0x82/0x90 fs/namei.c:4974
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 (&wnd->rw_lock/1){+.+.}-{3:3}:
lock_acquire+0x23a/0x630 kernel/locking/lockdep.c:5669
down_write_nested+0x39/0x60 kernel/locking/rwsem.c:1689
ntfs_mark_rec_free+0x3b/0x2b0 fs/ntfs3/fsntfs.c:713
ni_write_inode+0x433/0x1240 fs/ntfs3/frecord.c:3332
write_inode fs/fs-writeback.c:1440 [inline]
__writeback_single_inode+0x84d/0x15d0 fs/fs-writeback.c:1652
writeback_sb_inodes+0xbe3/0x1b10 fs/fs-writeback.c:1878
wb_writeback+0x504/0x1070 fs/fs-writeback.c:2052
wb_do_writeback fs/fs-writeback.c:2195 [inline]
wb_workfn+0x487/0x10f0 fs/fs-writeback.c:2235
process_one_work+0x909/0x1380 kernel/workqueue.c:2289
worker_thread+0xa5f/0x1210 kernel/workqueue.c:2436
kthread+0x268/0x300 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

-> #0 (&ni->ni_lock){+.+.}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3098 [inline]
check_prevs_add kernel/locking/lockdep.c:3217 [inline]
validate_chain+0x1667/0x58e0 kernel/locking/lockdep.c:3832
__lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5056
lock_acquire+0x23a/0x630 kernel/locking/lockdep.c:5669
__mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
ntfs_set_state+0x217/0x6f0 fs/ntfs3/fsntfs.c:920
attr_set_size+0x32e5/0x42f0 fs/ntfs3/attrib.c:880
ntfs_extend_mft+0x2f6/0x4b0 fs/ntfs3/fsntfs.c:498
ntfs_look_free_mft+0x439/0x10c0 fs/ntfs3/fsntfs.c:561
ni_create_attr_list+0x9d0/0x1510 fs/ntfs3/frecord.c:873
ni_ins_attr_ext+0x330/0xbf0 fs/ntfs3/frecord.c:968
ni_insert_attr+0x354/0x900 fs/ntfs3/frecord.c:1135
ni_insert_resident+0xf4/0x3c0 fs/ntfs3/frecord.c:1519
ntfs_set_ea+0xa70/0x16b0 fs/ntfs3/xattr.c:398
ntfs_save_wsl_perm+0x139/0x490 fs/ntfs3/xattr.c:929
ntfs3_setattr+0x961/0xb70 fs/ntfs3/file.c:817
notify_change+0xdcd/0x1080 fs/attr.c:482
chown_common+0x5aa/0x900 fs/open.c:736
do_fchownat+0x169/0x240 fs/open.c:767
__do_sys_fchownat fs/open.c:782 [inline]
__se_sys_fchownat fs/open.c:779 [inline]
__x64_sys_fchownat+0xb1/0xc0 fs/open.c:779
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:
&ni->ni_lock --> &wnd->rw_lock/1 --> &ni->file.run_lock#2

Possible unsafe locking scenario:

CPU0 CPU1
---- ----
lock(&ni->file.run_lock#2);
lock(&wnd->rw_lock/1);
lock(&ni->file.run_lock#2);
lock(&ni->ni_lock);

*** DEADLOCK ***

5 locks held by syz-executor.5/6605:
#0: ffff8880176c4460 (sb_writers#17){.+.+}-{0:0}, at: mnt_want_write+0x3b/0x80 fs/namespace.c:393
#1: ffff8880802a8b00 (&sb->s_type->i_mutex_key#24){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:756 [inline]
#1: ffff8880802a8b00 (&sb->s_type->i_mutex_key#24){+.+.}-{3:3}, at: chown_common+0x3e5/0x900 fs/open.c:726
#2: ffff8880802a8860 (&ni->ni_lock/4){+.+.}-{3:3}, at: ni_lock fs/ntfs3/ntfs_fs.h:1108 [inline]
#2: ffff8880802a8860 (&ni->ni_lock/4){+.+.}-{3:3}, at: ntfs_save_wsl_perm+0x86/0x490 fs/ntfs3/xattr.c:927
#3: ffff888034838120 (&wnd->rw_lock/1){+.+.}-{3:3}, at: ntfs_look_free_mft+0x1e1/0x10c0 fs/ntfs3/fsntfs.c:542
#4: ffff8880802acb70 (&ni->file.run_lock#2){++++}-{3:3}, at: ntfs_extend_mft+0x15c/0x4b0 fs/ntfs3/fsntfs.c:482

stack backtrace:
CPU: 0 PID: 6605 Comm: syz-executor.5 Not tainted 6.1.20-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
check_noncircular+0x2fa/0x3b0 kernel/locking/lockdep.c:2178
check_prev_add kernel/locking/lockdep.c:3098 [inline]
check_prevs_add kernel/locking/lockdep.c:3217 [inline]
validate_chain+0x1667/0x58e0 kernel/locking/lockdep.c:3832
__lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5056
lock_acquire+0x23a/0x630 kernel/locking/lockdep.c:5669
__mutex_lock_common+0x1d4/0x2520 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
ntfs_set_state+0x217/0x6f0 fs/ntfs3/fsntfs.c:920
attr_set_size+0x32e5/0x42f0 fs/ntfs3/attrib.c:880
ntfs_extend_mft+0x2f6/0x4b0 fs/ntfs3/fsntfs.c:498
ntfs_look_free_mft+0x439/0x10c0 fs/ntfs3/fsntfs.c:561
ni_create_attr_list+0x9d0/0x1510 fs/ntfs3/frecord.c:873
ni_ins_attr_ext+0x330/0xbf0 fs/ntfs3/frecord.c:968
ni_insert_attr+0x354/0x900 fs/ntfs3/frecord.c:1135
ni_insert_resident+0xf4/0x3c0 fs/ntfs3/frecord.c:1519
ntfs_set_ea+0xa70/0x16b0 fs/ntfs3/xattr.c:398
ntfs_save_wsl_perm+0x139/0x490 fs/ntfs3/xattr.c:929
ntfs3_setattr+0x961/0xb70 fs/ntfs3/file.c:817
notify_change+0xdcd/0x1080 fs/attr.c:482
chown_common+0x5aa/0x900 fs/open.c:736
do_fchownat+0x169/0x240 fs/open.c:767
__do_sys_fchownat fs/open.c:782 [inline]
__se_sys_fchownat fs/open.c:779 [inline]
__x64_sys_fchownat+0xb1/0xc0 fs/open.c:779
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:0x7f5b5628c0f9
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:00007f5b56ff1168 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
RAX: ffffffffffffffda RBX: 00007f5b563abf80 RCX: 00007f5b5628c0f9
RDX: 0000000000000000 RSI: 0000000020000000 RDI: ffffffffffffff9c
RBP: 00007f5b562e7b39 R08: 0000000000000000 R09: 0000000000000000
R10: ffffffffffffffff R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe5e98ad4f R14: 00007f5b56ff1300 R15: 0000000000022000
</TASK>
ntfs3: loop5: Mark volume as dirty due to NTFS errors


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

syzbot

unread,
May 6, 2023, 4:45:50 AM5/6/23
to syzkaller...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: ca48fc16c493 Linux 6.1.27
git tree: linux-6.1.y
console output: https://syzkaller.appspot.com/x/log.txt?x=1643394c280000
kernel config: https://syzkaller.appspot.com/x/.config?x=aea4bb7802570997
dashboard link: https://syzkaller.appspot.com/bug?extid=93a13140a96de3ffd18c
compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2
userspace arch: arm64
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=12e7f050280000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1568fb90280000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/ec11c1903c52/disk-ca48fc16.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/8ce41c1ad391/vmlinux-ca48fc16.xz
kernel image: https://storage.googleapis.com/syzbot-assets/affba5631cad/Image-ca48fc16.gz.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/5c12c5d05ee8/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+93a131...@syzkaller.appspotmail.com

ntfs3: loop0: Different NTFS' sector size (2048) and media sector size (512)
ntfs3: loop0: ino=1b, "file0" ntfs_iget5
============================================
WARNING: possible recursive locking detected
6.1.27-syzkaller #0 Not tainted
--------------------------------------------
syz-executor120/4217 is trying to acquire lock:
ffff0000e2400100 (&ni->ni_lock){+.+.}-{3:3}, at: ntfs_set_state+0x1a4/0x5c4 fs/ntfs3/fsntfs.c:920

but task is already holding lock:
ffff0000e2407700 (&ni->ni_lock){+.+.}-{3:3}, at: ni_trylock fs/ntfs3/ntfs_fs.h:1123 [inline]
ffff0000e2407700 (&ni->ni_lock){+.+.}-{3:3}, at: ni_write_inode+0x134/0xfb8 fs/ntfs3/frecord.c:3240

other info that might help us debug this:
Possible unsafe locking scenario:

CPU0
----
lock(&ni->ni_lock);
lock(&ni->ni_lock);

*** DEADLOCK ***

May be due to missing lock nesting notation

3 locks held by syz-executor120/4217:
#0: ffff0000d5d0a460 (sb_writers#8){.+.+}-{0:0}, at: mnt_want_write+0x44/0x9c fs/namespace.c:393
#1: ffff0000e24079a0 (&sb->s_type->i_mutex_key#17){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:756 [inline]
#1: ffff0000e24079a0 (&sb->s_type->i_mutex_key#17){+.+.}-{3:3}, at: do_truncate+0x1ac/0x28c fs/open.c:63
#2: ffff0000e2407700 (&ni->ni_lock){+.+.}-{3:3}, at: ni_trylock fs/ntfs3/ntfs_fs.h:1123 [inline]
#2: ffff0000e2407700 (&ni->ni_lock){+.+.}-{3:3}, at: ni_write_inode+0x134/0xfb8 fs/ntfs3/frecord.c:3240

stack backtrace:
CPU: 0 PID: 4217 Comm: syz-executor120 Not tainted 6.1.27-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/14/2023
Call trace:
dump_backtrace+0x1c8/0x1f4 arch/arm64/kernel/stacktrace.c:158
show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:165
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x108/0x170 lib/dump_stack.c:106
dump_stack+0x1c/0x5c lib/dump_stack.c:113
__lock_acquire+0x6310/0x764c kernel/locking/lockdep.c:5056
lock_acquire+0x26c/0x7cc kernel/locking/lockdep.c:5669
__mutex_lock_common+0x190/0x21a0 kernel/locking/mutex.c:603
__mutex_lock kernel/locking/mutex.c:747 [inline]
mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
ntfs_set_state+0x1a4/0x5c4 fs/ntfs3/fsntfs.c:920
ntfs_bad_inode+0x88/0x9c fs/ntfs3/fsntfs.c:885
ntfs_iget5+0x2d4/0x2b38 fs/ntfs3/inode.c:520
ni_update_parent+0x688/0xa58 fs/ntfs3/frecord.c:3196
ni_write_inode+0xc4c/0xfb8 fs/ntfs3/frecord.c:3291
ntfs_sync_inode+0x2c/0x3c fs/ntfs3/inode.c:1025
ntfs_truncate fs/ntfs3/file.c:508 [inline]
ntfs3_setattr+0x784/0x974 fs/ntfs3/file.c:792
notify_change+0xc24/0xec0 fs/attr.c:482
do_truncate+0x1c0/0x28c fs/open.c:65
vfs_truncate+0x2c4/0x36c fs/open.c:111
do_sys_truncate+0xec/0x1b4 fs/open.c:134
__do_sys_truncate fs/open.c:146 [inline]
__se_sys_truncate fs/open.c:144 [inline]
__arm64_sys_truncate+0x5c/0x70 fs/open.c:144
__invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
invoke_syscall+0x98/0x2c0 arch/arm64/kernel/syscall.c:52
el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
do_el0_svc+0x64/0x218 arch/arm64/kernel/syscall.c:206
el0_svc+0x58/0x168 arch/arm64/kernel/entry-common.c:637
el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581
ntfs3: loop0: Mark volume as dirty due to NTFS errors


---
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
Reply all
Reply to author
Forward
0 new messages