Skip to contentSkip to conversation

possible deadlock in bch2_symlink

syzbot syzbot 5 participants 8 messages Sep 29, 2024 – Aug 18, 2025

lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    ad46e8f95e93 Merge tag 'pm-6.12-rc1-2' of git://git.kernel..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17eb9e80580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=62086b2fd100a029
dashboard link: https://syzkaller.appspot.com/bug?extid=7836a68852a10ec3d790
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

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

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7feb34a89c2a/non_bootable_disk-ad46e8f9.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/72b7539cbeb1/vmlinux-ad46e8f9.xz
kernel image: https://storage.googleapis.com/syzbot-assets/73c9b9cebaf4/bzImage-ad46e8f9.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

loop0: detected capacity change from 0 to 32768
bcachefs (loop0): starting version 1.7: mi_btree_bitmap opts=errors=continue,compression=lz4,nojournal_transaction_names bcachefs (loop0): recovering from clean shutdown, journal seq 7
bcachefs (loop0): Doing compatible version upgrade from 1.7: mi_btree_bitmap to 1.12: rebalance_work_acct_fix
running recovery passes: check_allocations
invalid bkey u64s 11 type alloc_v4 0:14:0 len 0 ver 0:
gen 0 oldest_gen 0 data_type journal

  journal_seq       1
  need_discard      1
  need_inc_gen      1
  dirty_sectors     256
  stripe_sectors    0
  cached_sectors    0
  stripe            67108864
  stripe_redundancy 0
  io_time[READ]     1
  io_time[WRITE]    1
  fragmentation     0
  bp_start          8

invalid data type (got 2 should be 7): delete?, fixing
bcachefs (loop0): accounting_read... done
bcachefs (loop0): alloc_read... done
bcachefs (loop0): stripes_read... done
bcachefs (loop0): snapshots_read... done
bcachefs (loop0): check_allocations...
btree ptr not marked in member info btree allocated bitmap
u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 75277f57b0c8c24 written 32 min_key POS_MIN durability: 1 ptr: 0:26:0 gen 0, fixing
btree ptr not marked in member info btree allocated bitmap
u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 19bc58a6c09b6540 written 24 min_key POS_MIN durability: 1 ptr: 0:38:0 gen 0, fixing
btree ptr not marked in member info btree allocated bitmap
u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq c18f4a4face03c6 written 24 min_key POS_MIN durability: 1 ptr: 0:41:0 gen 0, fixing
btree ptr not marked in member info btree allocated bitmap
u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 7675f41d391e5d36 written 16 min_key POS_MIN durability: 1 ptr: 0:35:0 gen 0, fixing
btree ptr not marked in member info btree allocated bitmap
u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq bcb9905dfb2993d5 written 16 min_key POS_MIN durability: 1 ptr: 0:32:0 gen 0, fixing
btree ptr not marked in member info btree allocated bitmap
u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 9a831b4a3f983356 written 32 min_key POS_MIN durability: 1 ptr: 0:29:0 gen 0, fixing
bucket 0:14 gen 0 has wrong data_type: got free, should be journal, fixing
bucket 0:14 gen 0 data type journal has wrong dirty_sectors: got 0, should be 256, fixing
done
bcachefs (loop0): going read-write
bcachefs (loop0): journal_replay... done
bcachefs (loop0): resume_logged_ops... done
bcachefs (loop0): delete_dead_inodes... done
bcachefs (loop0): Fixed errors, running fsck a second time to verify fs is clean
bcachefs (loop0): resume_logged_ops... done
bcachefs (loop0): delete_dead_inodes... done
bcachefs (loop0): done starting filesystem
============================================
WARNING: possible recursive locking detected
6.11.0-syzkaller-11728-gad46e8f95e93 #0 Not tainted
--------------------------------------------
syz.0.0/5107 is trying to acquire lock:
ffff888012fadae8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: inode_lock include/linux/fs.h:815 [inline] ffff888012fadae8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: bch2_symlink+0x176/0x310 fs/bcachefs/fs.c:700

but task is already holding lock:
ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: inode_lock include/linux/fs.h:815 [inline] ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:783 [inline] ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1002 [inline] ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1203 [inline] ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_copy_up_flags+0x1900/0x46f0 fs/overlayfs/copy_up.c:1258

