loop1: detected capacity change from 0 to 16
loop1: detected capacity change from 0 to 1024
======================================================
WARNING: possible circular locking dependency detected
6.10.0-rc1-syzkaller-00013-g2bfcfd584ff5 #0 Not tainted
------------------------------------------------------
syz-executor.1/15310 is trying to acquire lock:
ffff88802302a0b0 (&tree->tree_lock#2/2){+.+.}-{3:3}, at: hfsplus_find_init+0x195/0x200 fs/hfsplus/bfind.c:36

but task is already holding lock:
ffff8880230280b0 (&tree->tree_lock#2){+.+.}-{3:3}, at: hfsplus_find_init+0x1a7/0x200 fs/hfsplus/bfind.c:30

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&tree->tree_lock#2){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:608 [inline]
       __mutex_lock+0x175/0x9c0 kernel/locking/mutex.c:752
       hfsplus_file_truncate+0x886/0x9e0 fs/hfsplus/extents.c:595
       hfsplus_write_failed fs/hfsplus/inode.c:37 [inline]
       hfsplus_write_begin+0x117/0x150 fs/hfsplus/inode.c:51
       generic_perform_write+0x272/0x620 mm/filemap.c:4015
       __generic_file_write_iter+0x1fd/0x240 mm/filemap.c:4110
       generic_file_write_iter+0xe7/0x350 mm/filemap.c:4136
       new_sync_write fs/read_write.c:497 [inline]
       vfs_write+0x6b6/0x1140 fs/read_write.c:590
       ksys_write+0x12f/0x260 fs/read_write.c:643
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&HFSPLUS_I(inode)->extents_lock){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:608 [inline]
       __mutex_lock+0x175/0x9c0 kernel/locking/mutex.c:752
       hfsplus_get_block+0x277/0x9e0 fs/hfsplus/extents.c:260
       block_read_full_folio+0x38f/0xa70 fs/buffer.c:2407
       filemap_read_folio+0xe5/0x2c0 mm/filemap.c:2355
       do_read_cache_folio+0x203/0x540 mm/filemap.c:3788
       do_read_cache_page mm/filemap.c:3854 [inline]
       read_cache_page+0x5b/0x160 mm/filemap.c:3863
       read_mapping_page include/linux/pagemap.h:896 [inline]
       __hfs_bnode_create+0x63e/0x870 fs/hfsplus/bnode.c:440
       hfsplus_bnode_find+0x2c8/0xcb0 fs/hfsplus/bnode.c:486
       hfsplus_brec_find+0x2b9/0x520 fs/hfsplus/bfind.c:183
       hfsplus_find_attr+0xe6/0x190 fs/hfsplus/attributes.c:153
       __hfsplus_getxattr+0x321/0x5f0 fs/hfsplus/xattr.c:520
       hfsplus_getxattr+0x102/0x180 fs/hfsplus/xattr.c:588
       hfsplus_security_getxattr+0x39/0x50 fs/hfsplus/xattr_security.c:20
       vfs_getxattr_alloc+0x1be/0x340 fs/xattr.c:393
       ima_read_xattr+0x38/0x60 security/integrity/ima/ima_appraise.c:229
       process_measurement+0x120b/0x23a0 security/integrity/ima/ima_main.c:353
       ima_file_check+0xc1/0x110 security/integrity/ima/ima_main.c:572
       security_file_post_open+0x6d/0xc0 security/security.c:2982
       do_open fs/namei.c:3652 [inline]
       path_openat+0x17ec/0x29f0 fs/namei.c:3807
       do_filp_open+0x1dc/0x430 fs/namei.c:3834
       do_sys_openat2+0x17a/0x1e0 fs/open.c:1405
       do_sys_open fs/open.c:1420 [inline]
       __do_sys_open fs/open.c:1428 [inline]
       __se_sys_open fs/open.c:1424 [inline]
       __x64_sys_open+0x154/0x1e0 fs/open.c:1424
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&tree->tree_lock#2/2){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3134 [inline]
       check_prevs_add kernel/locking/lockdep.c:3253 [inline]
       validate_chain kernel/locking/lockdep.c:3869 [inline]
       __lock_acquire+0x2478/0x3b30 kernel/locking/lockdep.c:5137
       lock_acquire kernel/locking/lockdep.c:5754 [inline]
       lock_acquire+0x1b1/0x560 kernel/locking/lockdep.c:5719
       __mutex_lock_common kernel/locking/mutex.c:608 [inline]
       __mutex_lock+0x175/0x9c0 kernel/locking/mutex.c:752
       hfsplus_find_init+0x195/0x200 fs/hfsplus/bfind.c:36
       hfsplus_attr_exists+0x103/0x200 fs/hfsplus/attributes.c:178
       __hfsplus_setxattr+0x4c6/0x2180 fs/hfsplus/xattr.c:336
       hfsplus_setxattr+0x10c/0x180 fs/hfsplus/xattr.c:432
       __vfs_setxattr+0x173/0x1e0 fs/xattr.c:200
       __vfs_setxattr_noperm+0x127/0x660 fs/xattr.c:234
       __vfs_setxattr_locked+0x182/0x260 fs/xattr.c:295
       vfs_setxattr+0x146/0x350 fs/xattr.c:321
       do_setxattr+0x146/0x170 fs/xattr.c:629
       setxattr+0x15d/0x180 fs/xattr.c:652
       path_setxattr+0x179/0x1e0 fs/xattr.c:671
       __do_sys_setxattr fs/xattr.c:687 [inline]
       __se_sys_setxattr fs/xattr.c:683 [inline]
       __x64_sys_setxattr+0xc4/0x160 fs/xattr.c:683
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &tree->tree_lock#2/2 --> &HFSPLUS_I(inode)->extents_lock --> &tree->tree_lock#2

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&tree->tree_lock#2);
                               lock(&HFSPLUS_I(inode)->extents_lock);
                               lock(&tree->tree_lock#2);
  lock(&tree->tree_lock#2/2);

 *** DEADLOCK ***

3 locks held by syz-executor.1/15310:
 #0: ffff8880776e2420 (sb_writers#20){.+.+}-{0:0}, at: path_setxattr+0xc3/0x1e0 fs/xattr.c:669
 #1: ffff88802207d400 (&sb->s_type->i_mutex_key#25){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:791 [inline]
 #1: ffff88802207d400 (&sb->s_type->i_mutex_key#25){+.+.}-{3:3}, at: vfs_setxattr+0x123/0x350 fs/xattr.c:320
 #2: ffff8880230280b0 (&tree->tree_lock#2){+.+.}-{3:3}, at: hfsplus_find_init+0x1a7/0x200 fs/hfsplus/bfind.c:30

stack backtrace:
CPU: 0 PID: 15310 Comm: syz-executor.1 Not tainted 6.10.0-rc1-syzkaller-00013-g2bfcfd584ff5 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:114
 check_noncircular+0x31a/0x400 kernel/locking/lockdep.c:2187
 check_prev_add kernel/locking/lockdep.c:3134 [inline]
 check_prevs_add kernel/locking/lockdep.c:3253 [inline]
 validate_chain kernel/locking/lockdep.c:3869 [inline]
 __lock_acquire+0x2478/0x3b30 kernel/locking/lockdep.c:5137
 lock_acquire kernel/locking/lockdep.c:5754 [inline]
 lock_acquire+0x1b1/0x560 kernel/locking/lockdep.c:5719
 __mutex_lock_common kernel/locking/mutex.c:608 [inline]
 __mutex_lock+0x175/0x9c0 kernel/locking/mutex.c:752
 hfsplus_find_init+0x195/0x200 fs/hfsplus/bfind.c:36
 hfsplus_attr_exists+0x103/0x200 fs/hfsplus/attributes.c:178
 __hfsplus_setxattr+0x4c6/0x2180 fs/hfsplus/xattr.c:336
 hfsplus_setxattr+0x10c/0x180 fs/hfsplus/xattr.c:432
 __vfs_setxattr+0x173/0x1e0 fs/xattr.c:200
 __vfs_setxattr_noperm+0x127/0x660 fs/xattr.c:234
 __vfs_setxattr_locked+0x182/0x260 fs/xattr.c:295
 vfs_setxattr+0x146/0x350 fs/xattr.c:321
 do_setxattr+0x146/0x170 fs/xattr.c:629
 setxattr+0x15d/0x180 fs/xattr.c:652
 path_setxattr+0x179/0x1e0 fs/xattr.c:671
 __do_sys_setxattr fs/xattr.c:687 [inline]
 __se_sys_setxattr fs/xattr.c:683 [inline]
 __x64_sys_setxattr+0xc4/0x160 fs/xattr.c:683
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fec9f87cee9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007feca06700c8 EFLAGS: 00000246 ORIG_RAX: 00000000000000bc
RAX: ffffffffffffffda RBX: 00007fec9f9b3f80 RCX: 00007fec9f87cee9
RDX: 0000000020000200 RSI: 00000000200001c0 RDI: 0000000020000040
RBP: 00007fec9f8c947f R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000014 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007fec9f9b3f80 R15: 00007ffc8c3a1c98
 </TASK>