Skip to content

Commit fd5a005

Browse files
calebsanderaxboe
authored andcommitted
ublk: move offset check out of __ublk_check_and_get_req()
__ublk_check_and_get_req() checks that the passed in offset is within the data length of the specified ublk request. However, only user copy (ublk_check_and_get_req()) supports accessing ublk request data at a nonzero offset. Zero-copy buffer registration (ublk_register_io_buf()) always passes 0 for the offset, so the check is unnecessary. Move the check from __ublk_check_and_get_req() to ublk_check_and_get_req(). Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ca80afd commit fd5a005

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static void ublk_io_release(void *priv);
255255
static void ublk_stop_dev_unlocked(struct ublk_device *ub);
256256
static void ublk_abort_queue(struct ublk_device *ub, struct ublk_queue *ubq);
257257
static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
258-
u16 q_id, u16 tag, struct ublk_io *io, size_t offset);
258+
u16 q_id, u16 tag, struct ublk_io *io);
259259
static inline unsigned int ublk_req_build_flags(struct request *req);
260260

261261
static inline struct ublksrv_io_desc *
@@ -2297,7 +2297,7 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
22972297
if (!ublk_dev_support_zero_copy(ub))
22982298
return -EINVAL;
22992299

2300-
req = __ublk_check_and_get_req(ub, q_id, tag, io, 0);
2300+
req = __ublk_check_and_get_req(ub, q_id, tag, io);
23012301
if (!req)
23022302
return -EINVAL;
23032303

@@ -2591,7 +2591,7 @@ static int ublk_ch_uring_cmd_local(struct io_uring_cmd *cmd,
25912591
}
25922592

25932593
static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
2594-
u16 q_id, u16 tag, struct ublk_io *io, size_t offset)
2594+
u16 q_id, u16 tag, struct ublk_io *io)
25952595
{
25962596
struct request *req;
25972597

@@ -2612,9 +2612,6 @@ static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
26122612
if (!ublk_rq_has_data(req))
26132613
goto fail_put;
26142614

2615-
if (offset > blk_rq_bytes(req))
2616-
goto fail_put;
2617-
26182615
return req;
26192616
fail_put:
26202617
ublk_put_req_ref(io, req);
@@ -2696,10 +2693,15 @@ ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
26962693
return -EINVAL;
26972694

26982695
io = &ubq->ios[tag];
2699-
req = __ublk_check_and_get_req(ub, q_id, tag, io, buf_off);
2696+
req = __ublk_check_and_get_req(ub, q_id, tag, io);
27002697
if (!req)
27012698
return -EINVAL;
27022699

2700+
if (buf_off > blk_rq_bytes(req)) {
2701+
ret = -EINVAL;
2702+
goto out;
2703+
}
2704+
27032705
if (!ublk_check_ubuf_dir(req, dir)) {
27042706
ret = -EACCES;
27052707
goto out;

0 commit comments

Comments
 (0)