other info that might help us debug this:

 Possible unsafe locking scenario:
       CPU0
       ----

lock(&sb->s_type->i_mutex_key#19);
lock(&sb->s_type->i_mutex_key#19);

*** DEADLOCK ***

May be due to missing lock nesting notation

6 locks held by syz.0.0/5107:
#0: ffff88804e2a6420 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:515
#1: ffff888040e71e50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:850 [inline] #1: ffff888040e71e50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{3:3}, at: filename_create+0x260/0x540 fs/namei.c:4026 #2: ffff888040e72418 (&ovl_i_mutex_key[depth]){+.+.}-{3:3}, at: inode_lock include/linux/fs.h:815 [inline] #2: ffff888040e72418 (&ovl_i_mutex_key[depth]){+.+.}-{3:3}, at: vfs_link+0x3b2/0x6e0 fs/namei.c:4730
#3: ffff888040e727d0 (&ovl_i_lock_key[depth]){+.+.}-{3:3}, at: ovl_inode_lock_interruptible fs/overlayfs/overlayfs.h:657 [inline] #3: ffff888040e727d0 (&ovl_i_lock_key[depth]){+.+.}-{3:3}, at: ovl_copy_up_start+0x53/0x310 fs/overlayfs/util.c:719 #4: ffff88804e256420 (sb_writers#11){.+.+}-{0:0}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:782 [inline] #4: ffff88804e256420 (sb_writers#11){.+.+}-{0:0}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1002 [inline] #4: ffff88804e256420 (sb_writers#11){.+.+}-{0:0}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1203 [inline] #4: ffff88804e256420 (sb_writers#11){.+.+}-{0:0}, at: ovl_copy_up_flags+0x18e9/0x46f0 fs/overlayfs/copy_up.c:1258 #5: ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: inode_lock include/linux/fs.h:815 [inline] #5: ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:783 [inline] #5: ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1002 [inline] #5: ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1203 [inline] #5: ffff888012facbf8 (&sb->s_type->i_mutex_key#19){++++}-{3:3}, at: ovl_copy_up_flags+0x1900/0x46f0 fs/overlayfs/copy_up.c:1258

stack backtrace:
CPU: 0 UID: 0 PID: 5107 Comm: syz.0.0 Not tainted 6.11.0-syzkaller-11728-gad46e8f95e93 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_deadlock_bug+0x483/0x620 kernel/locking/lockdep.c:3034
 check_deadlock kernel/locking/lockdep.c:3086 [inline]
 validate_chain+0x15e2/0x5920 kernel/locking/lockdep.c:3888
 __lock_acquire+0x1384/0x2050 kernel/locking/lockdep.c:5199
 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5822
 down_write+0x99/0x220 kernel/locking/rwsem.c:1579
 inode_lock include/linux/fs.h:815 [inline]
 bch2_symlink+0x176/0x310 fs/bcachefs/fs.c:700
 vfs_symlink+0x137/0x2e0 fs/namei.c:4615
 ovl_do_symlink+0x85/0xd0 fs/overlayfs/overlayfs.h:267
 ovl_create_real+0x346/0x550 fs/overlayfs/dir.c:206
 ovl_copy_up_workdir fs/overlayfs/copy_up.c:784 [inline]
 ovl_do_copy_up fs/overlayfs/copy_up.c:1002 [inline]
 ovl_copy_up_one fs/overlayfs/copy_up.c:1203 [inline]
 ovl_copy_up_flags+0x193c/0x46f0 fs/overlayfs/copy_up.c:1258
 ovl_link+0x85/0x320 fs/overlayfs/dir.c:716
 vfs_link+0x4f0/0x6e0 fs/namei.c:4739
 do_linkat+0x555/0x6f0 fs/namei.c:4809
 __do_sys_link fs/namei.c:4843 [inline]
 __se_sys_link fs/namei.c:4841 [inline]
 __x64_sys_link+0x82/0x90 fs/namei.c:4841
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f9772d7dff9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f9773bdf038 EFLAGS: 00000246 ORIG_RAX: 0000000000000056
RAX: ffffffffffffffda RBX: 00007f9772f36058 RCX: 00007f9772d7dff9
RDX: 0000000000000000 RSI: 0000000020000300 RDI: 0000000020000200
RBP: 00007f9772df0296 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007f9772f36058 R15: 00007fff2ceaaba8
 </TASK>

---
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 [email protected].

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

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

author syzbot
#1 lore raw
syzbot has found a reproducer for the following issue on:

syzbot has found a reproducer for the following issue on:

HEAD commit:    7ee983c850b4 Merge tag 'drm-fixes-2025-02-08' of https://g..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17375ca4580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=1909f2f0d8e641ce
dashboard link: https://syzkaller.appspot.com/bug?extid=7836a68852a10ec3d790
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14e0cca4580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=155361b0580000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7feb34a89c2a/non_bootable_disk-7ee983c8.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/f2f78699fc41/vmlinux-7ee983c8.xz
kernel image: https://storage.googleapis.com/syzbot-assets/ca55e6e8dd01/bzImage-7ee983c8.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/aa79c539b21d/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

bcachefs (loop0): reading snapshots table
bcachefs (loop0): reading snapshots done
bcachefs (loop0): done starting filesystem
============================================
WARNING: possible recursive locking detected
6.14.0-rc1-syzkaller-00181-g7ee983c850b4 #0 Not tainted
--------------------------------------------
syz-executor294/5305 is trying to acquire lock:
ffff888044775078 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] ffff888044775078 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: bch2_symlink+0x176/0x310 fs/bcachefs/fs.c:839

but task is already holding lock:
ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:782 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_flags+0x19cb/0x47c0 fs/overlayfs/copy_up.c:1257

other info that might help us debug this:

 Possible unsafe locking scenario:
       CPU0
       ----

lock(&sb->s_type->i_mutex_key#16);
lock(&sb->s_type->i_mutex_key#16);

*** DEADLOCK ***

May be due to missing lock nesting notation

7 locks held by syz-executor294/5305:
#0: ffff88801df94420 (sb_writers#10){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:547
#1: ffff88804470de50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:912 [inline] #1: ffff88804470de50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{4:4}, at: lock_rename fs/namei.c:3217 [inline] #1: ffff88804470de50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{4:4}, at: do_renameat2+0x62c/0x13f0 fs/namei.c:5161 #2: ffff88804470e418 (&ovl_i_mutex_key[depth]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] #2: ffff88804470e418 (&ovl_i_mutex_key[depth]){+.+.}-{4:4}, at: lock_two_nondirectories+0xe1/0x170 fs/inode.c:1281 #3: ffff88804470e9e0 (&ovl_i_mutex_key[depth]/4){+.+.}-{4:4}, at: vfs_rename+0x6a2/0xf00 fs/namei.c:5040
#4: ffff88804470e7d0 (&ovl_i_lock_key[depth]){+.+.}-{4:4}, at: ovl_inode_lock_interruptible fs/overlayfs/overlayfs.h:650 [inline] #4: ffff88804470e7d0 (&ovl_i_lock_key[depth]){+.+.}-{4:4}, at: ovl_copy_up_start+0x53/0x310 fs/overlayfs/util.c:727 #5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:781 [inline] #5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline]
#5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline] #5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_copy_up_flags+0x19b4/0x47c0 fs/overlayfs/copy_up.c:1257 #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:782 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_flags+0x19cb/0x47c0 fs/overlayfs/copy_up.c:1257

stack backtrace:
CPU: 0 UID: 0 PID: 5305 Comm: syz-executor294 Not tainted 6.14.0-rc1-syzkaller-00181-g7ee983c850b4 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_deadlock_bug+0x483/0x620 kernel/locking/lockdep.c:3039
 check_deadlock kernel/locking/lockdep.c:3091 [inline]
 validate_chain+0x15e2/0x5920 kernel/locking/lockdep.c:3893
 __lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5228
 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5851
 down_write+0x99/0x220 kernel/locking/rwsem.c:1577
 inode_lock include/linux/fs.h:877 [inline]
 bch2_symlink+0x176/0x310 fs/bcachefs/fs.c:839
 vfs_symlink+0x137/0x2e0 fs/namei.c:4671
 ovl_do_symlink+0x85/0xd0 fs/overlayfs/overlayfs.h:267
 ovl_create_real+0x346/0x550 fs/overlayfs/dir.c:206
 ovl_copy_up_workdir fs/overlayfs/copy_up.c:783 [inline]
 ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline]
 ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline]
 ovl_copy_up_flags+0x19fe/0x47c0 fs/overlayfs/copy_up.c:1257
 ovl_rename+0x62a/0x1760 fs/overlayfs/dir.c:1150
 vfs_rename+0xbdb/0xf00 fs/namei.c:5069
 do_renameat2+0xd94/0x13f0 fs/namei.c:5226
 __do_sys_rename fs/namei.c:5273 [inline]
 __se_sys_rename fs/namei.c:5271 [inline]
 __x64_sys_rename+0x82/0x90 fs/namei.c:5271
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f0d8dddad19
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 17 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:00007ffd9dbea2d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000052
RAX: ffffffffffffffda RBX: 0031656c69662f2e RCX: 00007f0d8dddad19
RDX: 00007f0d8dddad19 RSI: 0000400000000840 RDI: 0000400000000800
RBP: 0031656c69662f2e R08: 000055558454d4c0 R09: 000055558454d4c0
R10: 000055558454d4c0 R11: 0000000000000246 R12: 00007ffd9dbea300
R13: 00007ffd9dbea528 R14: 431bde82d7b634db R15: 00007f0d8de2303b
 </TASK>

syz-executor294 (5305) used greatest stack depth: 10768 bytes left

---
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.

#2 lore raw

+cc overlayfs

Quoted 120 lines · syzbot

syzbot has found a reproducer for the following issue on:

HEAD commit:    7ee983c850b4 Merge tag 'drm-fixes-2025-02-08' of https://g..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17375ca4580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=1909f2f0d8e641ce
dashboard link: https://syzkaller.appspot.com/bug?extid=7836a68852a10ec3d790
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14e0cca4580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=155361b0580000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7feb34a89c2a/non_bootable_disk-7ee983c8.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/f2f78699fc41/vmlinux-7ee983c8.xz
kernel image: https://storage.googleapis.com/syzbot-assets/ca55e6e8dd01/bzImage-7ee983c8.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/aa79c539b21d/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

bcachefs (loop0): reading snapshots table
bcachefs (loop0): reading snapshots done
bcachefs (loop0): done starting filesystem
============================================
WARNING: possible recursive locking detected
6.14.0-rc1-syzkaller-00181-g7ee983c850b4 #0 Not tainted
--------------------------------------------
syz-executor294/5305 is trying to acquire lock:
ffff888044775078 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] ffff888044775078 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: bch2_symlink+0x176/0x310 fs/bcachefs/fs.c:839

