From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org
Subject: [PATCH 7.3.y 15/15] io_uring: enforce task restrictions on blind MSG_RING
Date: Sat, 5 Dec 2026 23:13:05 +0000 [thread overview]
Message-ID: <20261205231305.4158103-16-axboe@kernel.dk> (raw)
In-Reply-To: <20261205231305.4158103-1-axboe@kernel.dk>
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
prev parent reply other threads:[~2026-12-05 23:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jens Axboe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205231305.4158103-16-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=io-uring@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox