public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, David Hildenbrand <david@redhat.com>
Subject: [PATCH v2 3/3] io_uring: don't assume uaddr alignment in io_vec_fill_bvec
Date: Tue, 24 Jun 2025 14:40:35 +0100	[thread overview]
Message-ID: <19530391f5c361a026ac9b401ff8e123bde55d98.1750771718.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1750771718.git.asml.silence@gmail.com>

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: 9ef4cbbcb4ac3 ("io_uring: add infra for importing vectored reg buffers")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/rsrc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 8b06c732d136..c58fe736f297 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1336,7 +1336,6 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
 {
 	unsigned long folio_size = 1 << imu->folio_shift;
 	unsigned long folio_mask = folio_size - 1;
-	u64 folio_addr = imu->ubuf & ~folio_mask;
 	struct bio_vec *res_bvec = vec->bvec;
 	size_t total_len = 0;
 	unsigned bvec_idx = 0;
@@ -1358,8 +1357,13 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
 		if (unlikely(check_add_overflow(total_len, iov_len, &total_len)))
 			return -EOVERFLOW;
 
-		/* by using folio address it also accounts for bvec offset */
-		offset = buf_addr - folio_addr;
+		offset = buf_addr - imu->ubuf;
+		/*
+		 * Only the first bvec can have non zero bv_offset, account it
+		 * here and work with full folios below.
+		 */
+		offset += imu->bvec[0].bv_offset;
+
 		src_bvec = imu->bvec + (offset >> imu->folio_shift);
 		offset &= folio_mask;
 
-- 
2.49.0


  parent reply	other threads:[~2025-06-24 13:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24 13:40 [PATCH v2 0/3] io_uring mm related abuses Pavel Begunkov
2025-06-24 13:40 ` [PATCH v2 1/3] io_uring/rsrc: fix folio unpinning Pavel Begunkov
2025-06-25  7:53   ` David Hildenbrand
2025-06-25 20:33     ` Pavel Begunkov
2025-06-24 13:40 ` [PATCH v2 2/3] io_uring/rsrc: don't rely on user vaddr alignment Pavel Begunkov
2025-06-26  9:30   ` David Hildenbrand
2025-06-24 13:40 ` Pavel Begunkov [this message]
2025-06-25  2:52 ` [PATCH v2 0/3] io_uring mm related abuses Jens Axboe
2025-06-25 20:24   ` Pavel Begunkov
2025-06-25 22:36     ` Jens Axboe
2025-06-25  2:52 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19530391f5c361a026ac9b401ff8e123bde55d98.1750771718.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=david@redhat.com \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox