All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable
@ 2026-12-05 23:12 Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.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:12 UTC (permalink / raw)
  To: stable; +Cc: io-uring, gregkh

Hi Greg,

Here are 15 io_uring fixes for 7.3-stable. Patches 1-11 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
12-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").

The series applies on top of v7.3.7 plus queue-7.3 at stable-queue
commit 16dfa5cc8e2f. It also applies to v7.3.7 alone.

None of the patches needed changes, they are the upstream commits as
they are.

Please take 6 and 7 together: both are needed for the walk of a link
chain under timeout_lock to be safe against a linked timeout that goes
away.

Testing: the liburing test suite (liburing-2.15-76-ged312b3c) was run in
KVM guests with PROVE_LOCKING on two kernels: v7.3.7, and v7.3.7 plus
these patches. The patched kernel fails exactly the tests that v7.3.7
fails (napi-test times out; cbpf_filter, iowait, 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 change in 14 is build
tested only, the guests have no NIC that supports zcrx. io_uring/ builds
without warnings on v7.3.7 plus queue-7.3 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
   4/15 io_uring: free the ring after a grace period
   5/15 io_uring/filetable: don't install O_PATH files
   6/15 io_uring/timeout: hold timeout_lock for the link splice
   7/15 io_uring/cancel: always walk links under timeout_lock
   8/15 io_uring/net: don't count the buffers of a send bundle
   9/15 io_uring/net: restore the cmsg buffer on recvmsg retry
  15/15 io_uring: enforce task restrictions on blind MSG_RING

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.
  10/15 io_uring/openclose: allow an empty path with O_EMPTYPATH
        Functional fix, a valid open failed with -ENOENT.
  11/15 io_uring/bpf-ops: validate loop_step before registration
        The WARN needs a struct_ops map, which needs CAP_BPF.
  12/15 io_uring: close poll activation race when enabling rings
        Missed poll wakeup on the app's own ring.
  13/15 io_uring/cancel: arm local work wakeups only for submitter
        Needs a zcrx ifq for the crash, which needs CAP_NET_ADMIN.
  14/15 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 ring after a grace period
  io_uring/filetable: don't install O_PATH files
  io_uring/timeout: hold timeout_lock for the link splice
  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

Hengyu Liang (1):
  io_uring/openclose: allow an empty path with O_EMPTYPATH

Louis Thiery (1):
  io_uring/net: don't charge the folio offset to truesize for managed
    frags

Pavel Begunkov (1):
  io_uring/zcrx: don't sync dma-bufs

Sechang Lim (1):
  io_uring/bpf-ops: validate loop_step before registration

Shawn Shao (1):
  io_uring: enforce task restrictions on blind MSG_RING

 include/linux/io_uring_types.h |  2 ++
 io_uring/bpf-ops.c             |  8 +++++++
 io_uring/cancel.c              | 21 +++++++++---------
 io_uring/filetable.c           |  3 +++
 io_uring/io_uring.c            | 39 +++++++---------------------------
 io_uring/io_uring.h            | 21 ++++++++++++++++++
 io_uring/kbuf.c                |  3 +++
 io_uring/net.c                 | 27 +++++++++++++++++------
 io_uring/openclose.c           |  5 ++++-
 io_uring/register.c            | 21 ++++++++++++++++++
 io_uring/tctx.c                |  3 +++
 io_uring/timeout.c             |  5 ++++-
 io_uring/zcrx.c                |  6 +++++-
 13 files changed, 113 insertions(+), 51 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 7.3.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.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:12 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 4b36883e101b..d9eecff5a935 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1501,7 +1501,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 7.3.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.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:12 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 d9eecff5a935..f218dac1c2e0 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] 16+ messages in thread

* [PATCH 7.3.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 04/15] io_uring: free the ring after a grace period Jens Axboe
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 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 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] 16+ messages in thread

* [PATCH 7.3.y 04/15] io_uring: free the ring after a grace period
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (2 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 05/15] io_uring/filetable: don't install O_PATH files Jens Axboe
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 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 1c85ce0e471d..61d4a9e3549e 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -516,6 +516,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 c6bd17cca45f..f10035424a78 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2323,7 +2323,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] 16+ messages in thread

