Commit fc66b07da5f4 for kernel
commit fc66b07da5f49aed1740b2007bf69e8774e17a1b
Author: Shawn Shao <shawnq1@163.com>
Date: Sat Dec 5 04:08:43 2026 +0000
io_uring: enforce task restrictions on blind MSG_RING
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>
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index a3caadbeb384..e04c8690157a 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1824,31 +1824,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;
@@ -1946,7 +1921,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 c8592f4ef510..8da1a2d030ea 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -217,6 +217,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);
}