From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512417; b=F5qQWL4R8SDDgDh7ob7HReGPnY+yXIF0gkOageznIhoYMRtIiwkE1CDjTFT9CRL25K34 9GS43HpKYnkvoYOZC9s459MH8eLj8O/7A3+vJVEYnRWD6HeF0E64FQBIbumrEagAGKyQv LXRBIKuHGSgrCcUEnTi0rt9Bge5tV5JZeS/DSmZokmuQJaioh2R6oJP5t2NuxJ295VvCQ vjNq4rszejYTMRnuvl0sQpYaSnDeP0nf3qFffaKJ69iPA6cXVk5EDyXD8Cm62NYm0km0K aVL3uOrFCbBR2cm9SmEgttFozItB3dl5qAfphQmMXMR4Sh5DCRGIkrqM5cWAYiW5aTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512417; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=1nTGicBWD0cxj5d7QBYx+jZpY0loNeCYsfPBoL3OGyA=; b=z5CSLNqt3hwykueAvKjIkR2yDGCWi9lI13nTCLbbFfsK/S7h6mG038fmuMVlVn1JPMgd m9m69qhLJOrAkXublu+XaR219mtTrlfppYmLpXH8dWavMl4yGnQm5l+2ONeUdVY+6Xx4M MPLGqBhXzMRmh9WiwVJzqzvwmayi449sG2mlozuccOVEeASW4cGGx886D8/+x6WDJftat lKQEVYxTSCY76YbJHd+RXQyjVf29ypDzs1OYpN3ra0sh+nLWfag/fvGnoty5hla4tDTI2 2wRF4wzy0DWcOMZGA7n53SUYaYrX80cfip1XWSU1W4Lvlg0u676iDXlHGpIp/MeQahA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=ZHWE158Y; arc=none smtp.remote-ip=209.85.210.47 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AEE9606A32F for ; Sat, 5 Dec 2026 23:13:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8AEE9606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=ZHWE158Y Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-8479f46ecd8so979239a34.0 for ; Sat, 05 Dec 2026 15:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512416; x=1797117216; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1nTGicBWD0cxj5d7QBYx+jZpY0loNeCYsfPBoL3OGyA=; b=ZHWE158Y0OXRCq8LBOa8KPmdUM3+uCs7ViI7pNRSSB83+zxJuwKtPsUUgxZFGwh86G +MjqMaSV/e4brrQaxf3/ObNSfJ54lIJvcDxP5Cupys+qp+WrepDw9RhfaOaYosDa4daq aJz4VyOrWf7f0+c3LCXRCmvAluId9UadhbzzICWc+Vgu9/oFrDKUFTKKeowkaBh1eEPO XGHxe1zygRjztDq7vdNqJJu0MFRZquiJzSrdVRFo81YWUDFQUoTKnz9XnsEM/FeTFeQ5 9DFENjv+vjcuU5OGaGX2nEsucgH7jc3I4biwQxy8WzUtS9xOS86eB1wHkWVcqL4nIUid 6B8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512416; x=1797117216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1nTGicBWD0cxj5d7QBYx+jZpY0loNeCYsfPBoL3OGyA=; b=Tf6z5e0RrP7lBTvArxsOWpnLHVhKG9jp6+lbA5rCY1zonEG+rIJ9wl4b7VFd5iPQrm ZI5yRadmYknp62/i+pK521NyoGKDXIerZ41PvkaDVN2FNlh2tOUr11pB/pqiXMunSiiP QmNgLb/FNTOaj980sxTxKuLePaIyx2wEoefwj3yqBpxg/di5tecdmdWYADT4mDQ/qqCn nKNefHYdemsn8moMvb4yHRFcScRelTtvcs5j472h6xpw3eiA+ac6rOyLVN6dATDjWSbq m+KUjSpzZ9Z5PdQnrb+/zGBrJHHpib+826FWCWVMX9pkb99NfYzorJ2beFTp+msraqgR 6FWg== X-Gm-Message-State: APuU4Z/iKsnxe9XowBYIPvIi8QK9lTIGMIKUHnNOHly4lAyICRtH5qFi u3rrRjuzPb9Dgf9O1Gz5sGQ81JoxIhJHP/jKHAZINy+y5jKjUubyXT87l/OnpNqe2ttmcRkHeCo E8S+3wtY= X-Gm-Gg: AZFdTZeK9JKqk0qkBiulP0+y/Fe8jnk05yLVSkA0Sv146r6tTNr0ZkC8xlpI9utfoFt ekLchPAAhCGFFoFHR64YtsvDIJpU7sukLQ1fRydWEENaB6wrSgSqiKuiFPdJ8O+5/MIzmJjSrIb PqqUgDXXbLRg7B/NRaYijz4zUvj6KtciygLPO6aOigEnG1CFzWdzUyaEt9DvRUQP0QY7suZDMrt ElmMSei4AeN8xyyQWJOYahfq4kUwWXQp8nyd4JK91z7n1B6eSihszp86f3WH2sdNbJtdLQsN4lM qKJDI2qshS/S5xctaJC0C+G1aGE0Gl8nzu5C8E6Fw0PB0pD5Wt7m2exiSYgm5FBKnlgBZTGb/34 F58HpGB5pdQOm9+Vws5HxdlODVkddFrGKmMTSE2l+74R+HwOecn6wH3d/yhmCYG9h95yGQ/eBu8 IAo8j8kBKcEsrtX+xLcyh3x36tT1LQewXYBiP5cW076xJguoNkHrehVEy9uEtDmu5hRWJcLKwKg mBLnh1sUKWWK/DrhqL5Ki7uFrRdTkM962Ne98IFiHy+/+qmzVxIe+pJSZyaX0czacMCC7EzIHgk YI8tY1doW2gyvBDcoNBFs58I+53evD3PBkhBtuYpwOrE519d4rsB0rTDBIAYxKz4jngqHhGfZQM woCPo32KTL3crf9M8R1LKzRu9hmhhRRukAS5h X-Received: by 2002:a05:6830:3114:b0:85b:c75:dc65 with SMTP id 46e09a7af769-863f89c5636mr6935647a34.7.1796512416513; Sat, 05 Dec 2026 15:13:36 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f8331ff6sm6269737a34.22.2026.12.05.15.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:13:35 -0800 (PST) From: Jens Axboe 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 Message-ID: <20261205231305.4158103-16-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231305.4158103-1-axboe@kernel.dk> References: <20261205231305.4158103-1-axboe@kernel.dk> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Shawn Shao 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 Link: https://patch.msgid.link/20261205040843.2911303-1-shawnq1@163.com Signed-off-by: Jens Axboe --- 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