but task is already holding lock:
ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:782 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline] ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_flags+0x19cb/0x47c0 fs/overlayfs/copy_up.c:1257

other info that might help us debug this:

Possible unsafe locking scenario:
      CPU0
      ----

lock(&sb->s_type->i_mutex_key#16);
lock(&sb->s_type->i_mutex_key#16);

*** DEADLOCK ***

May be due to missing lock nesting notation

7 locks held by syz-executor294/5305:
#0: ffff88801df94420 (sb_writers#10){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:547
#1: ffff88804470de50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:912 [inline] #1: ffff88804470de50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{4:4}, at: lock_rename fs/namei.c:3217 [inline] #1: ffff88804470de50 (&ovl_i_mutex_dir_key[depth]/1){+.+.}-{4:4}, at: do_renameat2+0x62c/0x13f0 fs/namei.c:5161 #2: ffff88804470e418 (&ovl_i_mutex_key[depth]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] #2: ffff88804470e418 (&ovl_i_mutex_key[depth]){+.+.}-{4:4}, at: lock_two_nondirectories+0xe1/0x170 fs/inode.c:1281 #3: ffff88804470e9e0 (&ovl_i_mutex_key[depth]/4){+.+.}-{4:4}, at: vfs_rename+0x6a2/0xf00 fs/namei.c:5040
#4: ffff88804470e7d0 (&ovl_i_lock_key[depth]){+.+.}-{4:4}, at: ovl_inode_lock_interruptible fs/overlayfs/overlayfs.h:650 [inline] #4: ffff88804470e7d0 (&ovl_i_lock_key[depth]){+.+.}-{4:4}, at: ovl_copy_up_start+0x53/0x310 fs/overlayfs/util.c:727 #5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:781 [inline] #5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline]
#5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline] #5: ffff8880477b0420 (sb_writers#9){.+.+}-{0:0}, at: ovl_copy_up_flags+0x19b4/0x47c0 fs/overlayfs/copy_up.c:1257 #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: inode_lock include/linux/fs.h:877 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_workdir fs/overlayfs/copy_up.c:782 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline] #6: ffff888044774148 (&sb->s_type->i_mutex_key#16){++++}-{4:4}, at: ovl_copy_up_flags+0x19cb/0x47c0 fs/overlayfs/copy_up.c:1257

stack backtrace:
CPU: 0 UID: 0 PID: 5305 Comm: syz-executor294 Not tainted 6.14.0-rc1-syzkaller-00181-g7ee983c850b4 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
print_deadlock_bug+0x483/0x620 kernel/locking/lockdep.c:3039
check_deadlock kernel/locking/lockdep.c:3091 [inline]
validate_chain+0x15e2/0x5920 kernel/locking/lockdep.c:3893
__lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5228
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5851
down_write+0x99/0x220 kernel/locking/rwsem.c:1577
inode_lock include/linux/fs.h:877 [inline]
bch2_symlink+0x176/0x310 fs/bcachefs/fs.c:839
vfs_symlink+0x137/0x2e0 fs/namei.c:4671
ovl_do_symlink+0x85/0xd0 fs/overlayfs/overlayfs.h:267
ovl_create_real+0x346/0x550 fs/overlayfs/dir.c:206
ovl_copy_up_workdir fs/overlayfs/copy_up.c:783 [inline]
ovl_do_copy_up fs/overlayfs/copy_up.c:1001 [inline]
ovl_copy_up_one fs/overlayfs/copy_up.c:1202 [inline]
ovl_copy_up_flags+0x19fe/0x47c0 fs/overlayfs/copy_up.c:1257
ovl_rename+0x62a/0x1760 fs/overlayfs/dir.c:1150
vfs_rename+0xbdb/0xf00 fs/namei.c:5069
do_renameat2+0xd94/0x13f0 fs/namei.c:5226
__do_sys_rename fs/namei.c:5273 [inline]
__se_sys_rename fs/namei.c:5271 [inline]
__x64_sys_rename+0x82/0x90 fs/namei.c:5271
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f0d8dddad19
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 17 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:00007ffd9dbea2d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000052
RAX: ffffffffffffffda RBX: 0031656c69662f2e RCX: 00007f0d8dddad19
RDX: 00007f0d8dddad19 RSI: 0000400000000840 RDI: 0000400000000800
RBP: 0031656c69662f2e R08: 000055558454d4c0 R09: 000055558454d4c0
R10: 000055558454d4c0 R11: 0000000000000246 R12: 00007ffd9dbea300
R13: 00007ffd9dbea528 R14: 431bde82d7b634db R15: 00007f0d8de2303b
</TASK>

syz-executor294 (5305) used greatest stack depth: 10768 bytes left

---
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.

#3 lore raw
Quoted 1 line · Alan Huang

+cc overlayfs

Sigh...

1) ovl_copy_up_workdir() should lock wdir with I_MUTEX_PARENT, same as filename_create().

2) what the hell is bch2_symlink() need to lock the new inode for? page_symlink() doesn't need that; are there any bcachefs-specific reasons to bother with that?

#4 lore raw
Quoted 8 lines · Al Viro
Quoted 1 line · Alan Huang

+cc overlayfs

Sigh...

2) what the hell is bch2_symlink() need to lock the new inode for? page_symlink() doesn't need that; are there any bcachefs-specific reasons to bother with that?

No, there isn't. I'll look it over and kill that tomorrow...

author syzbot Tested-by
#6 lore raw
syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Tested on:

commit:         9e7e7e36 ovl: use I_MUTEX_PARENT when locking parent i..
git tree:       https://github.com/amir73il/linux ovl-fixes
console output: https://syzkaller.appspot.com/x/log.txt?x=11d09ba2580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=41498776bd40da1
dashboard link: https://syzkaller.appspot.com/bug?extid=7836a68852a10ec3d790
compiler:       Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7

Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.