Skip to content

Commit 2ff9494

Browse files
Xinyu Zhangaxboe
authored andcommitted
block: fix sanity checks in blk_rq_map_user_bvec
blk_rq_map_user_bvec contains a check bytes + bv->bv_len > nr_iter which causes unnecessary failures in NVMe passthrough I/O, reproducible as follows: - register a 2 page, page-aligned buffer against a ring - use that buffer to do a 1 page io_uring NVMe passthrough read The second (i = 1) iteration of the loop in blk_rq_map_user_bvec will then have nr_iter == 1 page, bytes == 1 page, bv->bv_len == 1 page, so the check bytes + bv->bv_len > nr_iter will succeed, causing the I/O to fail. This failure is unnecessary, as when the check succeeds, it means we've checked the entire buffer that will be used by the request - i.e. blk_rq_map_user_bvec should complete successfully. Therefore, terminate the loop early and return successfully when the check bytes + bv->bv_len > nr_iter succeeds. While we're at it, also remove the check that all segments in the bvec are single-page. While this seems to be true for all users of the function, it doesn't appear to be required anywhere downstream. CC: stable@vger.kernel.org Signed-off-by: Xinyu Zhang <xizhang@purestorage.com> Co-developed-by: Uday Shankar <ushankar@purestorage.com> Signed-off-by: Uday Shankar <ushankar@purestorage.com> Fixes: 3798754 ("block: extend functionality to map bvec iterator") Link: https://lore.kernel.org/r/20241023211519.4177873-1-ushankar@purestorage.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 49c234b commit 2ff9494

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

block/blk-map.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,7 @@ static int blk_rq_map_user_bvec(struct request *rq, const struct iov_iter *iter)
600600
if (nsegs >= nr_segs || bytes > UINT_MAX - bv->bv_len)
601601
goto put_bio;
602602
if (bytes + bv->bv_len > nr_iter)
603-
goto put_bio;
604-
if (bv->bv_offset + bv->bv_len > PAGE_SIZE)
605-
goto put_bio;
603+
break;
606604

607605
nsegs++;
608606
bytes += bv->bv_len;

0 commit comments

Comments
 (0)