syzbot


possible deadlock in io_uring_register

Status: fixed on 2021/11/10 00:50
Subsystems: fs
[Documentation on labels]
Reported-by: syzbot+97fa56483f69d677969f@syzkaller.appspotmail.com
Fix commit: 009ad9f0c6ee io_uring: drop ctx->uring_lock before acquiring sqd->lock
First crash: 1201d, last: 1198d
Duplicate bugs (1)
duplicates (1):
Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
possible deadlock in io_sq_thread fs io-uring C 11 1198d 1200d 0/28 closed as dup on 2021/09/09 01:02
Discussions (2)
Title Replies (including bot) Last reply
[syzbot] possible deadlock in io_uring_register 1 (2) 2021/09/09 02:01
[PATCH] io_uring: drop ctx->uring_lock before acquiring sqd->lock 1 (1) 2021/09/09 01:10

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.14.0-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.0/30511 is trying to acquire lock:
ffff88807abb0c70 (&sqd->lock){+.+.}-{3:3}, at: io_register_iowq_max_workers fs/io_uring.c:10553 [inline]
ffff88807abb0c70 (&sqd->lock){+.+.}-{3:3}, at: __io_uring_register fs/io_uring.c:10759 [inline]
ffff88807abb0c70 (&sqd->lock){+.+.}-{3:3}, at: __do_sys_io_uring_register+0x10aa/0x2e70 fs/io_uring.c:10794

but task is already holding lock:
ffff8880199040a8 (&ctx->uring_lock){+.+.}-{3:3}, at: __do_sys_io_uring_register+0x2e1/0x2e70 fs/io_uring.c:10793

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&ctx->uring_lock){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:596 [inline]
       __mutex_lock+0x131/0x12f0 kernel/locking/mutex.c:729
       __io_sq_thread fs/io_uring.c:7293 [inline]
       io_sq_thread+0x65a/0x1370 fs/io_uring.c:7370
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

-> #0 (&sqd->lock){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3051 [inline]
       check_prevs_add kernel/locking/lockdep.c:3174 [inline]
       validate_chain kernel/locking/lockdep.c:3789 [inline]
       __lock_acquire+0x2a07/0x54a0 kernel/locking/lockdep.c:5015
       lock_acquire kernel/locking/lockdep.c:5625 [inline]
       lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5590
       __mutex_lock_common kernel/locking/mutex.c:596 [inline]
       __mutex_lock+0x131/0x12f0 kernel/locking/mutex.c:729
       io_register_iowq_max_workers fs/io_uring.c:10553 [inline]
       __io_uring_register fs/io_uring.c:10759 [inline]
       __do_sys_io_uring_register+0x10aa/0x2e70 fs/io_uring.c:10794
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&ctx->uring_lock);
                               lock(&sqd->lock);
                               lock(&ctx->uring_lock);
  lock(&sqd->lock);

 *** DEADLOCK ***

1 lock held by syz-executor.0/30511:
 #0: ffff8880199040a8 (&ctx->uring_lock){+.+.}-{3:3}, at: __do_sys_io_uring_register+0x2e1/0x2e70 fs/io_uring.c:10793

stack backtrace:
CPU: 0 PID: 30511 Comm: syz-executor.0 Not tainted 5.14.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2131
 check_prev_add kernel/locking/lockdep.c:3051 [inline]
 check_prevs_add kernel/locking/lockdep.c:3174 [inline]
 validate_chain kernel/locking/lockdep.c:3789 [inline]
 __lock_acquire+0x2a07/0x54a0 kernel/locking/lockdep.c:5015
 lock_acquire kernel/locking/lockdep.c:5625 [inline]
 lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5590
 __mutex_lock_common kernel/locking/mutex.c:596 [inline]
 __mutex_lock+0x131/0x12f0 kernel/locking/mutex.c:729
 io_register_iowq_max_workers fs/io_uring.c:10553 [inline]
 __io_uring_register fs/io_uring.c:10759 [inline]
 __do_sys_io_uring_register+0x10aa/0x2e70 fs/io_uring.c:10794
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x4665f9
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 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fe0dee3c188 EFLAGS: 00000246 ORIG_RAX: 00000000000001ab
RAX: ffffffffffffffda RBX: 000000000056bf80 RCX: 00000000004665f9
RDX: 0000000020004000 RSI: 0000000000000013 RDI: 0000000000000003
RBP: 00000000004bfcc4 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000002 R11: 0000000000000246 R12: 000000000056bf80
R13: 0000000000a9fb1f R14: 00007fe0dee3c300 R15: 0000000000022000

Crashes (16):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2021/09/11 05:22 upstream 926de8c4326c 5ae8508a .config console log report info ci-upstream-kasan-gce possible deadlock in io_uring_register
2021/09/10 12:53 upstream bf9f243f23e6 5ae8508a .config console log report info ci-upstream-kasan-gce-selinux-root possible deadlock in io_uring_register
2021/09/10 12:52 upstream bf9f243f23e6 5ae8508a .config console log report info ci-upstream-kasan-gce-smack-root possible deadlock in io_uring_register
2021/09/10 11:21 upstream bf9f243f23e6 5ae8508a .config console log report info ci-upstream-kasan-gce-selinux-root possible deadlock in io_uring_register
2021/09/10 06:02 upstream bf9f243f23e6 e2776ee4 .config console log report info ci-upstream-kasan-gce-root possible deadlock in io_uring_register
2021/09/09 17:47 upstream a3fa7a101dcf e2776ee4 .config console log report info ci-upstream-kasan-gce possible deadlock in io_uring_register
2021/09/09 15:29 upstream a3fa7a101dcf e2776ee4 .config console log report info ci-upstream-kasan-gce-root possible deadlock in io_uring_register
2021/09/09 07:06 upstream 2d338201d531 e2776ee4 .config console log report info ci-upstream-kasan-gce-smack-root possible deadlock in io_uring_register
2021/09/09 07:05 upstream 2d338201d531 e2776ee4 .config console log report info ci-upstream-kasan-gce-smack-root possible deadlock in io_uring_register
2021/09/09 07:05 upstream 730bf31b8fc8 e2776ee4 .config console log report info ci-upstream-kasan-gce-root possible deadlock in io_uring_register
2021/09/09 06:56 upstream 0f4b9289bad3 e2776ee4 .config console log report info ci-upstream-kasan-gce possible deadlock in io_uring_register
2021/09/08 15:00 upstream ac08b1c68d1b e2776ee4 .config console log report info ci-upstream-kasan-gce-selinux-root possible deadlock in io_uring_register
2021/09/08 13:56 upstream ac08b1c68d1b e2776ee4 .config console log report info ci-upstream-kasan-gce-root possible deadlock in io_uring_register
2021/09/08 05:32 upstream a2b28235335f 064c9eb7 .config console log report info ci-upstream-kasan-gce possible deadlock in io_uring_register
2021/09/08 00:01 upstream a2b28235335f 064c9eb7 .config console log report info ci-upstream-kasan-gce-root possible deadlock in io_uring_register
2021/09/08 11:37 linux-next 999569d59a0a e2776ee4 .config console log report info ci-upstream-linux-next-kasan-gce-root possible deadlock in io_uring_register
* Struck through repros no longer work on HEAD.