* [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable
@ 2026-12-05 23:11 Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
Hi Greg,
Here are 14 io_uring patches for 6.18-stable. Patches 1, 2, 3, 6, 7, 8,
9 and 10 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 11,
12 and 14 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 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; 13 (v7.1) for 14, which needs
ifq->kern_readable.
The series applies on top of v6.18.66 plus queue-6.18 at stable-queue
commit 16dfa5cc8e2f. It also applies to v6.18.66 alone.
Patches 5, 11, 13 and 14 needed changes for 6.18. 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; 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.18.66, and v6.18.66 plus these patches. The patched kernel
fails exactly the tests that v6.18.66 fails (napi-test times out;
read-mshot, read-mshot-fuse, ringbuf-read, send-zerocopy, timestamp,
vec-regbuf and waitid fail), all from the test environment. No WARNING,
BUG, lockdep or KASAN report in dmesg on either kernel. The zcrx
changes in 13 and 14 are build tested only, the guests have no NIC
that supports zcrx. io_uring/ builds without warnings on v6.18.66
plus queue-6.18 plus this series.
CVE assessment, by the io_uring maintainer:
Should get a CVE:
3/14 io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
6/14 io_uring: free the ring after a grace period
7/14 io_uring/filetable: don't install O_PATH files
8/14 io_uring/cancel: always walk links under timeout_lock
9/14 io_uring/net: don't count the buffers of a send bundle
10/14 io_uring/net: restore the cmsg buffer on recvmsg retry
Should not get a CVE:
1/14 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/14 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/14 io_uring/tctx: add separate lock for list of tctx's in ctx
prep for 6/14
5/14 io_uring: free the task context after a grace period
Fixes 4/14 of this series, no release has the bug.
11/14 io_uring: close poll activation race when enabling rings
Missed poll wakeup on the app's own ring.
12/14 io_uring/cancel: arm local work wakeups only for submitter
Early or spurious wakeups of the submitter, no crash in this
tree.
13/14 io_uring/zcrx: cache fallback availability in zcrx ctx
prep for 14/14
14/14 io_uring/zcrx: don't sync dma-bufs
Needs a zcrx ifq, which needs CAP_NET_ADMIN.
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 (1):
io_uring/tctx: add separate lock for list of tctx's in ctx
Louis Thiery (1):
io_uring/net: don't charge the folio offset to truesize for managed
frags
Pavel Begunkov (2):
io_uring/zcrx: cache fallback availability in zcrx ctx
io_uring/zcrx: don't sync dma-bufs
include/linux/io_uring_types.h | 13 ++++++++++++-
io_uring/cancel.c | 26 +++++++++++++++-----------
io_uring/filetable.c | 3 +++
io_uring/io_uring.c | 18 +++++++++++++-----
io_uring/kbuf.c | 3 +++
io_uring/net.c | 27 +++++++++++++++++++++------
io_uring/register.c | 2 ++
io_uring/tctx.c | 13 ++++++++-----
io_uring/zcrx.c | 18 +++++++++++++++---
io_uring/zcrx.h | 1 +
10 files changed, 93 insertions(+), 31 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 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 e8d5d17fc754..f9ec1e709ef8 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1484,7 +1484,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] 15+ messages in thread
* [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ 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 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 f9ec1e709ef8..fa70b07b73f8 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1114,6 +1114,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] 15+ messages in thread
* [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ 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 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 6659f56e91fc..1f95b64731dd 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -413,6 +413,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] 15+ messages in thread
* [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (2 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period Jens Axboe
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 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>
---
include/linux/io_uring_types.h | 8 +++++++-
io_uring/cancel.c | 5 +++++
io_uring/io_uring.c | 5 +++++
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 5d00cc2d396a..97f836654425 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -433,11 +433,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 471d6f2e5f18..92bee62c09ad 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -197,7 +197,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 */
@@ -210,6 +212,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;
@@ -508,6 +511,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;
@@ -520,6 +524,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/io_uring.c b/io_uring/io_uring.c
index df5f33a0f937..75dc5659a8da 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -344,6 +344,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
INIT_LIST_HEAD(&ctx->ltimeout_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);
xa_init_flags(&ctx->zcrx_ctxs, XA_FLAGS_ALLOC);
@@ -3241,6 +3242,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));
@@ -3252,6 +3254,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
@@ -3268,7 +3271,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);
diff --git a/io_uring/register.c b/io_uring/register.c
index de49874e8502..2de06dca8fe1 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -321,6 +321,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))
@@ -331,6 +332,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 0e4445d3a83c..b4a44675093e 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -144,9 +144,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;
}
@@ -184,9 +184,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] 15+ messages in thread
* [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (3 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 06/14] io_uring: free the ring " Jens Axboe
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ 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 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.18 has no io_uring_free_tctx(), the tctx is freed in
__io_uring_free()]
---
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 97f836654425..bdb0dc928c6e 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -130,6 +130,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 75dc5659a8da..fb4528bc3aac 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -724,6 +724,8 @@ static inline void io_put_task(struct io_kiocb *req)
if (likely(tctx->task == current)) {
tctx->cached_refs++;
} else {
+ 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 b4a44675093e..c7b08c9a1657 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -62,7 +62,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] 15+ messages in thread
* [PATCH 6.18.y 06/14] io_uring: free the ring after a grace period
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (4 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 07/14] io_uring/filetable: don't install O_PATH files Jens Axboe
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ 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 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 bdb0dc928c6e..a866cbb92620 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -447,6 +447,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 fb4528bc3aac..d300026c74bf 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3068,7 +3068,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
kvfree(ctx->cancel_table.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 c7b08c9a1657..602b5af32053 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -186,7 +186,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] 15+ messages in thread
* [PATCH 6.18.y 07/14] io_uring/filetable: don't install O_PATH files
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (5 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 06/14] io_uring: free the ring " Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 08/14] io_uring/cancel: always walk links under timeout_lock Jens Axboe
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ 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 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 cb1838c9fc37..f547ab1193b1 100644
--- a/io_uring/filetable.c
+++ b/io_uring/filetable.c
@@ -67,6 +67,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_table.data.nr)
return -ENXIO;
if (slot_index >= ctx->file_table.data.nr)
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6.18.y 08/14] io_uring/cancel: always walk links under timeout_lock
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (6 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 07/14] 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.18.y 09/14] io_uring/net: don't count the buffers of a send bundle Jens Axboe
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ 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>
---
io_uring/cancel.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index 92bee62c09ad..b4d31de286fe 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -432,6 +432,7 @@ static bool io_match_linked(struct io_kiocb *head)
bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
bool cancel_all)
{
+ struct io_ring_ctx *ctx = head->ctx;
bool matched;
if (tctx && head->tctx != tctx)
@@ -439,16 +440,13 @@ bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
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] 15+ messages in thread
* [PATCH 6.18.y 09/14] io_uring/net: don't count the buffers of a send bundle
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (7 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 08/14] 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.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ 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 fa70b07b73f8..09ef15e0700e 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -533,12 +533,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] 15+ messages in thread
* [PATCH 6.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (8 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 09/14] 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.18.y 11/14] io_uring: close poll activation race when enabling rings Jens Axboe
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ 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 09ef15e0700e..476ae9b38b63 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1045,6 +1045,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;
@@ -1082,6 +1084,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);
@@ -1106,6 +1110,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);
return IOU_RETRY;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6.18.y 11/14] io_uring: close poll activation race when enabling rings
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (9 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 10/14] 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.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ 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.18 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 d300026c74bf..2a8fb7a43c80 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3115,13 +3115,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);
rcu_read_lock();
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (10 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 11/14] io_uring: close poll activation race when enabling rings Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs Jens Axboe
13 siblings, 0 replies; 15+ 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>
---
io_uring/cancel.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index b4d31de286fe..4971dbaaf929 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -537,7 +537,8 @@ __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] 15+ messages in thread
* [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (11 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs Jens Axboe
13 siblings, 0 replies; 15+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Pavel Begunkov <asml.silence@gmail.com>
Commit 5c727ce042988df45232cfdb6599bb46116fd69c upstream.
Store a flag in struct io_zcrx_ifq telling if the backing memory is
normal page or dmabuf based. It was looking it up from the area, however
it logically allocates from the zcrx ctx and not a particular area, and
once we add more than one area it'll become a mess.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://patch.msgid.link/65e75408a7758fe7e60fae89b7a8d5ae4857f515.1774261953.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.18 has no ZCRX_REG_NODEV or zcrx_register_netdev(), set
kern_readable before the netdev lookup in io_register_zcrx_ifq(), and
its io_zcrx_append_area() has no WARN_ON_ONCE() on ifq->area]
---
io_uring/zcrx.c | 9 ++++++++-
io_uring/zcrx.h | 1 +
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index b725dab91732..385e6d793d17 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -409,8 +409,13 @@ static void io_zcrx_free_area(struct io_zcrx_area *area)
static int io_zcrx_append_area(struct io_zcrx_ifq *ifq,
struct io_zcrx_area *area)
{
+ bool kern_readable = !area->mem.is_dmabuf;
+
if (ifq->area)
return -EINVAL;
+ if (WARN_ON_ONCE(ifq->kern_readable != kern_readable))
+ return -EINVAL;
+
ifq->area = area;
return 0;
}
@@ -608,6 +613,8 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
if (ret)
goto err;
+ ifq->kern_readable = !(area.flags & IORING_ZCRX_AREA_DMABUF);
+
ifq->netdev = netdev_get_by_index_lock(current->nsproxy->net_ns, reg.if_idx);
if (!ifq->netdev) {
ret = -ENODEV;
@@ -974,7 +981,7 @@ static struct net_iov *io_alloc_fallback_niov(struct io_zcrx_ifq *ifq)
struct io_zcrx_area *area = ifq->area;
struct net_iov *niov = NULL;
- if (area->mem.is_dmabuf)
+ if (!ifq->kern_readable)
return NULL;
scoped_guard(spinlock_bh, &area->freelist_lock) {
diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h
index a48871b5adad..e1174fa957a2 100644
--- a/io_uring/zcrx.h
+++ b/io_uring/zcrx.h
@@ -42,6 +42,7 @@ struct io_zcrx_ifq {
struct io_ring_ctx *ctx;
struct io_zcrx_area *area;
unsigned niov_shift;
+ bool kern_readable;
spinlock_t rq_lock ____cacheline_aligned_in_smp;
struct io_uring *rq_ring;
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
` (12 preceding siblings ...)
2026-12-05 23:11 ` [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx Jens Axboe
@ 2026-12-05 23:11 ` Jens Axboe
13 siblings, 0 replies; 15+ messages in thread
From: Jens Axboe @ 2026-12-05 23:11 UTC (permalink / raw)
To: stable; +Cc: io-uring, gregkh
From: Pavel Begunkov <asml.silence@gmail.com>
Commit 7e3dc305a86e40ce1f9cd926ecd06d339468f5cb upstream.
dma-bufs follow different synchronisation rules comparing to normal
memory, the user accessing it must use proper API like
DMA_BUF_IOCTL_SYNC. Don't sync dma-buf backed buffers with the
dma_sync_*() family of helpers.
Fixes: a5c98e9424573 ("io_uring/zcrx: dmabuf backed zerocopy receive")
Cc: stable@vger.kernel.org
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Link: https://patch.msgid.link/8e93a756a3b8fea2be7935d34e1b833fd98e40ea.1796301395.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.18 syncs one niov at a time in io_zcrx_sync_for_device(),
which gets the ifq from io_pp_to_ifq(), and io_pp_zc_init() takes a
ctx ref rather than an ifq ref]
---
io_uring/zcrx.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 385e6d793d17..133c0ca0a559 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -299,14 +299,15 @@ static void io_zcrx_sync_for_device(struct page_pool *pool,
struct net_iov *niov)
{
#if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC)
+ struct io_zcrx_ifq *ifq = io_pp_to_ifq(pool);
dma_addr_t dma_addr;
unsigned niov_size;
- if (!dma_dev_need_sync(pool->p.dev))
+ if (!ifq->kern_readable || !dma_dev_need_sync(pool->p.dev))
return;
- niov_size = 1U << io_pp_to_ifq(pool)->niov_shift;
+ niov_size = 1U << ifq->niov_shift;
dma_addr = page_pool_get_dma_addr_netmem(net_iov_to_netmem(niov));
__dma_sync_single_for_device(pool->p.dev, dma_addr + pool->p.offset,
niov_size, pool->p.dma_dir);
@@ -902,6 +903,10 @@ static int io_pp_zc_init(struct page_pool *pp)
if (ret)
return ret;
+ if (!ifq->kern_readable) {
+ pp->dma_sync_for_cpu = false;
+ pp->dma_sync = false;
+ }
percpu_ref_get(&ifq->ctx->refs);
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-12-05 23:12 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 06/14] io_uring: free the ring " Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 07/14] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 08/14] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 09/14] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 11/14] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs 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.