* [PATCH 7.3.y 05/15] io_uring/filetable: don't install O_PATH files
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (3 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 04/15] io_uring: free the ring after a grace period Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 06/15] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 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] 16+ messages in thread

* [PATCH 7.3.y 06/15] io_uring/timeout: hold timeout_lock for the link splice
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (4 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 05/15] io_uring/filetable: don't install O_PATH files Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 07/15] io_uring/cancel: always walk links under timeout_lock Jens Axboe
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 UTC (permalink / raw)
  To: stable; +Cc: io-uring, gregkh

From: Chris Mason <mason@kernel.org>

Commit 40162f8314a98948e0791b580024bbc899d2ee81 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 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 b46a50b39517..cdc41634c324 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] 16+ messages in thread

* [PATCH 7.3.y 07/15] io_uring/cancel: always walk links under timeout_lock
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (5 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 06/15] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 08/15] io_uring/net: don't count the buffers of a send bundle Jens Axboe
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 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 6be224ab53dc..b2fa12354499 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] 16+ messages in thread

* [PATCH 7.3.y 08/15] io_uring/net: don't count the buffers of a send bundle
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (6 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 07/15] io_uring/cancel: always walk links under timeout_lock Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:12 ` [PATCH 7.3.y 09/15] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 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 f218dac1c2e0..2e1d66504266 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] 16+ messages in thread

* [PATCH 7.3.y 09/15] io_uring/net: restore the cmsg buffer on recvmsg retry
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (7 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 08/15] io_uring/net: don't count the buffers of a send bundle Jens Axboe
@ 2026-12-05 23:12 ` Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 10/15] io_uring/openclose: allow an empty path with O_EMPTYPATH Jens Axboe
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:12 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 2e1d66504266..688db0f4af4d 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] 16+ messages in thread

* [PATCH 7.3.y 10/15] io_uring/openclose: allow an empty path with O_EMPTYPATH
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (8 preceding siblings ...)
  2026-12-05 23:12 ` [PATCH 7.3.y 09/15] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
@ 2026-12-05 23:13 ` Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 11/15] io_uring/bpf-ops: validate loop_step before registration Jens Axboe
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:13 UTC (permalink / raw)
  To: stable; +Cc: io-uring, gregkh

From: Hengyu Liang <hengyul@cs.unc.edu>

Commit 080434cbb0e9bf03e83f35ebc1cb339546ff6e1a upstream.

Commit 31cf44efa6df ("vfs: add O_EMPTYPATH to openat(2)/openat2(2)")
made build_open_flags() accept O_EMPTYPATH and turn it into
LOOKUP_EMPTY, so that openat(fd, "", O_EMPTYPATH) reopens the file
behind fd.

However, io_uring also uses build_open_flags(), but __io_openat_prep()
still copies the name with delayed_getname(), which rejects an empty
name with -ENOENT. As of now, IORING_OP_OPENAT and IORING_OP_OPENAT2
accept O_EMPTYPATH, but fail on the empty path this flag is meant for.

Before 31cf44efa6df, both calls fail: it prints "openat: -1" and
"IORING_OP_OPENAT: -2". After that commit (v7.2), the result is:

    openat: 4
    IORING_OP_OPENAT: -2

Copy the name with delayed_getname_uflags() and AT_EMPTY_PATH when
O_EMPTYPATH is set, as io_uring's statx already does for AT_EMPTY_PATH.

