* [PATCH] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
@ 2025-08-20 23:16 Jens Axboe
2025-08-21 0:31 ` Jens Axboe
2025-08-21 6:54 ` [syzbot ci] " syzbot ci
0 siblings, 2 replies; 3+ messages in thread
From: Jens Axboe @ 2025-08-20 23:16 UTC (permalink / raw)
To: io-uring; +Cc: Pavel Begunkov
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.
Cc: stable@vger.kernel.org
Fixes: e150e70fce42 ("io_uring/kbuf: open code __io_put_kbuf()")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
diff --git a/io_uring/kbuf.h b/io_uring/kbuf.h
index 723d0361898e..7f17e87d8617 100644
--- a/io_uring/kbuf.h
+++ b/io_uring/kbuf.h
@@ -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,
--
Jens Axboe
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
2025-08-20 23:16 [PATCH] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf() Jens Axboe
@ 2025-08-21 0:31 ` Jens Axboe
2025-08-21 6:54 ` [syzbot ci] " syzbot ci
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-08-21 0:31 UTC (permalink / raw)
To: io-uring; +Cc: Pavel Begunkov
On 8/20/25 5:16 PM, Jens Axboe wrote:
> 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.
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.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* [syzbot ci] Re: io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf()
2025-08-20 23:16 [PATCH] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf() Jens Axboe
2025-08-21 0:31 ` Jens Axboe
@ 2025-08-21 6:54 ` syzbot ci
1 sibling, 0 replies; 3+ messages in thread
From: syzbot ci @ 2025-08-21 6:54 UTC (permalink / raw)
To: asml.silence, axboe, io-uring; +Cc: syzbot, syzkaller-bugs
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/e2f14b20-2ad4-4e59-9966-26dd6aa70f31@kernel.dk
* [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:
Tested-by: syzbot@syzkaller.appspotmail.com
---
This report is generated by a bot. It may contain errors.
syzbot ci engineers can be reached at syzkaller@googlegroups.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-21 6:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-20 23:16 [PATCH] io_uring/kbuf: ensure ring ctx is held locked over io_put_kbuf() Jens Axboe
2025-08-21 0:31 ` Jens Axboe
2025-08-21 6:54 ` [syzbot ci] " syzbot ci
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).