From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@meta.com>
Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
dm-devel@lists.linux.dev, hch@lst.de, axboe@kernel.dk,
brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk,
Keith Busch <kbusch@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/1] block: validate user space vectors during extraction
Date: Thu, 18 Jun 2026 12:26:27 +0200 [thread overview]
Message-ID: <20260618102627.GA23200@lst.de> (raw)
In-Reply-To: <20260617233235.1016063-2-kbusch@meta.com>
On Wed, Jun 17, 2026 at 04:32:35PM -0700, Keith Busch wrote:
> @@ -1242,7 +1242,7 @@ static int bio_iov_iter_align_down(struct bio *bio, struct iov_iter *iter,
> * is returned only if 0 pages could be pinned.
> */
> int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
> - unsigned len_align_mask)
> + unsigned len_align_mask, unsigned vec_align_mask)
vec_align_mask needs to be documented in the kernel doc. And I find
the vec_align_mask name a bit confusing. This is all about the physical
address (really the dma address, but the page aligned offset map 1:1),
so maybe phys_align_mask or dma_align_mask might be better names?
Also wouldn't it be more natural to pass the start alignment requirement
before the length alignment paramter?
> @@ -1251,6 +1251,11 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
>
> if (iov_iter_is_bvec(iter)) {
> bio_iov_bvec_set(bio, iter);
> +
> + if (mp_bvec_iter_offset(bio->bi_io_vec, bio->bi_iter) &
> + vec_align_mask)
> + return -EINVAL;
Can you add a comment here? Especially as the bvec iter doesn't actually
require all individual bvecs to be aligned and I'm not entirely sure this
handles all case - writing down the rules might help a bit with that.
> ret = iov_iter_extract_bvecs(iter, bio->bi_io_vec,
> BIO_MAX_SIZE - bio->bi_iter.bi_size,
> - &bio->bi_vcnt, bio->bi_max_vecs, flags);
> + &bio->bi_vcnt, bio->bi_max_vecs,
> + vec_align_mask, flags);
> if (ret <= 0) {
> + if (ret == -EINVAL) {
> + bio_release_pages(bio, false);
> + bio_clear_flag(bio, BIO_PAGE_PINNED);
> + bio->bi_iter.bi_size = 0;
> + bio->bi_vcnt = 0;
> + return ret;
> + }
Do we need all this cleanups beyoned the bio_release_pages()? Most
callers just free the bio, so should not care about it, and the error
handling in __blkdev_direct_IO that calls bio_endio looks buggy for
other reasons..
> + * @align_mask: reject with -EINVAL if the source address or length is not
> + * aligned to this mask
Maybe use the same paramater name as on the bio side here?
And not for this patch, but this makes me wonder if we should handle the
len alignment in iov_iter_extract_bvecs as well, as that should simplify
it quite a bit.
next prev parent reply other threads:[~2026-06-18 10:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 23:32 [PATCH 0/1] direct-io: validate user space vectors during extraction Keith Busch
2026-06-17 23:32 ` [PATCH 1/1] block: " Keith Busch
2026-06-18 10:22 ` kernel test robot
2026-06-18 10:26 ` Christoph Hellwig [this message]
2026-06-18 13:17 ` Keith Busch
2026-06-18 13:43 ` Christoph Hellwig
2026-06-18 13:51 ` Keith Busch
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=20260618102627.GA23200@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=dm-devel@lists.linux.dev \
--cc=kbusch@kernel.org \
--cc=kbusch@meta.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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