Fixes: 31cf44efa6df ("vfs: add O_EMPTYPATH to openat(2)/openat2(2)")
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Link: https://patch.msgid.link/20261125180817.3682397-1-hengyul@cs.unc.edu
Reviewed-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/openclose.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/io_uring/openclose.c b/io_uring/openclose.c
index 24cf3ce2e2bc..29fe31f16a2b 100644
--- a/io_uring/openclose.c
+++ b/io_uring/openclose.c
@@ -54,6 +54,7 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
 {
 	struct io_open *open = io_kiocb_to_cmd(req, struct io_open);
 	const char __user *fname;
+	int uflags = 0;
 	int ret;
 
 	if (unlikely(sqe->buf_index))
@@ -67,7 +68,9 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
 
 	open->dfd = READ_ONCE(sqe->fd);
 	fname = u64_to_user_ptr(READ_ONCE(sqe->addr));
-	ret = delayed_getname(&open->filename, fname);
+	if (open->how.flags & O_EMPTYPATH)
+		uflags = AT_EMPTY_PATH;
+	ret = delayed_getname_uflags(&open->filename, fname, uflags);
 	if (unlikely(ret))
 		return ret;
 	req->flags |= REQ_F_NEED_CLEANUP;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7.3.y 11/15] io_uring/bpf-ops: validate loop_step before registration
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (9 preceding siblings ...)
  2026-12-05 23:13 ` [PATCH 7.3.y 10/15] io_uring/openclose: allow an empty path with O_EMPTYPATH Jens Axboe
@ 2026-12-05 23:13 ` Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 12/15] io_uring: close poll activation race when enabling rings Jens Axboe
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:13 UTC (permalink / raw)
  To: stable; +Cc: io-uring, gregkh

From: Sechang Lim <rhkrqnwk98@gmail.com>

Commit ba0084f1402bdf2946282290a3fb0af8f3544759 upstream.

A struct_ops map with only ring_fd set leaves loop_step NULL. The
struct_ops update path skips a zero program fd, and bpf_ring_ops does
not validate the completed value. Without BPF_F_LINK, the update then
calls bpf_io_reg(), where io_install_bpf() triggers a kernel warning
before returning -EINVAL. With BPF_F_LINK, the warning occurs when the
link is created.

Validate loop_step before either registration path. Reject an incomplete
value with -EINVAL so malformed userspace input cannot trigger the
warning.

Fixes: 98f37634b12b ("io_uring/bpf-ops: implement bpf ops registration")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://patch.msgid.link/20261119115942.3613868-1-rhkrqnwk98@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/bpf-ops.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/io_uring/bpf-ops.c b/io_uring/bpf-ops.c
index 6c2a587fb1bf..dfa93144b090 100644
--- a/io_uring/bpf-ops.c
+++ b/io_uring/bpf-ops.c
@@ -157,6 +157,13 @@ static int bpf_io_check_member(const struct btf_type *t,
 	return 0;
 }
 
+static int bpf_io_validate(void *kdata)
+{
+	const struct io_uring_bpf_ops *ops = kdata;
+
+	return ops->loop_step ? 0 : -EINVAL;
+}
+
 static int bpf_io_init_member(const struct btf_type *t,
 			       const struct btf_member *member,
 			       void *kdata, const void *udata)
@@ -269,6 +276,7 @@ static struct bpf_struct_ops bpf_ring_ops = {
 	.check_member = bpf_io_check_member,
 	.init_member = bpf_io_init_member,
 	.init = bpf_io_init,
+	.validate = bpf_io_validate,
 	.cfi_stubs = &io_bpf_ops_stubs,
 	.name = "io_uring_bpf_ops",
 	.owner = THIS_MODULE,
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7.3.y 12/15] io_uring: close poll activation race when enabling rings
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (10 preceding siblings ...)
  2026-12-05 23:13 ` [PATCH 7.3.y 11/15] io_uring/bpf-ops: validate loop_step before registration Jens Axboe
@ 2026-12-05 23:13 ` Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 13/15] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:13 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>
---
 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 f10035424a78..e0a145071261 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2370,13 +2370,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(!(data_race(ctx->int_flags) & IO_RING_F_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(!(data_race(ctx->int_flags) & IO_RING_F_POLL_ACTIVATED)))
+		io_activate_pollwq(ctx);
 
 	rcu_read_lock();
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7.3.y 13/15] io_uring/cancel: arm local work wakeups only for submitter
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (11 preceding siblings ...)
  2026-12-05 23:13 ` [PATCH 7.3.y 12/15] io_uring: close poll activation race when enabling rings Jens Axboe
@ 2026-12-05 23:13 ` Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 14/15] io_uring/zcrx: don't sync dma-bufs Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 15/15] io_uring: enforce task restrictions on blind MSG_RING Jens Axboe
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:13 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 b2fa12354499..e0eb66ec33ce 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -543,7 +543,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] 16+ messages in thread

