Skip to content

Commit 5f14404

Browse files
isilenceaxboe
authored andcommitted
io_uring/cmd: don't expose entire cmd async data
io_uring needs private bits in cmd's ->async_data, and they should never be exposed to drivers as it'd certainly be abused. Leave struct io_uring_cmd_data for the drivers but wrap it into a structure. It's a prep patch and doesn't do anything useful yet. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/20250319061251.21452-3-sidong.yang@furiosa.ai Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 575e7b0 commit 5f14404

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

io_uring/io_uring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
335335
sizeof(struct io_async_rw),
336336
offsetof(struct io_async_rw, clear));
337337
ret |= io_alloc_cache_init(&ctx->cmd_cache, IO_ALLOC_CACHE_MAX,
338-
sizeof(struct io_uring_cmd_data), 0);
338+
sizeof(struct io_async_cmd), 0);
339339
spin_lock_init(&ctx->msg_lock);
340340
ret |= io_alloc_cache_init(&ctx->msg_cache, IO_ALLOC_CACHE_MAX,
341341
sizeof(struct io_kiocb), 0);

io_uring/opdef.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ const struct io_issue_def io_issue_defs[] = {
416416
.plug = 1,
417417
.iopoll = 1,
418418
.iopoll_queue = 1,
419-
.async_size = sizeof(struct io_uring_cmd_data),
419+
.async_size = sizeof(struct io_async_cmd),
420420
.prep = io_uring_cmd_prep,
421421
.issue = io_uring_cmd,
422422
},

io_uring/uring_cmd.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
2020
{
2121
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
22-
struct io_uring_cmd_data *cache = req->async_data;
22+
struct io_async_cmd *ac = req->async_data;
23+
struct io_uring_cmd_data *cache = &ac->data;
2324

2425
if (cache->op_data) {
2526
kfree(cache->op_data);
@@ -169,12 +170,15 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *req,
169170
const struct io_uring_sqe *sqe)
170171
{
171172
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
172-
struct io_uring_cmd_data *cache;
173+
struct io_async_cmd *ac;
173174

174-
cache = io_uring_alloc_async_data(&req->ctx->cmd_cache, req);
175-
if (!cache)
175+
/* see io_uring_cmd_get_async_data() */
176+
BUILD_BUG_ON(offsetof(struct io_async_cmd, data) != 0);
177+
178+
ac = io_uring_alloc_async_data(&req->ctx->cmd_cache, req);
179+
if (!ac)
176180
return -ENOMEM;
177-
cache->op_data = NULL;
181+
ac->data.op_data = NULL;
178182

179183
/*
180184
* Unconditionally cache the SQE for now - this is only needed for
@@ -183,8 +187,8 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *req,
183187
* that it doesn't read in per-op data, play it safe and ensure that
184188
* any SQE data is stable beyond prep. This can later get relaxed.
185189
*/
186-
memcpy(cache->sqes, sqe, uring_sqe_size(req->ctx));
187-
ioucmd->sqe = cache->sqes;
190+
memcpy(ac->data.sqes, sqe, uring_sqe_size(req->ctx));
191+
ioucmd->sqe = ac->data.sqes;
188192
return 0;
189193
}
190194

io_uring/uring_cmd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
#include <linux/io_uring/cmd.h>
4+
5+
struct io_async_cmd {
6+
struct io_uring_cmd_data data;
7+
};
8+
39
int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags);
410
int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
511

0 commit comments

Comments
 (0)