======================================================
WARNING: possible circular locking dependency detected
6.10.0-rc5-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.4/9275 is trying to acquire lock:
ffff8880796d00b0 (&tree->tree_lock/1){+.+.}-{3:3}, at: hfs_find_init+0x183/0x220 fs/hfs/bfind.c:33

but task is already holding lock:
ffff88806f965578 (&HFS_I(tree->inode)->extents_lock){+.+.}-{3:3}, at: hfs_extend_file+0xa2/0xb10 fs/hfs/extent.c:397

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&HFS_I(tree->inode)->extents_lock){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:608 [inline]
       __mutex_lock+0x175/0x9c0 kernel/locking/mutex.c:752
       hfs_extend_file+0xa2/0xb10 fs/hfs/extent.c:397
       hfs_bmap_reserve+0x29c/0x380 fs/hfs/btree.c:234
       __hfs_ext_write_extent+0x3cf/0x520 fs/hfs/extent.c:121
       __hfs_ext_cache_extent fs/hfs/extent.c:174 [inline]
       hfs_ext_read_extent+0x809/0x9e0 fs/hfs/extent.c:202
       hfs_extend_file+0x4e4/0xb10 fs/hfs/extent.c:401
       hfs_get_block+0x17f/0x830 fs/hfs/extent.c:353
       __block_write_begin_int+0x4fb/0x16e0 fs/buffer.c:2128
       __block_write_begin fs/buffer.c:2177 [inline]
       block_write_begin+0xb1/0x4a0 fs/buffer.c:2236
       cont_write_begin+0x53d/0x740 fs/buffer.c:2590
       hfs_write_begin+0x87/0x150 fs/hfs/inode.c:53
       cont_expand_zero fs/buffer.c:2517 [inline]
       cont_write_begin+0x333/0x740 fs/buffer.c:2580
       hfs_write_begin+0x87/0x150 fs/hfs/inode.c:53
       hfs_file_truncate+0xc11/0xfc0 fs/hfs/extent.c:494
       hfs_inode_setattr+0x48f/0x5d0 fs/hfs/inode.c:652
       notify_change+0x742/0x11f0 fs/attr.c:497
       do_truncate+0x15c/0x220 fs/open.c:65
       do_ftruncate+0x5e5/0x720 fs/open.c:181
       do_sys_ftruncate fs/open.c:199 [inline]
       __do_sys_ftruncate fs/open.c:207 [inline]
       __se_sys_ftruncate fs/open.c:205 [inline]
       __x64_sys_ftruncate+0xa9/0x110 fs/open.c:205
       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/1){+.+.}-{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
       hfs_find_init+0x183/0x220 fs/hfs/bfind.c:33
       hfs_ext_read_extent+0x19c/0x9e0 fs/hfs/extent.c:200
       hfs_extend_file+0x4e4/0xb10 fs/hfs/extent.c:401
       hfs_bmap_reserve+0x29c/0x380 fs/hfs/btree.c:234
       hfs_cat_create+0x22b/0x810 fs/hfs/catalog.c:104
       hfs_create+0x6b/0xf0 fs/hfs/dir.c:202
       vfs_create fs/namei.c:3207 [inline]
       vfs_create+0x4c2/0x770 fs/namei.c:3191
       do_mknodat+0x3d5/0x5d0 fs/namei.c:4059
       __do_sys_mknodat fs/namei.c:4087 [inline]
       __se_sys_mknodat fs/namei.c:4084 [inline]
       __x64_sys_mknodat+0xb1/0xe0 fs/namei.c:4084
       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:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&HFS_I(tree->inode)->extents_lock);
                               lock(&tree->tree_lock/1);
                               lock(&HFS_I(tree->inode)->extents_lock);
  lock(&tree->tree_lock/1);

 *** DEADLOCK ***

4 locks held by syz-executor.4/9275:
 #0: ffff88802a5da420 (sb_writers#20){.+.+}-{0:0}, at: filename_create+0x10d/0x530 fs/namei.c:3893
 #1: ffff88806f965da8 (&type->i_mutex_dir_key#11/1){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:826 [inline]
 #1: ffff88806f965da8 (&type->i_mutex_dir_key#11/1){+.+.}-{3:3}, at: filename_create+0x1c2/0x530 fs/namei.c:3900
 #2: ffff88806259c0b0 (&tree->tree_lock){+.+.}-{3:3}, at: hfs_find_init+0x1be/0x220 fs/hfs/bfind.c:30
 #3: ffff88806f965578 (&HFS_I(tree->inode)->extents_lock){+.+.}-{3:3}, at: hfs_extend_file+0xa2/0xb10 fs/hfs/extent.c:397

stack backtrace:
CPU: 0 PID: 9275 Comm: syz-executor.4 Not tainted 6.10.0-rc5-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/07/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
 hfs_find_init+0x183/0x220 fs/hfs/bfind.c:33
 hfs_ext_read_extent+0x19c/0x9e0 fs/hfs/extent.c:200
 hfs_extend_file+0x4e4/0xb10 fs/hfs/extent.c:401
 hfs_bmap_reserve+0x29c/0x380 fs/hfs/btree.c:234
 hfs_cat_create+0x22b/0x810 fs/hfs/catalog.c:104
 hfs_create+0x6b/0xf0 fs/hfs/dir.c:202
 vfs_create fs/namei.c:3207 [inline]
 vfs_create+0x4c2/0x770 fs/namei.c:3191
 do_mknodat+0x3d5/0x5d0 fs/namei.c:4059
 __do_sys_mknodat fs/namei.c:4087 [inline]
 __se_sys_mknodat fs/namei.c:4084 [inline]
 __x64_sys_mknodat+0xb1/0xe0 fs/namei.c:4084
 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:0x7f0ba8c7d0a9
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:00007f0ba9aa60c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000103
RAX: ffffffffffffffda RBX: 00007f0ba8db3f80 RCX: 00007f0ba8c7d0a9
RDX: 0000000000000000 RSI: 0000000020000140 RDI: ffffffffffffff9c
RBP: 00007f0ba8cec074 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f0ba8db3f80 R15: 00007fff5102c018
 </TASK>