hfsplus: xattr search failed
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.0.197/6803 is trying to acquire lock:
ffff888176ef48f0 (&sbi->alloc_mutex){+.+.}-{4:4}, at: hfsplus_block_free+0xc7/0x630

but task is already holding lock:
ffff8881a687dc00 (&HFSPLUS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfsplus_file_truncate+0x2d0/0xd20

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&HFSPLUS_I(inode)->extents_lock){+.+.}-{4:4}:
       __mutex_lock+0x19d/0x1550
       hfsplus_get_block+0x391/0x1610
       block_read_full_folio+0x29f/0x810
       filemap_read_folio+0x12c/0x3a0
       do_read_cache_folio+0x354/0x590
       read_cache_page+0x5d/0x170
       hfsplus_block_allocate+0xf7/0xd30
       hfsplus_file_extend+0xb77/0x1df0
       hfsplus_get_block+0x41f/0x1610
       __blockdev_direct_IO+0x1590/0x3380
       hfsplus_direct_IO+0x21f/0x370
       generic_file_direct_write+0x1d0/0x3f0
       __generic_file_write_iter+0x11d/0x230
       generic_file_write_iter+0xae/0x330
       do_iter_readv_writev+0x612/0x8c0
       vfs_writev+0x343/0x990
       __se_sys_pwritev2+0x177/0x2a0
       do_syscall_64+0x174/0x580
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&sbi->alloc_mutex){+.+.}-{4:4}:
       __lock_acquire+0x1520/0x2cf0
       lock_acquire+0x106/0x350
       __mutex_lock+0x19d/0x1550
       hfsplus_block_free+0xc7/0x630
       hfsplus_free_extents+0x121/0xa50
       hfsplus_file_truncate+0x7ef/0xd20
       hfsplus_setattr+0x1b5/0x260
       notify_change+0xbba/0xea0
       do_truncate+0x1c2/0x250
       path_openat+0x2fed/0x3830
       do_file_open+0x23e/0x4a0
       do_sys_openat2+0x115/0x200
       __x64_sys_open+0x11e/0x150
       do_syscall_64+0x174/0x580
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&HFSPLUS_I(inode)->extents_lock);
                               lock(&sbi->alloc_mutex);
                               lock(&HFSPLUS_I(inode)->extents_lock);
  lock(&sbi->alloc_mutex);

 *** DEADLOCK ***

3 locks held by syz.0.197/6803:
 #0: ffff888177428450 (sb_writers#23){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90
 #1: ffff8881a687dd98 (&sb->s_type->i_mutex_key#34){+.+.}-{4:4}, at: do_truncate+0x18f/0x250
 #2: ffff8881a687dc00 (&HFSPLUS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfsplus_file_truncate+0x2d0/0xd20

stack backtrace:
CPU: 1 UID: 0 PID: 6803 Comm: syz.0.197 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150
 print_circular_bug+0x2e1/0x300
 check_noncircular+0x12e/0x150
 __lock_acquire+0x1520/0x2cf0
 lock_acquire+0x106/0x350
 __mutex_lock+0x19d/0x1550
 hfsplus_block_free+0xc7/0x630
 hfsplus_free_extents+0x121/0xa50
 hfsplus_file_truncate+0x7ef/0xd20
 hfsplus_setattr+0x1b5/0x260
 notify_change+0xbba/0xea0
 do_truncate+0x1c2/0x250
 path_openat+0x2fed/0x3830
 do_file_open+0x23e/0x4a0
 do_sys_openat2+0x115/0x200
 __x64_sys_open+0x11e/0x150
 do_syscall_64+0x174/0x580
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb79a59ce59
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 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 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fb79b4da028 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007fb79a815fa0 RCX: 00007fb79a59ce59
RDX: 1df2a23c5997fa7f RSI: 0000000000084242 RDI: 0000200000000440
RBP: 00007fb79a632e6f R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fb79a816038 R14: 00007fb79a815fa0 R15: 00007ffe735badc8
 </TASK>
