Skip to content

Commit e1d7727

Browse files
isilenceaxboe
authored andcommitted
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: [email protected] Reported-by: David Hildenbrand <[email protected]> Fixes: 9ef4cbb ("io_uring: add infra for importing vectored reg buffers") Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/io-uring/19530391f5c361a026ac9b401ff8e123bde55d98.1750771718.git.asml.silence@gmail.com/ Signed-off-by: Jens Axboe <[email protected]>
1 parent 3a3c6d6 commit e1d7727

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
@@ -1339,7 +1339,6 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
13391339
{
13401340
unsigned long folio_size = 1 << imu->folio_shift;
13411341
unsigned long folio_mask = folio_size - 1;
1342-
u64 folio_addr = imu->ubuf & ~folio_mask;
13431342
struct bio_vec *res_bvec = vec->bvec;
13441343
size_t total_len = 0;
13451344
unsigned bvec_idx = 0;
@@ -1361,8 +1360,13 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
13611360
if (unlikely(check_add_overflow(total_len, iov_len, &total_len)))
13621361
return -EOVERFLOW;
13631362

1364-
/* by using folio address it also accounts for bvec offset */
1365-
offset = buf_addr - folio_addr;
1363+
offset = buf_addr - imu->ubuf;
1364+
/*
1365+
* Only the first bvec can have non zero bv_offset, account it
1366+
* here and work with full folios below.
1367+
*/
1368+
offset += imu->bvec[0].bv_offset;
1369+
13661370
src_bvec = imu->bvec + (offset >> imu->folio_shift);
13671371
offset &= folio_mask;
13681372

0 commit comments

Comments
 (0)