io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
Jens Axboe
maintainerPATCH 1/1 io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
The issue_flags will tell us if this is needed or not, however a previous commit was a bit too eager with the cleanups and removed the required locking in case IO_URING_F_UNLOCKED is set in the issue_flags.
---
io_uring/kbuf.h +7 -1
@@ -4,6 +4,7 @@#include <uapi/linux/io_uring.h> #include <linux/io_uring_types.h> +#include "io_uring.h" enum {/* ring mapped provided buffers */
@@ -124,9 +125,14 @@ static inline bool io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)static inline unsigned int io_put_kbuf (struct io_kiocb *req,int len,unsigned issue_flags) { +int ret; +if (!(req->flags & (REQ_F_BUFFER_RING |REQ_F_BUFFER_SELECTED )))return 0 ; -return __io_put_kbufs (req, len,1 ); +io_ring_submit_lock (req->ctx, issue_flags); + ret =__io_put_kbufs (req, len,1 ); +io_ring_submit_unlock (req->ctx, issue_flags); +return ret; } static inline unsigned int io_put_kbufs(struct io_kiocb *req, int len,
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 3 lines · Jens Axboe
The
issue_flagswill tell us if this is needed or not, however a previous commit was a bit too eager with the cleanups and removed the required locking in caseIO_URING_F_UNLOCKEDis set in theissue_flags.
Actually, disregard that one - on closer inspection, it doesn't matter anymore. On the legacy side, it's just being freed. For ring buffers, they would already have been committed.
Signature · 1 line
Jens Axboe
syzbot ci has tested the following series
syzbot ci has tested the following series
[v1] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
https://lore.kernel.org/all/[email protected]
* [PATCH] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
and found the following issue:
possible deadlock in io_req_defer_failed
Full report is available here:
https://ci.syzbot.org/series/fd113bf0-fc76-46b7-8c0b-08fa3c8bda14
***
possible deadlock in io_req_defer_failed
tree: torvalds URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux base: dfc0f6373094dd88e1eaf76c44f2ff01b65db851 arch: amd64 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 config: https://ci.syzbot.org/builds/e832762c-b6ee-4bb3-b01f-da0e8f70d1d0/config C repro: https://ci.syzbot.org/findings/57691bf2-072c-42f3-8742-80414426104c/c_repro syz repro: https://ci.syzbot.org/findings/57691bf2-072c-42f3-8742-80414426104c/syz_repro
============================================
WARNING: possible recursive locking detected
syzkaller #0 Not tainted
--------------------------------------------
syz.0.17/6012 is trying to acquire lock:ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: io_ring_submit_lock io_uring/io_uring.h:287 [inline] ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: io_put_kbuf io_uring/kbuf.h:132 [inline] ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: io_req_defer_failed+0x166/0x550 io_uring/io_uring.c:988
but task is already holding lock:ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: __do_sys_io_uring_enter io_uring/io_uring.c:3463 [inline] ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: __se_sys_io_uring_enter+0x2d4/0x2b20 io_uring/io_uring.c:3398
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(&ctx->uring_lock);
lock(&ctx->uring_lock);
*** DEADLOCK ***
May be due to missing lock nesting notation
1 lock held by syz.0.17/6012:
#0: ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: __do_sys_io_uring_enter io_uring/io_uring.c:3463 [inline] #0: ffff88802aa620a8 (&ctx->uring_lock){+.+.}-{4:4}, at: __se_sys_io_uring_enter+0x2d4/0x2b20 io_uring/io_uring.c:3398
stack backtrace: CPU: 0 UID: 0 PID: 6012 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120 print_deadlock_bug+0x28b/0x2a0 kernel/locking/lockdep.c:3041 check_deadlock kernel/locking/lockdep.c:3093 [inline] validate_chain+0x1a3f/0x2140 kernel/locking/lockdep.c:3895 __lock_acquire+0xab9/0xd20 kernel/locking/lockdep.c:5237 lock_acquire+0x120/0x360 kernel/locking/lockdep.c:5868 __mutex_lock_common kernel/locking/mutex.c:598 [inline] __mutex_lock+0x187/0x1360 kernel/locking/mutex.c:760 io_ring_submit_lock io_uring/io_uring.h:287 [inline] io_put_kbuf io_uring/kbuf.h:132 [inline] io_req_defer_failed+0x166/0x550 io_uring/io_uring.c:988 io_queue_sqe io_uring/io_uring.c:2032 [inline] io_submit_sqe io_uring/io_uring.c:2284 [inline] io_submit_sqes+0xe28/0x1d10 io_uring/io_uring.c:2397 __do_sys_io_uring_enter io_uring/io_uring.c:3464 [inline] __se_sys_io_uring_enter+0x2df/0x2b20 io_uring/io_uring.c:3398 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f36d418ebe9 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:00007ffc1d32a978 EFLAGS: 00000246 ORIG_RAX: 00000000000001aa RAX: ffffffffffffffda RBX: 00007f36d43b5fa0 RCX: 00007f36d418ebe9 RDX: 0000000000000000 RSI: 0000000000003516 RDI: 0000000000000003 RBP: 00007f36d4211e19 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f36d43b5fa0 R14: 00007f36d43b5fa0 R15: 0000000000000006 </TASK>
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].