* [PATCH 7.3.y 14/15] io_uring/zcrx: don't sync dma-bufs
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (12 preceding siblings ...)
  2026-12-05 23:13 ` [PATCH 7.3.y 13/15] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
@ 2026-12-05 23:13 ` Jens Axboe
  2026-12-05 23:13 ` [PATCH 7.3.y 15/15] io_uring: enforce task restrictions on blind MSG_RING Jens Axboe
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:13 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>
---
 io_uring/zcrx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 6d7abb1636e7..9ee53a458dbf 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -354,7 +354,7 @@ static void zcrx_sync_for_device(struct page_pool *pp, struct io_zcrx_ifq *zcrx,
 	unsigned i, niov_size;
 	dma_addr_t dma_addr;
 
-	if (!dma_dev_need_sync(dev))
+	if (!zcrx->kern_readable || !dma_dev_need_sync(dev))
 		return;
 	niov_size = 1U << zcrx->niov_shift;
 
@@ -1425,6 +1425,10 @@ static int io_pp_zc_init(struct page_pool *pp)
 	if (pp->p.dma_dir != DMA_FROM_DEVICE)
 		return -EOPNOTSUPP;
 
+	if (!ifq->kern_readable) {
+		pp->dma_sync_for_cpu = false;
+		pp->dma_sync = false;
+	}
 	refcount_inc(&ifq->refs);
 	return 0;
 }
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7.3.y 15/15] io_uring: enforce task restrictions on blind MSG_RING
  2026-12-05 23:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
                   ` (13 preceding siblings ...)
  2026-12-05 23:13 ` [PATCH 7.3.y 14/15] io_uring/zcrx: don't sync dma-bufs Jens Axboe
@ 2026-12-05 23:13 ` Jens Axboe
  14 siblings, 0 replies; 16+ messages in thread
From: Jens Axboe @ 2026-12-05 23:13 UTC (permalink / raw)
  To: stable; +Cc: io-uring, gregkh

From: Shawn Shao <shawnq1@163.com>

Commit fc66b07da5f49aed1740b2007bf69e8774e17a1b upstream.

IORING_REGISTER_SEND_MSG_RING executes an embedded MSG_RING SQE
without going through normal submission. This bypasses per-task SQE
opcode restrictions and BPF filters.

Apply the same checks to the embedded request before sending the message.

Fixes: ed82f35b926b ("io_uring: allow registration of per-task restrictions")
Link: https://gist.github.com/shaos26/5175f691637a55377f1ce5c1e4b57dba
Signed-off-by: Shawn Shao <shawnq1@163.com>
Link: https://patch.msgid.link/20261205040843.2911303-1-shawnq1@163.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/io_uring.c | 28 ++--------------------------
 io_uring/io_uring.h | 21 +++++++++++++++++++++
 io_uring/register.c | 21 +++++++++++++++++++++
 3 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index e0a145071261..67afa59a1d40 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1777,31 +1777,6 @@ static void io_queue_sqe_fallback(struct io_kiocb *req)
 	}
 }
 
