* [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable
@ 2026-12-05 23:10 Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
Hi Greg,
Here are 15 io_uring patches for 6.12-stable. Patches 1, 2, 3, 6, 7, 10,
11 and 12 went to Linus in io_uring-7.4-20261127, merge commit
7cd8495c0f16 ("Merge tag 'io_uring-7.4-20261127' of
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux"). Patches 14
and 15 went in io_uring-7.4-20261205, merge commit 29217cb8ce52 ("Merge
tag 'io_uring-7.4-20261205' of
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux").
Patches 4, 5, 8, 9 and 13 are older mainline commits, backported because
the fixes are written on top of them: 4 (v6.19) and 5 (v7.4-rc1, Fixes:
4) for 6, which needs ctx->tctx_lock; 8 (v6.13) and 9 (v6.13, Fixes: 8)
for 10, which needs the raw timeout_lock; 13 (v6.13) for 14, which is
written for io_uring_poll() without the smp_rmb().
The series applies on top of v6.12.120 plus queue-6.12 at stable-queue
commit 16dfa5cc8e2f. It also applies to v6.12.120 alone.
Patches 4, 5, 8, 9, 10, 14 and 15 needed changes for 6.12. The
[axboe: ...] note at the end of each says what was changed and why. The
rest are the upstream changes as they are.
Please take these together, in this order: 4-6; 8-10; 13 and 14.
Testing: the liburing test suite (liburing-2.15-76-ged312b3c) was
run in KVM guests with PROVE_LOCKING and PROVE_RAW_LOCK_NESTING on
two kernels: v6.12.120, and v6.12.120 plus these patches. The patched
kernel fails exactly the tests that v6.12.120 fails (napi-test times
out; io-wq-unused-exit, read-mshot, read-mshot-fuse, ringbuf-read,
send-zerocopy, timestamp and waitid fail), all from the test
environment. No WARNING, BUG, lockdep or KASAN report in dmesg on
either kernel. io_uring/ builds without warnings on v6.12.120 plus
queue-6.12 plus this series.
CVE assessment, by the io_uring maintainer:
Should get a CVE:
3/15 io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
6/15 io_uring: free the ring after a grace period
7/15 io_uring/filetable: don't install O_PATH files
10/15 io_uring/cancel: always walk links under timeout_lock
11/15 io_uring/net: don't count the buffers of a send bundle
12/15 io_uring/net: restore the cmsg buffer on recvmsg retry
Should not get a CVE:
1/15 io_uring/net: don't charge the folio offset to truesize for
managed frags
Overcharges skb truesize on the sender's own socket; a
performance bug.
2/15 io_uring/net: don't copy msg_name on a recvmsg retry
Writes past msg_name, in the caller's own user memory only.
4/15 io_uring/tctx: add separate lock for list of tctx's in ctx
prep for 6/15
5/15 io_uring: free the task context after a grace period
Fixes 4/15 of this series, no release has the bug.
8/15 io_uring: make ctx->timeout_lock a raw spinlock
prep for 10/15
9/15 io_uring/timeout: flush timeouts outside of the timeout lock
Fixes 8/15 of this series, no release has the bug.
13/15 io_uring_poll: kill the no longer necessary barrier after
poll_wait()
prep for 14/15
14/15 io_uring: close poll activation race when enabling rings
Missed poll wakeup on the app's own ring.
15/15 io_uring/cancel: arm local work wakeups only for submitter
Early or spurious wakeups of the submitter, no crash in this
tree.
Andrea Parri (2):
io_uring: close poll activation race when enabling rings
io_uring/cancel: arm local work wakeups only for submitter
Chris Mason (8):
io_uring/net: don't copy msg_name on a recvmsg retry
io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
io_uring: free the task context after a grace period
io_uring: free the ring after a grace period
io_uring/filetable: don't install O_PATH files
io_uring/cancel: always walk links under timeout_lock
io_uring/net: don't count the buffers of a send bundle
io_uring/net: restore the cmsg buffer on recvmsg retry
Jens Axboe (3):
io_uring/tctx: add separate lock for list of tctx's in ctx
io_uring: make ctx->timeout_lock a raw spinlock
io_uring/timeout: flush timeouts outside of the timeout lock
Louis Thiery (1):
io_uring/net: don't charge the folio offset to truesize for managed
frags
Oleg Nesterov (1):
io_uring_poll: kill the no longer necessary barrier after poll_wait()
include/linux/io_uring_types.h | 15 +++++-
io_uring/cancel.c | 3 ++
io_uring/filetable.c | 3 ++
io_uring/io_uring.c | 50 +++++++++++--------
io_uring/kbuf.c | 3 ++
io_uring/net.c | 27 ++++++++---
io_uring/register.c | 2 +
io_uring/tctx.c | 13 +++--
io_uring/timeout.c | 87 ++++++++++++++++++++--------------
9 files changed, 134 insertions(+), 69 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Louis Thiery <thiery.louis@gmail.com>
Commit aaa55c8ff9147b1ce1ba50267aa9f080d469a963 upstream.
Registered buffers backed by huge pages are coalesced into one bvec per
folio, so bv_offset is relative to the folio, not to a 4K page.
io_sg_from_iter() adds PAGE_ALIGN(bv_len + bv_offset) to the skb
truesize, which charges the socket for the whole run-up inside the
folio. A 64K send from 1.5MB into a 2MB THP folio adds about 1.6MB of
truesize, and sk_wmem_queued fills long before any real memory is used.
The visible effect is a socket that looks full: with a 2MB send buffer
only 4 of 128 queued 64K sends complete before the sender blocks,
versus 30 of 128 with the same buffer registered as 4K pages, and most
pipelined send_zc requests come back short.
Only the in-page part of the offset matters for how much memory a
fragment ties up, so use offset_in_page(). This matches what
zerocopy_fill_skb_from_iter() charges for the same data.
Fixes: 57bebf807e2a ("io_uring/rsrc: optimise registered huge pages")
Cc: stable@vger.kernel.org
Signed-off-by: Louis Thiery <thiery.louis@gmail.com>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Reported-by: Brian Martin <brayniac@gmail.com>
Closes: https://lore.kernel.org/io-uring/CAC+fX10wVVSqGnfCg+aazorsCxB34sUDV-XJiBPd6R3Kuqc-7Q@mail.gmail.com/
Tested-by: Brian Martin <brayniac@gmail.com>
Link: https://patch.msgid.link/20261119232935.1708458-1-thiery.louis@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/net.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index c6512064bdda..53773b0d5276 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1414,7 +1414,12 @@ static int io_sg_from_iter(struct sk_buff *skb,
struct bio_vec v = mp_bvec_iter_bvec(from->bvec, bi);
copied += v.bv_len;
- truesize += PAGE_ALIGN(v.bv_len + v.bv_offset);
+ /*
+ * bv_offset is relative to the folio for coalesced huge page
+ * registrations, so only the in-page part of it matters for
+ * how much memory this fragment ties up.
+ */
+ truesize += PAGE_ALIGN(v.bv_len + offset_in_page(v.bv_offset));
__skb_fill_page_desc_noacc(shinfo, frag++, v.bv_page,
v.bv_offset, v.bv_len);
bvec_iter_advance_single(from->bvec, &bi, v.bv_len);
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit bbdf19889585f036692a0c77a1402a37cf07c417 upstream.
IORING_OP_RECVMSG with MSG_WAITALL can write past the end of the user's
msg_name buffer, if a partial receive is retried and the source address
is longer than the buffer.
msg_namelen is an in/out field: move_addr_to_user() reads the size of
the buffer from it, and then stores the untruncated length of the
address there. So the size is valid for one call to ____sys_recvmsg()
only. But io_recvmsg() passes the same umsg and uaddr again when it
retries a partial receive, and nothing restores msg_namelen in between:
msg_namelen = 16, AF_UNIX source address of 110 bytes
size read bytes copied msg_namelen stored
receive 1 16 16 110
receive 2 110 110 110
If the copy in the retry faults, the result of the request lacks the
data that the retry took off the socket. A retry that hits EOF has no
address, so it stores a msg_namelen of 0 while the buffer holds the
address. And an address that is longer than the one before it is
truncated to the length of the one before.
The fix used here is to copy the address out with the first part of the
data only, and to leave msg_name and msg_namelen alone in the retries.
The address is now that of the first part of the data and no longer that
of the last part. The two differ only if the source address changes
within one request: on an unconnected SOCK_SEQPACKET socket that
receives from several peers, or if an AF_UNIX peer binds between two
parts. A program that passes a msg_namelen smaller than its buffer got
the whole address from the second receive on, and now gets the truncated
address, as from recvmsg(2).
The retries also no longer reach audit_sockaddr(), so with an audit rule
for IORING_OP_RECVMSG the event of the retry that completes the request
can lack its SOCKADDR record. The event that keeps the record is that of
the first partial receive, which audit logs as failed with -EAGAIN.
Fixes: 7ba89d2af17a ("io_uring: ensure recv and recvmsg handle MSG_WAITALL correctly")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/net.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/io_uring/net.c b/io_uring/net.c
index 53773b0d5276..cc92e892fb53 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1108,6 +1108,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
if (ret > 0 && io_net_retry(sock, flags) &&
io_net_kbuf_can_retry(req, sel.buf_list, kmsg)) {
sr->done_io += ret;
+ /* msg_name and msg_namelen are filled in, leave them */
+ kmsg->uaddr = NULL;
return io_net_kbuf_recyle(req, sel.buf_list, kmsg, ret);
}
if (ret == -ERESTARTSYS)
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 04/15] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit 2f70f2cf62e87b908f301fd78b2d01308cbf2ea4 upstream.
A bundle receive with MSG_WAITALL can hit a NULL pointer dereference in
io_net_kbuf_can_retry(), or share ring provided buffers with another
request of the buffer group, if another reader of the socket takes the
data that the receive is about to append.
The buffer list is only known within the issue that selected from it, so
io_recv() has to commit or recycle ring provided buffers before it
returns IOU_RETRY. On -EAGAIN it calls io_kbuf_recycle(), which does
nothing if REQ_F_BL_NO_RECYCLE is set. A partial transfer sets that flag
for the buffer that holds the data, and nothing ever clears it. That was
fine while only a multishot receive selected more than once, as
multishot excludes MSG_WAITALL. But since commit 7c71a0af81ba
("io_uring/net: improve recv bundles") any bundle receive can put its
buffers and select new ones, and the stale flag covers these too:
io_recv() partial transfer
io_net_kbuf_recyle() sets the flag, commits the buffer
return IOU_RETRY
io_recv() fills the buffer, msg_inq > 1
io_recv_finish()
io_put_kbufs() leaves the flag set
io_buffers_peek() sets REQ_F_BUFFERS_COMMIT
sock_recvmsg() -EAGAIN, the data is gone
io_kbuf_recycle() does nothing
return IOU_RETRY buffers mapped, but not committed
io_recv() sel.buf_list is NULL, no selection
sock_recvmsg() partial transfer
io_net_kbuf_can_retry() reads bl->flags
The fix used here is to clear the flag when the request puts the buffers
that the flag was set for.
Fixes: 7c71a0af81ba ("io_uring/net: improve recv bundles")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/kbuf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 9d6b7c433eea..22c0da122827 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -403,6 +403,9 @@ unsigned int __io_put_kbufs(struct io_kiocb *req, struct io_buffer_list *bl,
ret = IORING_CQE_F_BUFFER | (req->buf_index << IORING_CQE_BUFFER_SHIFT);
+ /* only covers the buffer(s) being put, not a later selection */
+ req->flags &= ~REQ_F_BL_NO_RECYCLE;
+
if (unlikely(!(req->flags & REQ_F_BUFFER_RING))) {
io_kbuf_drop_legacy(req);
return ret;
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 04/15] io_uring/tctx: add separate lock for list of tctx's in ctx
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (2 preceding siblings ...)
2026-12-05 23:10 ` [PATCH 6.12.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 05/15] io_uring: free the task context after a grace period Jens Axboe
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
Commit 5623eb1ed035f01dfa620366a82b667545b10c82 upstream.
ctx->tcxt_list holds the tasks using this ring, and it's currently
protected by the normal ctx->uring_lock. However, this can cause a
circular locking issue, as reported by syzbot, where cancelations off
exec end up needing to remove an entry from this list:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Tainted: G L
------------------------------------------------------
syz.0.9999/12287 is trying to acquire lock:
ffff88805851c0a8 (&ctx->uring_lock){+.+.}-{4:4}, at: io_uring_del_tctx_node+0xf0/0x2c0 io_uring/tctx.c:179
but task is already holding lock:
ffff88802db5a2e0 (&sig->cred_guard_mutex){+.+.}-{4:4}, at: prepare_bprm_creds fs/exec.c:1360 [inline]
ffff88802db5a2e0 (&sig->cred_guard_mutex){+.+.}-{4:4}, at: bprm_execve+0xb9/0x1400 fs/exec.c:1733
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&sig->cred_guard_mutex){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:614 [inline]
__mutex_lock+0x187/0x1350 kernel/locking/mutex.c:776
proc_pid_attr_write+0x547/0x630 fs/proc/base.c:2837
vfs_write+0x27e/0xb30 fs/read_write.c:684
ksys_write+0x145/0x250 fs/read_write.c:738
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (sb_writers#3){.+.+}-{0:0}:
percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
__sb_start_write include/linux/fs/super.h:19 [inline]
sb_start_write+0x4d/0x1c0 include/linux/fs/super.h:125
mnt_want_write+0x41/0x90 fs/namespace.c:499
open_last_lookups fs/namei.c:4529 [inline]
path_openat+0xadd/0x3dd0 fs/namei.c:4784
do_filp_open+0x1fa/0x410 fs/namei.c:4814
io_openat2+0x3e0/0x5c0 io_uring/openclose.c:143
__io_issue_sqe+0x181/0x4b0 io_uring/io_uring.c:1792
io_issue_sqe+0x165/0x1060 io_uring/io_uring.c:1815
io_queue_sqe io_uring/io_uring.c:2042 [inline]
io_submit_sqe io_uring/io_uring.c:2320 [inline]
io_submit_sqes+0xbf4/0x2140 io_uring/io_uring.c:2434
__do_sys_io_uring_enter io_uring/io_uring.c:3280 [inline]
__se_sys_io_uring_enter+0x2e0/0x2b60 io_uring/io_uring.c:3219
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ctx->uring_lock){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a6/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x107/0x340 kernel/locking/lockdep.c:5868
__mutex_lock_common kernel/locking/mutex.c:614 [inline]
__mutex_lock+0x187/0x1350 kernel/locking/mutex.c:776
io_uring_del_tctx_node+0xf0/0x2c0 io_uring/tctx.c:179
io_uring_clean_tctx+0xd4/0x1a0 io_uring/tctx.c:195
io_uring_cancel_generic+0x6ca/0x7d0 io_uring/cancel.c:646
io_uring_task_cancel include/linux/io_uring.h:24 [inline]
begin_new_exec+0x10ed/0x2440 fs/exec.c:1131
load_elf_binary+0x9f8/0x2d70 fs/binfmt_elf.c:1010
search_binary_handler fs/exec.c:1669 [inline]
exec_binprm fs/exec.c:1701 [inline]
bprm_execve+0x92e/0x1400 fs/exec.c:1753
do_execveat_common+0x510/0x6a0 fs/exec.c:1859
do_execve fs/exec.c:1933 [inline]
__do_sys_execve fs/exec.c:2009 [inline]
__se_sys_execve fs/exec.c:2004 [inline]
__x64_sys_execve+0x94/0xb0 fs/exec.c:2004
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ctx->uring_lock --> sb_writers#3 --> &sig->cred_guard_mutex
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&sig->cred_guard_mutex);
lock(sb_writers#3);
lock(&sig->cred_guard_mutex);
lock(&ctx->uring_lock);
*** DEADLOCK ***
1 lock held by syz.0.9999/12287:
#0: ffff88802db5a2e0 (&sig->cred_guard_mutex){+.+.}-{4:4}, at: prepare_bprm_creds fs/exec.c:1360 [inline]
#0: ffff88802db5a2e0 (&sig->cred_guard_mutex){+.+.}-{4:4}, at: bprm_execve+0xb9/0x1400 fs/exec.c:1733
stack backtrace:
CPU: 0 UID: 0 PID: 12287 Comm: syz.0.9999 Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a6/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x107/0x340 kernel/locking/lockdep.c:5868
__mutex_lock_common kernel/locking/mutex.c:614 [inline]
__mutex_lock+0x187/0x1350 kernel/locking/mutex.c:776
io_uring_del_tctx_node+0xf0/0x2c0 io_uring/tctx.c:179
io_uring_clean_tctx+0xd4/0x1a0 io_uring/tctx.c:195
io_uring_cancel_generic+0x6ca/0x7d0 io_uring/cancel.c:646
io_uring_task_cancel include/linux/io_uring.h:24 [inline]
begin_new_exec+0x10ed/0x2440 fs/exec.c:1131
load_elf_binary+0x9f8/0x2d70 fs/binfmt_elf.c:1010
search_binary_handler fs/exec.c:1669 [inline]
exec_binprm fs/exec.c:1701 [inline]
bprm_execve+0x92e/0x1400 fs/exec.c:1753
do_execveat_common+0x510/0x6a0 fs/exec.c:1859
do_execve fs/exec.c:1933 [inline]
__do_sys_execve fs/exec.c:2009 [inline]
__se_sys_execve fs/exec.c:2004 [inline]
__x64_sys_execve+0x94/0xb0 fs/exec.c:2004
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ff3a8b8f749
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:00007ff3a9a97038 EFLAGS: 00000246 ORIG_RAX: 000000000000003b
RAX: ffffffffffffffda RBX: 00007ff3a8de5fa0 RCX: 00007ff3a8b8f749
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000200000000400
RBP: 00007ff3a8c13f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ff3a8de6038 R14: 00007ff3a8de5fa0 R15: 00007ff3a8f0fa28
</TASK>
Add a separate lock just for the tctx_list, tctx_lock. This can nest
under ->uring_lock, where necessary, and be used separately for list
manipulation. For the cancelation off exec side, this removes the
need to grab ->uring_lock, hence fixing the circular locking
dependency.
Reported-by: syzbot+b0e3b77ffaa8a4067ce5@syzkaller.appspotmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 has io_uring_try_cancel_iowq() in io_uring.c]
---
include/linux/io_uring_types.h | 8 +++++++-
io_uring/cancel.c | 3 +++
io_uring/io_uring.c | 7 +++++++
io_uring/register.c | 2 ++
io_uring/tctx.c | 8 ++++----
5 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 15da758064b0..ecf6b8e15fe7 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -392,11 +392,17 @@ struct io_ring_ctx {
struct user_struct *user;
struct mm_struct *mm_account;
+ /*
+ * List of tctx nodes for this ctx, protected by tctx_lock. For
+ * cancelation purposes, nests under uring_lock.
+ */
+ struct list_head tctx_list;
+ struct mutex tctx_lock;
+
/* ctx exit and cancelation */
struct llist_head fallback_llist;
struct delayed_work fallback_work;
struct work_struct exit_work;
- struct list_head tctx_list;
struct completion ref_comp;
/* io-wq management, e.g. thread count */
diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index 727166a2ba3e..c4178a752833 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -194,7 +194,9 @@ static int __io_async_cancel(struct io_cancel_data *cd,
} while (1);
/* slow path, try all io-wq's */
+ __set_current_state(TASK_RUNNING);
io_ring_submit_lock(ctx, issue_flags);
+ mutex_lock(&ctx->tctx_lock);
ret = -ENOENT;
list_for_each_entry(node, &ctx->tctx_list, ctx_node) {
/* has been done above, don't count what is running there */
@@ -207,6 +209,7 @@ static int __io_async_cancel(struct io_cancel_data *cd,
nr++;
}
}
+ mutex_unlock(&ctx->tctx_lock);
io_ring_submit_unlock(ctx, issue_flags);
if (all)
return nr;
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 3f8a0f7e84f6..de46d9e21140 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -333,6 +333,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
INIT_LIST_HEAD(&ctx->rsrc_ref_list);
init_llist_head(&ctx->work_llist);
INIT_LIST_HEAD(&ctx->tctx_list);
+ mutex_init(&ctx->tctx_lock);
ctx->submit_state.free_list.next = NULL;
INIT_HLIST_HEAD(&ctx->waitid_list);
#ifdef CONFIG_FUTEX
@@ -3037,6 +3038,7 @@ static __cold void io_ring_exit_work(struct work_struct *work)
exit.ctx = ctx;
mutex_lock(&ctx->uring_lock);
+ mutex_lock(&ctx->tctx_lock);
while (!list_empty(&ctx->tctx_list)) {
WARN_ON_ONCE(time_after(jiffies, timeout));
@@ -3048,6 +3050,7 @@ static __cold void io_ring_exit_work(struct work_struct *work)
if (WARN_ON_ONCE(ret))
continue;
+ mutex_unlock(&ctx->tctx_lock);
mutex_unlock(&ctx->uring_lock);
/*
* See comment above for
@@ -3064,7 +3067,9 @@ static __cold void io_ring_exit_work(struct work_struct *work)
if (exit.in_cancel)
schedule_timeout_idle(HZ / 20);
mutex_lock(&ctx->uring_lock);
+ mutex_lock(&ctx->tctx_lock);
}
+ mutex_unlock(&ctx->tctx_lock);
mutex_unlock(&ctx->uring_lock);
spin_lock(&ctx->completion_lock);
spin_unlock(&ctx->completion_lock);
@@ -3155,6 +3160,7 @@ static __cold bool io_uring_try_cancel_iowq(struct io_ring_ctx *ctx)
bool ret = false;
mutex_lock(&ctx->uring_lock);
+ mutex_lock(&ctx->tctx_lock);
list_for_each_entry(node, &ctx->tctx_list, ctx_node) {
struct io_uring_task *tctx = node->task->io_uring;
@@ -3167,6 +3173,7 @@ static __cold bool io_uring_try_cancel_iowq(struct io_ring_ctx *ctx)
cret = io_wq_cancel_cb(tctx->io_wq, io_cancel_ctx_cb, ctx, true);
ret |= (cret != IO_WQ_CANCEL_NOTFOUND);
}
+ mutex_unlock(&ctx->tctx_lock);
mutex_unlock(&ctx->uring_lock);
return ret;
diff --git a/io_uring/register.c b/io_uring/register.c
index f700ddf1f1d1..9ba5f4ef44e2 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -318,6 +318,7 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
return 0;
/* now propagate the restriction to all registered users */
+ mutex_lock(&ctx->tctx_lock);
list_for_each_entry(node, &ctx->tctx_list, ctx_node) {
tctx = node->task->io_uring;
if (WARN_ON_ONCE(!tctx->io_wq))
@@ -328,6 +329,7 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
/* ignore errors, it always returns zero anyway */
(void)io_wq_max_workers(tctx->io_wq, new_count);
}
+ mutex_unlock(&ctx->tctx_lock);
return 0;
err:
if (sqd) {
diff --git a/io_uring/tctx.c b/io_uring/tctx.c
index cea6d082a262..1ff01d73e9dd 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -138,9 +138,9 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
return ret;
}
- mutex_lock(&ctx->uring_lock);
+ mutex_lock(&ctx->tctx_lock);
list_add(&node->ctx_node, &ctx->tctx_list);
- mutex_unlock(&ctx->uring_lock);
+ mutex_unlock(&ctx->tctx_lock);
}
return 0;
}
@@ -178,9 +178,9 @@ __cold void io_uring_del_tctx_node(unsigned long index)
WARN_ON_ONCE(current != node->task);
WARN_ON_ONCE(list_empty(&node->ctx_node));
- mutex_lock(&node->ctx->uring_lock);
+ mutex_lock(&node->ctx->tctx_lock);
list_del(&node->ctx_node);
- mutex_unlock(&node->ctx->uring_lock);
+ mutex_unlock(&node->ctx->tctx_lock);
if (tctx->last == node->ctx)
tctx->last = NULL;
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 05/15] io_uring: free the task context after a grace period
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (3 preceding siblings ...)
2026-12-05 23:10 ` [PATCH 6.12.y 04/15] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 06/15] io_uring: free the ring " Jens Axboe
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit 9f5315d3f4368590c9fe06d4313b7247470bcf15 upstream.
A task other than the owner can free a request, io_ring_exit_work()
running the local task_work of a DEFER_TASKRUN ring for example, or
io_do_iopoll() reaping completions. io_put_task() then takes the else
branch:
percpu_counter_sub(&tctx->inflight, 1);
if (unlikely(atomic_read(&tctx->in_cancel)))
wake_up(&tctx->wait);
put_task_struct(tctx->task);
The first line is what lets the owner leave io_uring_cancel_generic(),
and on exec it frees the tctx right after. Nothing holds that off for
the remaining three lines, the task reference only covers a tctx freed
along with the task_struct. It used to work out because
io_uring_del_tctx_node() took the uring_lock that the freeing side holds
across io_put_task(), until that moved to tctx_lock.
Free the tctx with kfree_rcu(), and enter an RCU read section in
io_put_task() before the count is dropped.
Fixes: 5623eb1ed035 ("io_uring/tctx: add separate lock for list of tctx's in ctx")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 drops the count in io_put_task_remote(), enter the RCU read
section there]
---
include/linux/io_uring_types.h | 3 +++
io_uring/io_uring.c | 2 ++
io_uring/tctx.c | 2 +-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index ecf6b8e15fe7..3fa179dd10b4 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -103,6 +103,9 @@ struct io_uring_task {
atomic_t inflight_tracked;
struct percpu_counter inflight;
+ /* the tctx is freed after a grace period, see io_put_task() */
+ struct rcu_head rcu;
+
struct { /* task_work */
struct llist_head task_list;
struct callback_head task_work;
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index de46d9e21140..3e5201e19bb4 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -685,6 +685,8 @@ static void io_put_task_remote(struct task_struct *task)
{
struct io_uring_task *tctx = task->io_uring;
+ guard(rcu)();
+
percpu_counter_sub(&tctx->inflight, 1);
if (unlikely(atomic_read(&tctx->in_cancel)))
wake_up(&tctx->wait);
diff --git a/io_uring/tctx.c b/io_uring/tctx.c
index 1ff01d73e9dd..63c97eec3038 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -65,7 +65,7 @@ void __io_uring_free(struct task_struct *tsk)
WARN_ON_ONCE(tctx->cached_refs);
percpu_counter_destroy(&tctx->inflight);
- kfree(tctx);
+ kfree_rcu(tctx, rcu);
tsk->io_uring = NULL;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 06/15] io_uring: free the ring after a grace period
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (4 preceding siblings ...)
2026-12-05 23:10 ` [PATCH 6.12.y 05/15] io_uring: free the task context after a grace period Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 07/15] io_uring/filetable: don't install O_PATH files Jens Axboe
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit 0e433c705aff3846356f402e8b054d6e4ebbdbe0 upstream.
On !PREEMPT_RT, a task that removes its tctx node on exit or exec can
race with the exit work of a closed ring and cause a use-after-free of
the io_ring_ctx.
A mutex has to stay allocated until mutex_unlock() has returned. But
io_uring_del_tctx_node() holds no reference on the ring, only its node
on ->tctx_list keeps it, and io_ring_exit_work() frees the ring once it
has tctx_lock and finds the list empty. If the exit work has queued as
a waiter, it can get there while the unlock still needs the mutex:
io_uring_del_tctx_node() io_ring_exit_work()
======================== ===================
mutex_lock(tctx_lock)
list_del()
mutex_lock(tctx_lock)
lock wait_lock
set MUTEX_FLAG_WAITERS
mutex_unlock(tctx_lock)
clear the owner
__mutex_trylock() succeeds
unlock wait_lock
list_empty() is true
mutex_unlock(tctx_lock)
io_ring_ctx_free()
kfree(ctx)
lock wait_lock
waiter = lock->first_waiter
Each node used to hold a file reference that was dropped after the
unlock. Commit eebd2e37e662 ("io_uring: don't take task ring-file
notes") removed it, and relies on the exit work to wait for the nodes.
The fix used here is to do the unlock inside an RCU read section, and to
free the io_ring_ctx only after a grace period.
Fixes: eebd2e37e662 ("io_uring: don't take task ring-file notes")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/linux/io_uring_types.h | 2 ++
io_uring/io_uring.c | 2 +-
io_uring/tctx.c | 3 +++
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 3fa179dd10b4..a06b75630222 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -406,6 +406,8 @@ struct io_ring_ctx {
struct llist_head fallback_llist;
struct delayed_work fallback_work;
struct work_struct exit_work;
+ /* the ctx is freed after a grace period, see io_uring_del_tctx_node() */
+ struct rcu_head rcu;
struct completion ref_comp;
/* io-wq management, e.g. thread count */
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 3e5201e19bb4..e61d1a124a27 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2865,7 +2865,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
kfree(ctx->cancel_table_locked.hbs);
xa_destroy(&ctx->io_bl_xa);
xa_destroy(&ctx->personalities);
- kfree(ctx);
+ kfree_rcu(ctx, rcu);
}
static __cold void io_activate_pollwq_cb(struct callback_head *cb)
diff --git a/io_uring/tctx.c b/io_uring/tctx.c
index 63c97eec3038..9845bbd7551b 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -180,7 +180,10 @@ __cold void io_uring_del_tctx_node(unsigned long index)
mutex_lock(&node->ctx->tctx_lock);
list_del(&node->ctx_node);
+ /* keeps the ctx until the unlock is done, see io_ring_ctx_free() */
+ rcu_read_lock();
mutex_unlock(&node->ctx->tctx_lock);
+ rcu_read_unlock();
if (tctx->last == node->ctx)
tctx->last = NULL;
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 07/15] io_uring/filetable: don't install O_PATH files
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (5 preceding siblings ...)
2026-12-05 23:10 ` [PATCH 6.12.y 06/15] io_uring: free the ring " Jens Axboe
@ 2026-12-05 23:10 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 08/15] io_uring: make ctx->timeout_lock a raw spinlock Jens Axboe
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:10 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit e49d115878796b7b7f77f821d67b7b2f7ccaf400 upstream.
IORING_OP_FADVISE with POSIX_FADV_WILLNEED on a fixed file that was
opened with O_PATH can dereference a NULL pointer in the readahead code
of the filesystem.
The opcode handlers are written like the system calls that they mirror,
which get their file from fdget() and so never see an O_PATH file.
io_uring has to keep that true for req->file. io_file_get_normal() does,
with fget(). io_file_get_fixed() checks nothing, so a fixed file table
must never hold an O_PATH file. The register and update paths take their
files from fget(). But a direct open, IORING_OP_OPENAT or
IORING_OP_OPENAT2 with sqe->file_index set, installs the file that
do_file_open() returns, and io_install_fixed_file() refuses nothing but
io_uring files.
With O_PATH, do_dentry_open() returns before it calls ->open(), so
file->private_data stays NULL. generic_fadvise() has no check of its own
and starts readahead with that file, and fuse_send_readpages(), for one,
dereferences file->private_data.
The fix used here is to refuse O_PATH files in io_install_fixed_file()
as well, so that a direct open gives what an open followed by a register
gives.
A direct open with O_PATH now fails with -EBADF. Until now the slot
could be turned into a descriptor with IORING_OP_FIXED_FD_INSTALL,
passed to another ring with IORING_MSG_SEND_FD, and used with
IORING_OP_FGETXATTR and IORING_OP_FSETXATTR. No program that does so is
known, and a fixed file can't serve as the directory of a lookup.
Fixes: b9445598d8c6 ("io_uring: openat directly into fixed fd table")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/filetable.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/io_uring/filetable.c b/io_uring/filetable.c
index 72423e27e5e1..e68a6ddae682 100644
--- a/io_uring/filetable.c
+++ b/io_uring/filetable.c
@@ -73,6 +73,9 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
if (io_is_uring_fops(file))
return -EBADF;
+ /* Registered files come from fget(), which refuses these too */
+ if (file->f_mode & FMODE_PATH)
+ return -EBADF;
if (!ctx->file_data)
return -ENXIO;
if (slot_index >= ctx->nr_user_files)
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 08/15] io_uring: make ctx->timeout_lock a raw spinlock
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (6 preceding siblings ...)
2026-12-05 23:10 ` [PATCH 6.12.y 07/15] io_uring/filetable: don't install O_PATH files Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 09/15] io_uring/timeout: flush timeouts outside of the timeout lock Jens Axboe
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
Commit 020b40f3562495f3c703a283ece145ffec19e82d upstream.
Chase reports that their tester complaints about a locking context
mismatch:
=============================
[ BUG: Invalid wait context ]
6.13.0-rc1-gf137f14b7ccb-dirty #9 Not tainted
-----------------------------
syz.1.25198/182604 is trying to lock:
ffff88805e66a358 (&ctx->timeout_lock){-.-.}-{3:3}, at: spin_lock_irq
include/linux/spinlock.h:376 [inline]
ffff88805e66a358 (&ctx->timeout_lock){-.-.}-{3:3}, at:
io_match_task_safe io_uring/io_uring.c:218 [inline]
ffff88805e66a358 (&ctx->timeout_lock){-.-.}-{3:3}, at:
io_match_task_safe+0x187/0x250 io_uring/io_uring.c:204
other info that might help us debug this:
context-{5:5}
1 lock held by syz.1.25198/182604:
#0: ffff88802b7d48c0 (&acct->lock){+.+.}-{2:2}, at:
io_acct_cancel_pending_work+0x2d/0x6b0 io_uring/io-wq.c:1049
stack backtrace:
CPU: 0 UID: 0 PID: 182604 Comm: syz.1.25198 Not tainted
6.13.0-rc1-gf137f14b7ccb-dirty #9
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x82/0xd0 lib/dump_stack.c:120
print_lock_invalid_wait_context kernel/locking/lockdep.c:4826 [inline]
check_wait_context kernel/locking/lockdep.c:4898 [inline]
__lock_acquire+0x883/0x3c80 kernel/locking/lockdep.c:5176
lock_acquire.part.0+0x11b/0x370 kernel/locking/lockdep.c:5849
__raw_spin_lock_irq include/linux/spinlock_api_smp.h:119 [inline]
_raw_spin_lock_irq+0x36/0x50 kernel/locking/spinlock.c:170
spin_lock_irq include/linux/spinlock.h:376 [inline]
io_match_task_safe io_uring/io_uring.c:218 [inline]
io_match_task_safe+0x187/0x250 io_uring/io_uring.c:204
io_acct_cancel_pending_work+0xb8/0x6b0 io_uring/io-wq.c:1052
io_wq_cancel_pending_work io_uring/io-wq.c:1074 [inline]
io_wq_cancel_cb+0xb0/0x390 io_uring/io-wq.c:1112
io_uring_try_cancel_requests+0x15e/0xd70 io_uring/io_uring.c:3062
io_uring_cancel_generic+0x6ec/0x8c0 io_uring/io_uring.c:3140
io_uring_files_cancel include/linux/io_uring.h:20 [inline]
do_exit+0x494/0x27a0 kernel/exit.c:894
do_group_exit+0xb3/0x250 kernel/exit.c:1087
get_signal+0x1d77/0x1ef0 kernel/signal.c:3017
arch_do_signal_or_restart+0x79/0x5b0 arch/x86/kernel/signal.c:337
exit_to_user_mode_loop kernel/entry/common.c:111 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:329 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0x150/0x2a0 kernel/entry/common.c:218
do_syscall_64+0xd8/0x250 arch/x86/entry/common.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
which is because io_uring has ctx->timeout_lock nesting inside the
io-wq acct lock, the latter of which is used from inside the scheduler
and hence is a raw spinlock, while the former is a "normal" spinlock
and can hence be sleeping on PREEMPT_RT.
Change ctx->timeout_lock to be a raw spinlock to solve this nesting
dependency on PREEMPT_RT=y.
Reported-by: chase xd <sl1589472800@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 has two more timeout_lock sections from later fixes, the
cq_timeouts update in io_timeout_cancel() and the __io_wq_cancel_seen()
check in io_timeout(). Convert those as well]
---
include/linux/io_uring_types.h | 2 +-
io_uring/io_uring.c | 10 ++++----
io_uring/timeout.c | 42 +++++++++++++++++-----------------
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index a06b75630222..b9bcf8ba820b 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -344,7 +344,7 @@ struct io_ring_ctx {
/* timeouts */
struct {
- spinlock_t timeout_lock;
+ raw_spinlock_t timeout_lock;
struct list_head timeout_list;
struct list_head ltimeout_list;
unsigned cq_last_tm_flush;
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index e61d1a124a27..20cb8162e13a 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -215,9 +215,9 @@ bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task,
struct io_ring_ctx *ctx = head->ctx;
/* protect against races with linked timeouts */
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
matched = io_match_linked(head);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
} else {
matched = io_match_linked(head);
}
@@ -325,7 +325,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
init_waitqueue_head(&ctx->poll_wq);
init_waitqueue_head(&ctx->rsrc_quiesce_wq);
spin_lock_init(&ctx->completion_lock);
- spin_lock_init(&ctx->timeout_lock);
+ raw_spin_lock_init(&ctx->timeout_lock);
INIT_WQ_LIST(&ctx->iopoll_list);
INIT_LIST_HEAD(&ctx->defer_list);
INIT_LIST_HEAD(&ctx->timeout_list);
@@ -473,10 +473,10 @@ static void io_prep_async_link(struct io_kiocb *req)
if (req->flags & REQ_F_LINK_TIMEOUT) {
struct io_ring_ctx *ctx = req->ctx;
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
io_for_each_link(cur, req)
io_prep_async_work(cur);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
} else {
io_for_each_link(cur, req)
io_prep_async_work(cur);
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index e99709c4089d..4d54d2ef4784 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -75,11 +75,11 @@ static void io_timeout_complete(struct io_kiocb *req, struct io_tw_state *ts)
if (!io_should_terminate_tw(ctx) &&
io_req_post_cqe(req, -ETIME, IORING_CQE_F_MORE)) {
/* re-arm timer */
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
list_add(&timeout->list, ctx->timeout_list.prev);
data->timer.function = io_timeout_fn;
hrtimer_start(&data->timer, timespec64_to_ktime(data->ts), data->mode);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
return;
}
}
@@ -111,7 +111,7 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx)
u32 seq;
struct io_timeout *timeout, *tmp;
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
seq = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts);
/*
@@ -144,7 +144,7 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx)
io_kill_timeout(req, 0);
}
ctx->cq_last_tm_flush = seq;
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
}
static void io_req_tw_fail_links(struct io_kiocb *link, struct io_tw_state *ts)
@@ -210,9 +210,9 @@ void io_disarm_next(struct io_kiocb *req)
} else if (req->flags & REQ_F_LINK_TIMEOUT) {
struct io_ring_ctx *ctx = req->ctx;
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
link = io_disarm_linked_timeout(req);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
if (link)
io_req_queue_tw_complete(link, -ECANCELED);
}
@@ -248,11 +248,11 @@ static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer)
struct io_ring_ctx *ctx = req->ctx;
unsigned long flags;
- spin_lock_irqsave(&ctx->timeout_lock, flags);
+ raw_spin_lock_irqsave(&ctx->timeout_lock, flags);
list_del_init(&timeout->list);
atomic_set(&req->ctx->cq_timeouts,
atomic_read(&req->ctx->cq_timeouts) + 1);
- spin_unlock_irqrestore(&ctx->timeout_lock, flags);
+ raw_spin_unlock_irqrestore(&ctx->timeout_lock, flags);
if (!(data->flags & IORING_TIMEOUT_ETIME_SUCCESS))
req_set_fail(req);
@@ -302,12 +302,12 @@ int io_timeout_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd)
{
struct io_kiocb *req;
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
req = io_timeout_extract(ctx, cd);
if (!IS_ERR(req))
atomic_set(&ctx->cq_timeouts,
atomic_read(&ctx->cq_timeouts) + 1);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
if (IS_ERR(req))
return PTR_ERR(req);
@@ -351,7 +351,7 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
struct io_ring_ctx *ctx = req->ctx;
unsigned long flags;
- spin_lock_irqsave(&ctx->timeout_lock, flags);
+ raw_spin_lock_irqsave(&ctx->timeout_lock, flags);
prev = timeout->head;
timeout->head = NULL;
@@ -366,7 +366,7 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
}
list_del(&timeout->list);
timeout->prev = prev;
- spin_unlock_irqrestore(&ctx->timeout_lock, flags);
+ raw_spin_unlock_irqrestore(&ctx->timeout_lock, flags);
req->io_task_work.func = io_req_task_link_timeout;
io_req_task_work_add(req);
@@ -506,12 +506,12 @@ int io_timeout_remove(struct io_kiocb *req, unsigned int issue_flags)
} else {
enum hrtimer_mode mode = io_translate_timeout_mode(tr->flags);
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
if (tr->ltimeout)
ret = io_linked_timeout_update(ctx, tr->addr, &tr->ts, mode);
else
ret = io_timeout_update(ctx, tr->addr, &tr->ts, mode);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
}
if (ret < 0)
@@ -609,11 +609,11 @@ int io_timeout(struct io_kiocb *req, unsigned int issue_flags)
struct list_head *entry;
u32 tail, base, off = timeout->off;
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
/* the list is searched under ->timeout_lock, see io_wq_cancel_seen() */
if (__io_wq_cancel_seen(req, issue_flags)) {
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
io_req_task_queue_fail(req, -ECANCELED);
return IOU_ISSUE_SKIP_COMPLETE;
}
@@ -669,7 +669,7 @@ int io_timeout(struct io_kiocb *req, unsigned int issue_flags)
list_add(&timeout->list, entry);
data->timer.function = io_timeout_fn;
hrtimer_start(&data->timer, timespec64_to_ktime(data->ts), data->mode);
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
return IOU_ISSUE_SKIP_COMPLETE;
}
@@ -678,7 +678,7 @@ void io_queue_linked_timeout(struct io_kiocb *req)
struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout);
struct io_ring_ctx *ctx = req->ctx;
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
/*
* If the back reference is NULL, then our linked request finished
* before we got a chance to setup the timer
@@ -691,7 +691,7 @@ void io_queue_linked_timeout(struct io_kiocb *req)
data->mode);
list_add_tail(&timeout->list, &ctx->ltimeout_list);
}
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
/* drop submission reference */
io_put_req(req);
}
@@ -726,7 +726,7 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
* timeout_lockfirst to keep locking ordering.
*/
spin_lock(&ctx->completion_lock);
- spin_lock_irq(&ctx->timeout_lock);
+ raw_spin_lock_irq(&ctx->timeout_lock);
list_for_each_entry_safe(timeout, tmp, &ctx->timeout_list, list) {
struct io_kiocb *req = cmd_to_io_kiocb(timeout);
@@ -734,7 +734,7 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
io_kill_timeout(req, -ECANCELED))
canceled++;
}
- spin_unlock_irq(&ctx->timeout_lock);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
spin_unlock(&ctx->completion_lock);
return canceled != 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 09/15] io_uring/timeout: flush timeouts outside of the timeout lock
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (7 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 08/15] io_uring: make ctx->timeout_lock a raw spinlock Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 10/15] io_uring/cancel: always walk links under timeout_lock Jens Axboe
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
Commit a9c83a0ab66a5b02e914daed502fb8d3a8d3d619 upstream.
syzbot reports that a recent fix causes nesting issues between the (now)
raw timeoutlock and the eventfd locking:
=============================
[ BUG: Invalid wait context ]
6.13.0-rc4-00080-g9828a4c0901f #29 Not tainted
-----------------------------
kworker/u32:0/68094 is trying to lock:
ffff000014d7a520 (&ctx->wqh#2){..-.}-{3:3}, at: eventfd_signal_mask+0x64/0x180
other info that might help us debug this:
context-{5:5}
6 locks held by kworker/u32:0/68094:
#0: ffff0000c1d98148 ((wq_completion)iou_exit){+.+.}-{0:0}, at: process_one_work+0x4e8/0xfc0
#1: ffff80008d927c78 ((work_completion)(&ctx->exit_work)){+.+.}-{0:0}, at: process_one_work+0x53c/0xfc0
#2: ffff0000c59bc3d8 (&ctx->completion_lock){+.+.}-{3:3}, at: io_kill_timeouts+0x40/0x180
#3: ffff0000c59bc358 (&ctx->timeout_lock){-.-.}-{2:2}, at: io_kill_timeouts+0x48/0x180
#4: ffff800085127aa0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x8/0x38
#5: ffff800085127aa0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x8/0x38
stack backtrace:
CPU: 7 UID: 0 PID: 68094 Comm: kworker/u32:0 Not tainted 6.13.0-rc4-00080-g9828a4c0901f #29
Hardware name: linux,dummy-virt (DT)
Workqueue: iou_exit io_ring_exit_work
Call trace:
show_stack+0x1c/0x30 (C)
__dump_stack+0x24/0x30
dump_stack_lvl+0x60/0x80
dump_stack+0x14/0x20
__lock_acquire+0x19f8/0x60c8
lock_acquire+0x1a4/0x540
_raw_spin_lock_irqsave+0x90/0xd0
eventfd_signal_mask+0x64/0x180
io_eventfd_signal+0x64/0x108
io_req_local_work_add+0x294/0x430
__io_req_task_work_add+0x1c0/0x270
io_kill_timeout+0x1f0/0x288
io_kill_timeouts+0xd4/0x180
io_uring_try_cancel_requests+0x2e8/0x388
io_ring_exit_work+0x150/0x550
process_one_work+0x5e8/0xfc0
worker_thread+0x7ec/0xc80
kthread+0x24c/0x300
ret_from_fork+0x10/0x20
because after the preempt-rt fix for the timeout lock nesting inside
the io-wq lock, we now have the eventfd spinlock nesting inside the
raw timeout spinlock.
Rather than play whack-a-mole with other nesting on the timeout lock,
split the deletion and killing of timeouts so queueing the task_work
for the timeout cancelations can get done outside of the timeout lock.
Reported-by: syzbot+b1fc199a40b65d601b65@syzkaller.appspotmail.com
Fixes: 020b40f35624 ("io_uring: make ctx->timeout_lock a raw spinlock")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 passes the task rather than the tctx to io_kill_timeouts()
and io_match_task()]
---
io_uring/timeout.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index 4d54d2ef4784..2cf9887b4bc9 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -87,7 +87,27 @@ static void io_timeout_complete(struct io_kiocb *req, struct io_tw_state *ts)
io_req_task_complete(req, ts);
}
-static bool io_kill_timeout(struct io_kiocb *req, int status)
+static __cold bool io_flush_killed_timeouts(struct list_head *list, int err)
+{
+ if (list_empty(list))
+ return false;
+
+ while (!list_empty(list)) {
+ struct io_timeout *timeout;
+ struct io_kiocb *req;
+
+ timeout = list_first_entry(list, struct io_timeout, list);
+ list_del_init(&timeout->list);
+ req = cmd_to_io_kiocb(timeout);
+ if (err)
+ req_set_fail(req);
+ io_req_queue_tw_complete(req, err);
+ }
+
+ return true;
+}
+
+static void io_kill_timeout(struct io_kiocb *req, struct list_head *list)
__must_hold(&req->ctx->timeout_lock)
{
struct io_timeout_data *io = req->async_data;
@@ -95,21 +115,17 @@ static bool io_kill_timeout(struct io_kiocb *req, int status)
if (hrtimer_try_to_cancel(&io->timer) != -1) {
struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout);
- if (status)
- req_set_fail(req);
atomic_set(&req->ctx->cq_timeouts,
atomic_read(&req->ctx->cq_timeouts) + 1);
- list_del_init(&timeout->list);
- io_req_queue_tw_complete(req, status);
- return true;
+ list_move_tail(&timeout->list, list);
}
- return false;
}
__cold void io_flush_timeouts(struct io_ring_ctx *ctx)
{
- u32 seq;
struct io_timeout *timeout, *tmp;
+ LIST_HEAD(list);
+ u32 seq;
raw_spin_lock_irq(&ctx->timeout_lock);
seq = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts);
@@ -141,10 +157,11 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx)
if (events_got < events_needed)
break;
- io_kill_timeout(req, 0);
+ io_kill_timeout(req, &list);
}
ctx->cq_last_tm_flush = seq;
raw_spin_unlock_irq(&ctx->timeout_lock);
+ io_flush_killed_timeouts(&list, 0);
}
static void io_req_tw_fail_links(struct io_kiocb *link, struct io_tw_state *ts)
@@ -719,7 +736,7 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
bool cancel_all)
{
struct io_timeout *timeout, *tmp;
- int canceled = 0;
+ LIST_HEAD(list);
/*
* completion_lock is needed for io_match_task(). Take it before
@@ -730,11 +747,11 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
list_for_each_entry_safe(timeout, tmp, &ctx->timeout_list, list) {
struct io_kiocb *req = cmd_to_io_kiocb(timeout);
- if (io_match_task(req, tsk, cancel_all) &&
- io_kill_timeout(req, -ECANCELED))
- canceled++;
+ if (io_match_task(req, tsk, cancel_all))
+ io_kill_timeout(req, &list);
}
raw_spin_unlock_irq(&ctx->timeout_lock);
spin_unlock(&ctx->completion_lock);
- return canceled != 0;
+
+ return io_flush_killed_timeouts(&list, -ECANCELED);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 10/15] io_uring/cancel: always walk links under timeout_lock
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (8 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 09/15] io_uring/timeout: flush timeouts outside of the timeout lock Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 11/15] io_uring/net: don't count the buffers of a send bundle Jens Axboe
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit a6b53de207d3472f209e71fd4990be3dd3133d1f upstream.
The exit of a single thread that races with the close of its
IORING_SETUP_DEFER_TASKRUN ring can cause a use-after-free of a linked
timeout, if io-wq is the first to issue the request that the timeout is
linked to.
When io-wq calls io_match_task_safe(), ->timeout_lock alone protects the
walk of the link chain against the removal of a linked timeout. The
function takes the lock only if the head has REQ_F_LINK_TIMEOUT. But the
first issue sets that flag. If that happens in an io-wq worker,
cancellation can find the request as the current work of the worker
before the flag is set:
io_match_task_safe() io-wq worker, timer, task_work
==================== ==============================
REQ_F_LINK_TIMEOUT is clear
io_match_linked()
req = head->link
__io_issue_sqe()
__io_prep_linked_timeout()
io_queue_linked_timeout()
io_link_timeout_fn()
io_req_task_link_timeout()
__io_req_caches_free()
req = req->link
The fix used here is to take ->timeout_lock for every walk, whatever the
flags of the head say.
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 has io_match_task_safe() in io_uring.c]
---
io_uring/io_uring.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 20cb8162e13a..98cba5672475 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -204,6 +204,7 @@ static bool io_match_linked(struct io_kiocb *head)
bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task,
bool cancel_all)
{
+ struct io_ring_ctx *ctx = head->ctx;
bool matched;
if (task && head->task != task)
@@ -211,16 +212,13 @@ bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task,
if (cancel_all)
return true;
- if (head->flags & REQ_F_LINK_TIMEOUT) {
- struct io_ring_ctx *ctx = head->ctx;
-
- /* protect against races with linked timeouts */
- raw_spin_lock_irq(&ctx->timeout_lock);
- matched = io_match_linked(head);
- raw_spin_unlock_irq(&ctx->timeout_lock);
- } else {
- matched = io_match_linked(head);
- }
+ /*
+ * Protect against races with linked timeouts. REQ_F_LINK_TIMEOUT can't
+ * tell if there is one: an io-wq worker may set it during the walk.
+ */
+ raw_spin_lock_irq(&ctx->timeout_lock);
+ matched = io_match_linked(head);
+ raw_spin_unlock_irq(&ctx->timeout_lock);
return matched;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 11/15] io_uring/net: don't count the buffers of a send bundle
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (9 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 10/15] io_uring/cancel: always walk links under timeout_lock Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 12/15] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit 449c7dc8502404b3a95ffa75cf5b54be5350fc49 upstream.
A bundle send on a packet socket with a TX ring can cause a
slab-out-of-bounds read, if the frames in the ring hold more bytes than
the iovecs of the send.
io_send_finish() hands the result of the send to io_bundle_nbufs(),
which walks the iovec array and subtracts each iov_len from the result.
The walk only stops at zero, so the iovecs have to cover the result. But
io_send() only tests if the result is below the count of the iter, and
tpacket_snd() ignores msg_iter and returns the length of the frames that
it took from the TX ring:
iovecs = 2, of 1 byte each
frames in the TX ring = 1, of 64 bytes
sock_sendmsg() = 64
64 - iov[0].iov_len = 63
63 - iov[1].iov_len = 62
62 - iov[2].iov_len is out of bounds
The send side doesn't use the number of buffers: io_buffers_select()
commits them at selection, so at completion io_kbuf_commit() returns
before it reads the number.
The fix used here is to put the buffers of a send bundle without
counting them, so that nothing walks the iovecs with the result of the
send.
Fixes: a05d1f625c7a ("io_uring/net: support bundles for send")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/net.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index cc92e892fb53..01a3ad67474b 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -535,12 +535,10 @@ static inline bool io_send_finish(struct io_kiocb *req,
bool bundle_finished = sel->val <= 0;
unsigned int cflags;
- if (!(sr->flags & IORING_RECVSEND_BUNDLE)) {
- cflags = io_put_kbuf(req, sel->val, sel->buf_list);
+ /* Committed at selection time, so a bundle needs no buffer count */
+ cflags = io_put_kbuf(req, sel->val, sel->buf_list);
+ if (!(sr->flags & IORING_RECVSEND_BUNDLE))
goto finish;
- }
-
- cflags = io_put_kbufs(req, sel->val, sel->buf_list, io_bundle_nbufs(kmsg, sel->val));
/*
* Don't start new bundles if the buffer list is empty, or if the
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 12/15] io_uring/net: restore the cmsg buffer on recvmsg retry
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (10 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 11/15] io_uring/net: don't count the buffers of a send bundle Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 13/15] io_uring_poll: kill the no longer necessary barrier after poll_wait() Jens Axboe
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Chris Mason <mason@kernel.org>
Commit 437e79d6a2a7aba81d56c11198576a72574e6d52 upstream.
A single-shot IORING_OP_RECVMSG that is retried after -EAGAIN can report
the control messages of the failed attempt, and hide those that came
with the data. On an AF_UNIX stream socket with SO_PASSCRED, the caller
gets SCM_CREDENTIALS with pid, uid and gid 0, and never sees the
descriptors that an SCM_RIGHTS message installed.
io_recvmsg() passes the msghdr that was set up at prep to each attempt,
so a failed ->recvmsg() has to leave msg_control and msg_controllen as
they were. recvmsg(2) doesn't depend on that, since it copies the user's
msghdr for each call. unix_stream_read_generic() calls scm_recv_unix()
whatever its result is, with a zeroed scm_cookie if the queue was empty,
and put_cmsg() advances the control buffer. ____sys_recvmsg() then
counts the reported length from where its call started, but the caller
reads from the head of its buffer:
msg_control = C, msg_controllen = 64
first attempt, the queue is empty
put_cmsg(SCM_CREDENTIALS {0, 0, 0}) at C
msg_control = C + 32, msg_controllen = 32
return -EAGAIN
second attempt
cmsg_ptr = C + 32
put_cmsg(SCM_CREDENTIALS of the sender) at C + 32
msg_control = C + 64, msg_controllen = 0
put_user(msg_control - cmsg_ptr = 32, &umsg->msg_controllen)
The fix used here is to save the control buffer before each attempt, and
to restore it if the attempt fails with -EAGAIN and will be retried.
The tradeoff: with MSG_WAITALL, a retry whose control buffer the failed
attempts had used up went on after a short receive until the data buffer
was full. It now completes short, as every recvmsg with a control buffer
does since commit 78d0d2063bab ("io_uring/net: disable partial retries
for recvmsg with cmsg").
Fixes: e54937963fa2 ("net: remove cmsg restriction from io_uring based send/recvmsg calls")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/net.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/io_uring/net.c b/io_uring/net.c
index 01a3ad67474b..6564d24e49c2 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1037,6 +1037,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
int ret, min_ret = 0;
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
bool mshot_finished = true;
+ void __user *control;
+ size_t controllen;
int consumed = 0;
size_t len;
@@ -1074,6 +1076,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
kmsg->msg.msg_get_inq = 1;
kmsg->msg.msg_inq = -1;
+ control = kmsg->msg.msg_control_user;
+ controllen = kmsg->msg.msg_controllen;
if (req->flags & REQ_F_APOLL_MULTISHOT) {
ret = io_recvmsg_multishot(sock, sr, kmsg, flags,
&mshot_finished);
@@ -1098,6 +1102,12 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
if (ret < min_ret) {
if (ret == -EAGAIN && force_nonblock) {
+ /*
+ * Don't depend on the control buffer being untouched, a
+ * protocol may post a cmsg before it finds no data.
+ */
+ kmsg->msg.msg_control_user = control;
+ kmsg->msg.msg_controllen = controllen;
io_kbuf_recycle(req, sel.buf_list, issue_flags);
if (issue_flags & IO_URING_F_MULTISHOT)
return IOU_ISSUE_SKIP_COMPLETE;
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 13/15] io_uring_poll: kill the no longer necessary barrier after poll_wait()
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (11 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 12/15] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 14/15] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 15/15] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Oleg Nesterov <oleg@redhat.com>
Commit 4e15fa8305deecdf20233558ed9f7a8a62b708fd upstream.
Now that poll_wait() provides a full barrier we can remove smp_rmb() from
io_uring_poll().
In fact I don't think smp_rmb() was correct, it can't serialize LOADs and
STOREs.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20250107162730.GA18940@redhat.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
io_uring/io_uring.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 98cba5672475..0ad03f222bf5 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2912,13 +2912,12 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
if (unlikely(!ctx->poll_activated))
io_activate_pollwq(ctx);
-
- poll_wait(file, &ctx->poll_wq, wait);
/*
- * synchronizes with barrier from wq_has_sleeper call in
- * io_commit_cqring
+ * provides mb() which pairs with barrier from wq_has_sleeper
+ * call in io_commit_cqring
*/
- smp_rmb();
+ poll_wait(file, &ctx->poll_wq, wait);
+
if (!io_sqring_full(ctx))
mask |= EPOLLOUT | EPOLLWRNORM;
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 14/15] io_uring: close poll activation race when enabling rings
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (12 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 13/15] io_uring_poll: kill the no longer necessary barrier after poll_wait() Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 15/15] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Andrea Parri <parri.andrea@gmail.com>
Commit e20a070b2a2ba35411251850c8969c1ac1838433 upstream.
An epoll waiter can hang with completions pending when polling a
disabled SINGLE_ISSUER ring races with IORING_REGISTER_ENABLE_RINGS:
CPU0 CPU1
---- ----
io_activate_pollwq()
submitter_task == NULL
submitter_task = current
wq_has_sleeper() == false
poll_wait()
Neither side retries the activation. The activation flag remains
clear, so completion and deferred task work paths skip poll_wq wakeups.
Cure this by registering the poll waiter before trying to activate
poll_wq. The full barrier in poll_wait() pairs with the barrier in
wq_has_sleeper(), which ensures that either the poller observes
submitter_task or the ring enable path observes the waiter.
Tested in a 2-vCPU x86-64 KVM guest with a reproducer that races
EPOLL_CTL_ADD on a disabled ring against IORING_REGISTER_ENABLE_RINGS.
v7.4-rc5 missed the wakeup in each of three runs, at iterations 177,
505 and 26826. With this patch, three runs of 100000 iterations passed.
The bug was found with the help of an LLM, which was also used to write
the fix, the changelog and the tests.
Fixes: bca39f390585 ("io_uring: add lazy poll_wq activation")
Cc: stable@vger.kernel.org
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
Link: https://patch.msgid.link/20261204174710.131485-1-parri.andrea@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 has ctx->poll_activated rather than
IO_RING_F_POLL_ACTIVATED in ctx->int_flags]
---
io_uring/io_uring.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 0ad03f222bf5..1f67e0596faf 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2910,13 +2910,14 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
struct io_ring_ctx *ctx = file->private_data;
__poll_t mask = 0;
- if (unlikely(!ctx->poll_activated))
- io_activate_pollwq(ctx);
/*
- * provides mb() which pairs with barrier from wq_has_sleeper
- * call in io_commit_cqring
+ * The poll_wait() barrier pairs with wq_has_sleeper() on the CQ
+ * wakeup and ring enable paths.
*/
poll_wait(file, &ctx->poll_wq, wait);
+ /* A stale flag only causes a redundant activation attempt. */
+ if (unlikely(!ctx->poll_activated))
+ io_activate_pollwq(ctx);
if (!io_sqring_full(ctx))
mask |= EPOLLOUT | EPOLLWRNORM;
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6.12.y 15/15] io_uring/cancel: arm local work wakeups only for submitter
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
` (13 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.12.y 14/15] io_uring: close poll activation race when enabling rings Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Andrea Parri <parri.andrea@gmail.com>
Commit 709d9af776febf3a0773727939742460a55e14e2 upstream.
io_uring_try_cancel_requests() arms cq_wait_nr on every DEFER_TASKRUN
ring it visits, so that io_req_local_work_add() wakes the caller. The
wakeup goes to submitter_task, which need not be the caller. A
cancelling task can visit a ring whose local work belongs to another
task, and ring release and io_ring_exit_work() call in as well.
A cancelling task can also visit a ring that is still disabled, where
submitter_task is NULL. A later ZCRX event then passes it to
wake_up_state():
BUG: kernel NULL pointer dereference, address: 00000000000008e4
RIP: 0010:_raw_spin_lock_irqsave+0x1b/0x50
Call Trace:
try_to_wake_up+0x51/0x790
io_req_local_work_add+0xbb/0x1b0
zcrx_send_notif+0xf9/0x120
On an enabled ring, the same arm can replace the submitter's cq_wait_nr
batch threshold and cause an early wakeup. If the submitter is not
waiting on the ring, a later local work add can still find the count
armed and wake the submitter from an unrelated interruptible sleep.
Arm cq_wait_nr only when the caller is allowed to run the ring's local
work. The submitter-only rearm before cancellation sleeps already uses
the same ownership check.
ZCRX could skip disabled rings, as msg_ring does, but that leaves the
wrong arm on enabled rings. Work that ZCRX queues on a disabled ring
waits there until the ring is enabled, or until io_ring_exit_work()
drains it.
ZCRX events are the only local work a disabled ring can receive, so the
NULL pointer dereference needs commit 0719e10d826a ("io_uring/zcrx:
notify user when out of buffers"). Older kernels only see the early
wakeups.
Tested in a 2-vCPU x86-64 KVM guest with a reproducer that execs with
an io_uring request pending while ZCRX copy events target a disabled
DEFER_TASKRUN ring. v7.4-rc5 hit the NULL pointer dereference above.
With this patch, 1000 runs completed.
The bug was found with the help of an LLM, which was also used to write
the fix, the changelog and the tests.
Fixes: 360cd42c4e95 ("io_uring: optimise io_req_local_work_add")
Cc: stable@vger.kernel.org
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
Link: https://patch.msgid.link/20261204184949.185716-1-parri.andrea@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 has io_uring_try_cancel_requests() in io_uring.c]
---
io_uring/io_uring.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 1f67e0596faf..c27b0b3c4e7c 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3189,7 +3189,8 @@ static __cold bool io_uring_try_cancel_requests(struct io_ring_ctx *ctx,
bool ret = false;
/* set it so io_req_local_work_add() would wake us up */
- if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) {
+ if ((ctx->flags & IORING_SETUP_DEFER_TASKRUN) &&
+ io_allowed_defer_tw_run(ctx)) {
atomic_set(&ctx->cq_wait_nr, 1);
smp_mb();
}
--
2.55.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-12-05 23:11 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 23:10 [PATCH 6.12.y 00/15] io_uring fixes for 6.12-stable Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 04/15] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 05/15] io_uring: free the task context after a grace period Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 06/15] io_uring: free the ring " Jens Axboe
2026-12-05 23:10 ` [PATCH 6.12.y 07/15] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 08/15] io_uring: make ctx->timeout_lock a raw spinlock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 09/15] io_uring/timeout: flush timeouts outside of the timeout lock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 10/15] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 11/15] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 12/15] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 13/15] io_uring_poll: kill the no longer necessary barrier after poll_wait() Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 14/15] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:11 ` [PATCH 6.12.y 15/15] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.