Skip to content

Commit edd05bb

Browse files
author
Ming Lei
committed
io_uring: don't assume uaddr alignment in io_vec_fill_bvec
JIRA: https://issues.redhat.com/browse/RHEL-106845 commit e1d7727 Author: Pavel Begunkov <asml.silence@gmail.com> Date: Tue Jun 24 14:40:35 2025 +0100 io_uring: don't assume uaddr alignment in io_vec_fill_bvec There is no guaranteed alignment for user pointers. Don't use mask trickery and adjust the offset by bv_offset. Cc: stable@vger.kernel.org Reported-by: David Hildenbrand <david@redhat.com> Fixes: 9ef4cbb ("io_uring: add infra for importing vectored reg buffers") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/io-uring/19530391f5c361a026ac9b401ff8e123bde55d98.1750771718.git.asml.silence@gmail.com/ Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 86b8485 commit edd05bb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

io_uring/rsrc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,6 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
13311331
{
13321332
unsigned long folio_size = 1 << imu->folio_shift;
13331333
unsigned long folio_mask = folio_size - 1;
1334-
u64 folio_addr = imu->ubuf & ~folio_mask;
13351334
struct bio_vec *res_bvec = vec->bvec;
13361335
size_t total_len = 0;
13371336
unsigned bvec_idx = 0;
@@ -1353,8 +1352,13 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
13531352
if (unlikely(check_add_overflow(total_len, iov_len, &total_len)))
13541353
return -EOVERFLOW;
13551354

1356-
/* by using folio address it also accounts for bvec offset */
1357-
offset = buf_addr - folio_addr;
1355+
offset = buf_addr - imu->ubuf;
1356+
/*
1357+
* Only the first bvec can have non zero bv_offset, account it
1358+
* here and work with full folios below.
1359+
*/
1360+
offset += imu->bvec[0].bv_offset;
1361+
13581362
src_bvec = imu->bvec + (offset >> imu->folio_shift);
13591363
offset &= folio_mask;
13601364

0 commit comments

Comments
 (0)