-/*
- * Check SQE restrictions (opcode and flags).
- *
- * Returns 'true' if SQE is allowed, 'false' otherwise.
- */
-static inline bool io_check_restriction(struct io_ring_ctx *ctx,
-					struct io_kiocb *req,
-					unsigned int sqe_flags)
-{
-	if (!(ctx->int_flags & IO_RING_F_OP_RESTRICTED))
-		return true;
-	if (!test_bit(req->opcode, ctx->restrictions.sqe_op))
-		return false;
-
-	if ((sqe_flags & ctx->restrictions.sqe_flags_required) !=
-	    ctx->restrictions.sqe_flags_required)
-		return false;
-
-	if (sqe_flags & ~(ctx->restrictions.sqe_flags_allowed |
-			  ctx->restrictions.sqe_flags_required))
-		return false;
-
-	return true;
-}
-
 static void io_init_drain(struct io_ring_ctx *ctx)
 {
 	struct io_kiocb *head = ctx->submit_state.link.head;
@@ -1899,7 +1874,8 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		}
 	}
 	if (unlikely(ctx->int_flags & (IO_RING_F_OP_RESTRICTED | IO_RING_F_DRAIN_ACTIVE | IO_RING_F_DRAIN_NEXT))) {
-		if (!io_check_restriction(ctx, req, sqe_flags))
+		if (!io_check_restriction(&ctx->restrictions, req->opcode,
+					  sqe_flags))
 			return io_init_fail_req(req, -EACCES);
 		/* knock it to the slow queue path, will be drained there */
 		if (ctx->int_flags & IO_RING_F_DRAIN_ACTIVE)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 0cb053aabe4b..e9893135524e 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -216,6 +216,27 @@ bool __io_alloc_req_refill(struct io_ring_ctx *ctx);
 
 void io_activate_pollwq(struct io_ring_ctx *ctx);
 void io_restriction_clone(struct io_restriction *dst, struct io_restriction *src);
+
+/* Check SQE restrictions (opcode and flags). */
+static inline bool io_check_restriction(const struct io_restriction *restrictions,
+					u8 opcode, unsigned int sqe_flags)
+{
+	if (!restrictions->op_registered)
+		return true;
+	if (!test_bit(opcode, restrictions->sqe_op))
+		return false;
+
+	if ((sqe_flags & restrictions->sqe_flags_required) !=
+	    restrictions->sqe_flags_required)
+		return false;
+
+	if (sqe_flags & ~(restrictions->sqe_flags_allowed |
+			  restrictions->sqe_flags_required))
+		return false;
+
+	return true;
+}
+
 void io_poison_req(struct io_kiocb *req);
 
 static inline void io_lockdep_assert_cq_locked(struct io_ring_ctx *ctx)
diff --git a/io_uring/register.c b/io_uring/register.c
index 62f492e6472f..6f491ba9c44c 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -1036,7 +1036,10 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 
 static int io_uring_register_send_msg_ring(void __user *arg, unsigned int nr_args)
 {
+	struct io_restriction *restrictions = current->io_uring_restrict;
 	struct io_uring_sqe sqe;
+	struct io_kiocb req = {};
+	int ret;
 
 	if (!arg || nr_args != 1)
 		return -EINVAL;
@@ -1048,6 +1051,24 @@ static int io_uring_register_send_msg_ring(void __user *arg, unsigned int nr_arg
 	if (sqe.opcode != IORING_OP_MSG_RING)
 		return -EINVAL;
 
+	if (restrictions) {
+		/* Apply per-task SQE policy to the embedded operation. */
+		if (!io_check_restriction(restrictions, sqe.opcode, sqe.flags))
+			return -EACCES;
+
+		req.opcode = sqe.opcode;
+		req.flags = (__force io_req_flags_t)sqe.flags;
+		req.cqe.user_data = sqe.user_data;
+		if (restrictions->bpf_filters) {
+			struct io_bpf_filter __rcu **filters =
+				restrictions->bpf_filters->filters;
+
+			ret = io_uring_run_bpf_filters(filters, &req);
+			if (ret)
+				return ret;
+		}
+	}
+
 	return io_uring_sync_msg_ring(&sqe);
 }
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-12-05 23:13 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:12 [PATCH 7.3.y 00/15] io_uring fixes for 7.3-stable Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 01/15] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 02/15] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 04/15] io_uring: free the ring after a grace period Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 05/15] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 06/15] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 07/15] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 08/15] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-12-05 23:12 ` [PATCH 7.3.y 09/15] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
2026-12-05 23:13 ` [PATCH 7.3.y 10/15] io_uring/openclose: allow an empty path with O_EMPTYPATH Jens Axboe
2026-12-05 23:13 ` [PATCH 7.3.y 11/15] io_uring/bpf-ops: validate loop_step before registration Jens Axboe
2026-12-05 23:13 ` [PATCH 7.3.y 12/15] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:13 ` [PATCH 7.3.y 13/15] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
2026-12-05 23:13 ` [PATCH 7.3.y 14/15] io_uring/zcrx: don't sync dma-bufs Jens Axboe
2026-12-05 23:13 ` [PATCH 7.3.y 15/15] io_uring: enforce task restrictions on blind MSG_RING 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.