On 2/18/25 22:42, Keith Busch wrote:
From: Keith Busch <kbusch@xxxxxxxxxx> Provide new operations for the user to request mapping an active request to an io uring instance's buf_table. The user has to provide the index it wants to install the buffer. A reference count is taken on the request to ensure it can't be completed while it is active in a ring's buf_table. Signed-off-by: Keith Busch <kbusch@xxxxxxxxxx> --- drivers/block/ublk_drv.c | 137 +++++++++++++++++++++++++--------- include/uapi/linux/ublk_cmd.h | 4 + 2 files changed, 105 insertions(+), 36 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 529085181f355..0c753176b14e9 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -51,6 +51,9 @@
...
+static int ublk_unregister_io_buf(struct io_uring_cmd *cmd, + struct ublk_queue *ubq, int tag, + const struct ublksrv_io_cmd *ub_cmd, + unsigned int issue_flags) +{ + struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx; + struct ublk_device *ub = cmd->file->private_data; + int index = (int)ub_cmd->addr; + struct ublk_rq_data *data; + struct request *req; + + if (!ub) + return -EPERM; + + req = blk_mq_tag_to_rq(ub->tag_set.tags[ubq->q_id], tag);
Shouldn't there some speculation sanitisation for the tag as well? Looks like a user passed value directly indexing an array.
+ if (!req) + return -EINVAL; + + data = blk_mq_rq_to_pdu(req); + io_buffer_unregister_bvec(ctx, index, issue_flags); + return 0; +} +
Pavel Begunkov