2024-05-23 10:09:44

by syzbot

[permalink] [raw]
Subject: [syzbot] [btrfs?] [overlayfs?] possible deadlock in ovl_copy_up_flags

Hello,

syzbot found the following issue on:

HEAD commit: c75962170e49 Add linux-next specific files for 20240517
git tree: linux-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=1438a5cc980000
kernel config: https://syzkaller.appspot.com/x/.config?x=fba88766130220e8
dashboard link: https://syzkaller.appspot.com/bug?extid=85e58cdf5b3136471d4b
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=115f3e58980000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14f4c97c980000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/21696f8048a3/disk-c7596217.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/b8c71f928633/vmlinux-c7596217.xz
kernel image: https://storage.googleapis.com/syzbot-assets/350bfc6c0a6a/bzImage-c7596217.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/7f6a8434331c/mount_0.gz

The issue was bisected to:

commit 9a87907de3597a339cc129229d1a20bc7365ea5f
Author: Miklos Szeredi <[email protected]>
Date: Thu May 2 18:35:57 2024 +0000

ovl: implement tmpfile

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=120f89cc980000
final oops: https://syzkaller.appspot.com/x/report.txt?x=110f89cc980000
console output: https://syzkaller.appspot.com/x/log.txt?x=160f89cc980000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email protected]
Fixes: 9a87907de359 ("ovl: implement tmpfile")

============================================
WARNING: possible recursive locking detected
6.9.0-next-20240517-syzkaller #0 Not tainted
--------------------------------------------
syz-executor489/5091 is trying to acquire lock:
ffff88802f7f2420 (sb_writers#4){.+.+}-{0:0}, at: ovl_do_copy_up fs/overlayfs/copy_up.c:967 [inline]
ffff88802f7f2420 (sb_writers#4){.+.+}-{0:0}, at: ovl_copy_up_one fs/overlayfs/copy_up.c:1168 [inline]
ffff88802f7f2420 (sb_writers#4){.+.+}-{0:0}, at: ovl_copy_up_flags+0x1110/0x4470 fs/overlayfs/copy_up.c:1223

but task is already holding lock:
ffff88802f7f2420 (sb_writers#4){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:409

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

CPU0
----
lock(sb_writers#4);
lock(sb_writers#4);

*** DEADLOCK ***

May be due to missing lock nesting notation

3 locks held by syz-executor489/5091:
#0: ffff8880241fe420 (sb_writers#9){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:409
#1: ffff88802f7f2420 (sb_writers#4){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:409
#2: ffff88807f0ea808 (&ovl_i_lock_key[depth]){+.+.}-{3:3}, at: ovl_inode_lock_interruptible fs/overlayfs/overlayfs.h:657 [inline]
#2: ffff88807f0ea808 (&ovl_i_lock_key[depth]){+.+.}-{3:3}, at: ovl_copy_up_start+0x53/0x310 fs/overlayfs/util.c:719

stack backtrace:
CPU: 1 PID: 5091 Comm: syz-executor489 Not tainted 6.9.0-next-20240517-syzkaller #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+0x241/0x360 lib/dump_stack.c:114
check_deadlock kernel/locking/lockdep.c:3062 [inline]
validate_chain+0x15c1/0x58e0 kernel/locking/lockdep.c:3856
__lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754
percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
__sb_start_write include/linux/fs.h:1655 [inline]
sb_start_write include/linux/fs.h:1791 [inline]
ovl_start_write+0x11d/0x290 fs/overlayfs/util.c:31
ovl_do_copy_up fs/overlayfs/copy_up.c:967 [inline]
ovl_copy_up_one fs/overlayfs/copy_up.c:1168 [inline]
ovl_copy_up_flags+0x1110/0x4470 fs/overlayfs/copy_up.c:1223
ovl_create_tmpfile fs/overlayfs/dir.c:1317 [inline]
ovl_tmpfile+0x262/0x6d0 fs/overlayfs/dir.c:1373
vfs_tmpfile+0x396/0x510 fs/namei.c:3701
do_tmpfile+0x156/0x340 fs/namei.c:3764
path_openat+0x2ab8/0x3280 fs/namei.c:3798
do_filp_open+0x235/0x490 fs/namei.c:3834
do_sys_openat2+0x13e/0x1d0 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+0x225/0x270 fs/open.c:1424
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fab92feaba9
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:00007ffd714aed18 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 0030656c69662f2e RCX: 00007fab92feaba9
RDX: 0000000000000000 RSI: 0000000000410202 RDI: 0000000020000040
RBP: 00007fab930635f0 R08: 000055557e7894c0 R09: 000055557e7894c0
R10: 000055557e7894c0 R11: 0000000000000246 R12: 00007ffd714aed40
R13: 00007ffd714aef68 R14: 431bde82d7b634db R15: 00007fab9303303b
</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.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection

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

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.

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


2024-05-23 16:43:34

by David Sterba

[permalink] [raw]
Subject: Re: [syzbot] [btrfs?] [overlayfs?] possible deadlock in ovl_copy_up_flags

On Thu, May 23, 2024 at 03:09:26AM -0700, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: c75962170e49 Add linux-next specific files for 20240517
> git tree: linux-next
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=1438a5cc980000
> kernel config: https://syzkaller.appspot.com/x/.config?x=fba88766130220e8
> dashboard link: https://syzkaller.appspot.com/bug?extid=85e58cdf5b3136471d4b
> 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=115f3e58980000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14f4c97c980000
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/21696f8048a3/disk-c7596217.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/b8c71f928633/vmlinux-c7596217.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/350bfc6c0a6a/bzImage-c7596217.xz
> mounted in repro: https://storage.googleapis.com/syzbot-assets/7f6a8434331c/mount_0.gz
>
> The issue was bisected to:
>
> commit 9a87907de3597a339cc129229d1a20bc7365ea5f
> Author: Miklos Szeredi <[email protected]>
> Date: Thu May 2 18:35:57 2024 +0000
>
> ovl: implement tmpfile

In the C reproducer it's btrfs + overlayfs, this more looks like a bug in
overlayfs handling the tmpfile and sb_*_write accross layers. Btrfs
functions are not on the stack.

#syz set subsystems: overlayfs

2024-05-27 13:51:22

by Miklos Szeredi

[permalink] [raw]
Subject: Re: [syzbot] [btrfs?] [overlayfs?] possible deadlock in ovl_copy_up_flags

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git
f74ee925761ead1a07a5e42e1cb1f2d59ab75b8c

2024-05-27 21:36:18

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] [overlayfs] possible deadlock in ovl_copy_up_flags

Hello,

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

Reported-and-tested-by: [email protected]

Tested on:

commit: f74ee925 ovl: tmpfile copy-up fix
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git
console output: https://syzkaller.appspot.com/x/log.txt?x=142c4e2c980000
kernel config: https://syzkaller.appspot.com/x/.config?x=b9016f104992d69c
dashboard link: https://syzkaller.appspot.com/bug?extid=85e58cdf5b3136471d4b
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

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