* [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 8afad1b2ddc0..f8d547c5e7d6 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1116,6 +1116,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] 11+ messages in thread* [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
2026-11-25 18:43 ` [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 03/10] io_uring: free the ring after a grace period Jens Axboe
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 873d66a06b36..78d29008919a 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -428,6 +428,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] 11+ messages in thread* [PATCH 03/10] io_uring: free the ring after a grace period
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
2026-11-25 18:43 ` [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-11-25 18:43 ` [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 04/10] io_uring: free the ring from an RCU work Jens Axboe
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 1468bcb02893..1b85872bb7ea 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -517,6 +517,8 @@ struct io_ring_ctx {
/* ctx exit and cancelation */
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 be5a4f9505e0..06ff99921871 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2368,7 +2368,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
xa_destroy(&ctx->io_bl_xa);
xa_destroy(&ctx->hpage_acct);
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 b4fecea3ea47..c6b7f5647f79 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -231,7 +231,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] 11+ messages in thread* [PATCH 04/10] io_uring: free the ring from an RCU work
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (2 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 03/10] io_uring: free the ring after a grace period Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 05/10] io_uring/filetable: don't install O_PATH files Jens Axboe
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe
The ring is currently freed in two steps: a synchronize_rcu() in
io_ring_exit_work() for DEFER_TASKRUN and SQPOLL rings, which pairs with
the RCU read sections in the task_work add paths, and a kfree_rcu() of
the ctx itself, which pairs with the one in io_uring_del_tctx_node().
The kfree_rcu() alone can't replace the synchronize_rcu(). The task_work
add paths also look at the ring memory (->rings and ->rings_rcu, for the
SQ flags) and at ->submitter_task, and io_ring_ctx_free() releases both
before it gets to the free of the ctx.
Instead of waiting for a grace period in the exit work, queue the whole
io_ring_ctx_free() as an RCU work, and make its final free a plain
kfree(). That is process context, as io_ring_ctx_free() needs, and
everything it tears down now happens after a grace period. This covers
the readers in the task_work add paths for all rings, and the unlock in
io_uring_del_tctx_node(), and removes both the synchronize_rcu() and the
rcu_head in the ctx.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/linux/io_uring_types.h | 4 ++--
io_uring/io_uring.c | 23 +++++++++++++++++------
io_uring/tctx.c | 2 +-
io_uring/tw.c | 2 +-
4 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 1b85872bb7ea..7a835113eac3 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -517,8 +517,8 @@ struct io_ring_ctx {
/* ctx exit and cancelation */
struct work_struct exit_work;
- /* the ctx is freed after a grace period, see io_uring_del_tctx_node() */
- struct rcu_head rcu;
+ /* the ctx is freed after a grace period, see io_ring_exit_work() */
+ struct rcu_work free_rwork;
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 06ff99921871..6808229edf07 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2368,7 +2368,15 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
xa_destroy(&ctx->io_bl_xa);
xa_destroy(&ctx->hpage_acct);
xa_destroy(&ctx->personalities);
- kfree_rcu(ctx, rcu);
+ kfree(ctx);
+}
+
+static __cold void io_ring_ctx_free_work(struct work_struct *work)
+{
+ struct io_ring_ctx *ctx = container_of(to_rcu_work(work),
+ struct io_ring_ctx, free_rwork);
+
+ io_ring_ctx_free(ctx);
}
static __cold void io_activate_pollwq_cb(struct callback_head *cb)
@@ -2660,11 +2668,14 @@ static __cold void io_ring_exit_work(struct work_struct *work)
spin_lock(&ctx->completion_lock);
spin_unlock(&ctx->completion_lock);
- /* pairs with the RCU read sections in the task_work add paths */
- if (ctx->flags & (IORING_SETUP_DEFER_TASKRUN | IORING_SETUP_SQPOLL))
- synchronize_rcu();
-
- io_ring_ctx_free(ctx);
+ /*
+ * Free the ring after a grace period. This pairs with the RCU read
+ * sections in the task_work add paths, which look at the rings and
+ * the submitter task, and with the one in io_uring_del_tctx_node(),
+ * which may still be unlocking ->tctx_lock.
+ */
+ INIT_RCU_WORK(&ctx->free_rwork, io_ring_ctx_free_work);
+ queue_rcu_work(iou_wq, &ctx->free_rwork);
}
static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
diff --git a/io_uring/tctx.c b/io_uring/tctx.c
index c6b7f5647f79..508a72fdfc1b 100644
--- a/io_uring/tctx.c
+++ b/io_uring/tctx.c
@@ -231,7 +231,7 @@ __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() */
+ /* keeps the ctx until the unlock is done, see io_ring_exit_work() */
rcu_read_lock();
mutex_unlock(&node->ctx->tctx_lock);
rcu_read_unlock();
diff --git a/io_uring/tw.c b/io_uring/tw.c
index b4a9e28ce779..41b3b9422d41 100644
--- a/io_uring/tw.c
+++ b/io_uring/tw.c
@@ -184,7 +184,7 @@ void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
struct io_ring_ctx *ctx = req->ctx;
int nr_wait;
- /* pairs with synchronize_rcu() in io_ring_exit_work() */
+ /* pairs with the grace period before the free in io_ring_exit_work() */
guard(rcu)();
/*
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 05/10] io_uring/filetable: don't install O_PATH files
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (3 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 04/10] io_uring: free the ring from an RCU work Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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] 11+ messages in thread* [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (4 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 05/10] io_uring/filetable: don't install O_PATH files Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock Jens Axboe
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 that has fired.
io-wq calls its match function under raw spinlocks, so there
io_match_task_safe() walks the link chain without ->uring_lock. It holds
->timeout_lock, which is enough only if a linked timeout leaves the
chain under that lock. But io_req_task_link_timeout() does the splice
under ->uring_lock alone. Once the ring is closed, the closing task runs
that task_work, and with a drain active the flush frees the request:
io_match_task_safe() io_cancel_local_task_work()
==================== ===========================
lock ->timeout_lock
io_match_linked()
req = head->link
lock ->uring_lock
io_req_task_link_timeout()
prev->link = req->link
io_req_task_complete()
io_submit_flush_completions()
io_free_batch_list()
io_queue_deferred()
__io_req_caches_free()
req = req->link
The fix used here is to hold ->timeout_lock as well for the splice,
which stays in task_work and under ->uring_lock.
Fixes: 49ae66eb8c27 ("io_uring: defer linked-timeout chain splice out of hrtimer context")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/timeout.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index db78059cfeab..46c01704b58f 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -392,11 +392,14 @@ static void io_req_task_link_timeout(struct io_tw_req tw_req, io_tw_token_t tw)
if (prev) {
/*
* splice the linked timeout out of prev's chain if the regular
- * completion path didn't already do it.
+ * completion path didn't already do it. io-wq cancellation
+ * walks the chain with only ->timeout_lock held.
*/
+ raw_spin_lock_irq(&req->ctx->timeout_lock);
if (prev->link == req)
prev->link = req->link;
req->link = NULL;
+ raw_spin_unlock_irq(&req->ctx->timeout_lock);
if (!tw.cancel) {
struct io_cancel_data cd = {
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (5 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle Jens Axboe
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 e3d9fe8fc982..5b57d27225ac 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -438,6 +438,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)
@@ -445,16 +446,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] 11+ messages in thread* [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (6 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 09/10] io_uring: drop cached task refs on ring release Jens Axboe
2026-11-25 18:43 ` [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 f8d547c5e7d6..9c69f37cb8aa 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -515,12 +515,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] 11+ messages in thread* [PATCH 09/10] io_uring: drop cached task refs on ring release
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (7 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
2026-11-25 18:43 ` [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
An exiting task can leak its own task_struct, if its exit releases a
ring that still has a request of that task in flight.
If a task frees its own request, io_put_task() doesn't put the task
reference but keeps it in tctx->cached_refs. An exiting task empties
that cache for the last time in io_uring_cancel_generic(). So whatever
frees requests in that task later on has to call
io_uring_drop_tctx_refs() afterwards, as tctx_task_work_run() does. The
cancel pass in io_ring_ctx_wait_and_kill() doesn't. With a timeout armed
on a DEFER_TASKRUN ring:
do_exit()
io_uring_files_cancel()
io_uring_cancel_generic()
io_uring_drop_tctx_refs()
io_tctx_cancel_done() is true, the timeout stays armed
exit_files()
io_uring_release()
io_ring_ctx_wait_and_kill()
io_ring_ctx_cancel()
io_kill_timeouts()
io_cancel_local_task_work()
io_put_task()
tctx->cached_refs++
Commit e775f93f2ab9 ("io_uring: ensure that cached task references are
always put on exit") added that call to io_ring_ctx_wait_and_kill().
Commit 02bac94bd8ef ("io_uring: don't iopoll from
io_ring_ctx_wait_and_kill()") removed it together with the completions
at release, and commit 89baa3154a72 ("io_uring: run cancelations
synchronously on ring release") brought only the completions back.
The fix used here is to restore that call, after the task that releases
the ring has run its cancelations.
Fixes: 89baa3154a72 ("io_uring: run cancelations synchronously on ring release")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/io_uring.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 6808229edf07..d8491f86e480 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2702,6 +2702,9 @@ static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
if (!(current->flags & PF_IO_WORKER)) {
io_ring_ctx_cancel(ctx);
io_ring_ctx_wait_inflight(ctx);
+ /* exit is past the drop in io_uring_cancel_generic() */
+ if (current->io_uring)
+ io_uring_drop_tctx_refs(current);
}
INIT_WORK(&ctx->exit_work, io_ring_exit_work);
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
` (8 preceding siblings ...)
2026-11-25 18:43 ` [PATCH 09/10] io_uring: drop cached task refs on ring release Jens Axboe
@ 2026-11-25 18:43 ` Jens Axboe
9 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2026-11-25 18:43 UTC (permalink / raw)
To: io-uring; +Cc: Chris Mason, Jens Axboe
From: Chris Mason <mason@kernel.org>
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 9c69f37cb8aa..b0d508b772ce 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1047,6 +1047,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;
@@ -1084,6 +1086,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);
@@ -1108,6 +1112,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] 11+ messages in thread