* [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs()
@ 2026-09-09 8:06 David Howells
2026-09-10 5:28 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: David Howells @ 2026-09-09 8:06 UTC (permalink / raw)
To: Jens Axboe
Cc: dhowells, Keith Busch, Hannes Reinecke, Christoph Hellwig,
Alexander Viro, Paulo Alcantara, netfs, linux-block,
linux-fsdevel, linux-kernel
Commit 14b007e17881 added an address check using iter_iov_addr() and a
length check using iter_iov_len() to iov_iter_extract_bvecs(), but these
cannot be used so and are unsafe in this circumstance as the functions have
hardwired assumptions about the iterator type. They should only be used
with ITER_UBUF or ITER_IOVEC-type iterators; they shouldn't be used with
ITER_BVEC, ITER_KVEC, ITER_FOLIOQ, ITER_XARRAY or ITER_DISCARD iterators.
This proves to be a problem for cachefiles as an iterator of type
ITER_FOLIOQ is passed and iter_iov_addr() and iter_iov_len() both
malfunction because iter->__iov in iter_iov() is not pointing to an iovec
array.
Fix this by using iov_iter_alignment() instead.
Fixes: 14b007e17881 ("block: validate user space vectors during extraction")
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
cc: Hannes Reinecke <hare@kernel.org>
cc: Christoph Hellwig <hch@infradead.org>
cc: Jens Axboe <axboe@kernel.dk>
cc: Alexander Viro <viro@zeniv.linux.org.uk>
cc: Paulo Alcantara <pc@manguebit.org>
cc: netfs@lists.linux.dev
cc: linux-block@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
---
lib/iov_iter.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 6665372ecf71..2072c04e99d0 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1921,15 +1921,29 @@ ssize_t iov_iter_extract_bvecs(struct iov_iter *iter, struct bio_vec *bv,
unsigned short max_vecs, unsigned mem_align_mask,
iov_iter_extraction_t extraction_flags)
{
- unsigned long start = (unsigned long)iter_iov_addr(iter);
unsigned short entries_left = max_vecs - *nr_vecs;
unsigned short nr_pages, i = 0;
size_t left, offset, len;
struct page **pages;
ssize_t size;
- if ((start | iter_iov_len(iter)) & mem_align_mask)
+ /*
+ * DMA engines typically have both memory address and length alignment
+ * requirements, so check these against the alignment mask. For UBUF,
+ * IOVEC and KVEC, only the current segment will be extracted from; for
+ * everything else we might extract from multiple segments, so we need
+ * to check those too.
+ */
+ if (likely(iter_is_ubuf(iter) ||
+ iter_is_iovec(iter) ||
+ iov_iter_is_kvec(iter))) {
+ unsigned long start = (unsigned long)iter_iov_addr(iter);
+
+ if ((start | iter_iov_len(iter)) & mem_align_mask)
+ return -EINVAL;
+ } else if (iov_iter_alignment(iter) & mem_align_mask) {
return -EINVAL;
+ }
/*
* Move page array up in the allocated memory for the bio vecs as far as
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs()
2026-09-09 8:06 [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs() David Howells
@ 2026-09-10 5:28 ` Christoph Hellwig
2026-09-10 7:20 ` Christian Brauner
2026-09-10 20:55 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-09-10 5:28 UTC (permalink / raw)
To: David Howells
Cc: Jens Axboe, Keith Busch, Hannes Reinecke, Christoph Hellwig,
Alexander Viro, Paulo Alcantara, netfs, linux-block,
linux-fsdevel, linux-kernel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs()
2026-09-09 8:06 [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs() David Howells
2026-09-10 5:28 ` Christoph Hellwig
@ 2026-09-10 7:20 ` Christian Brauner
2026-09-10 20:55 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-09-10 7:20 UTC (permalink / raw)
To: Jens Axboe, David Howells
Cc: Keith Busch, Hannes Reinecke, Christoph Hellwig, Alexander Viro,
Paulo Alcantara, netfs, linux-block, linux-fsdevel, linux-kernel
On Wed, 09 Sep 2026 09:06:31 +0100, David Howells wrote:
> block: Fix start and length check added to iov_iter_extract_bvecs()
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] block: Fix start and length check added to iov_iter_extract_bvecs()
https://git.kernel.org/vfs/vfs/c/57a78ad2305f
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs()
2026-09-09 8:06 [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs() David Howells
2026-09-10 5:28 ` Christoph Hellwig
2026-09-10 7:20 ` Christian Brauner
@ 2026-09-10 20:55 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-09-10 20:55 UTC (permalink / raw)
To: David Howells
Cc: Keith Busch, Hannes Reinecke, Christoph Hellwig, Alexander Viro,
Paulo Alcantara, netfs, linux-block, linux-fsdevel, linux-kernel
On Wed, 09 Sep 2026 09:06:31 +0100, David Howells wrote:
> Commit 14b007e17881 added an address check using iter_iov_addr() and a
> length check using iter_iov_len() to iov_iter_extract_bvecs(), but these
> cannot be used so and are unsafe in this circumstance as the functions have
> hardwired assumptions about the iterator type. They should only be used
> with ITER_UBUF or ITER_IOVEC-type iterators; they shouldn't be used with
> ITER_BVEC, ITER_KVEC, ITER_FOLIOQ, ITER_XARRAY or ITER_DISCARD iterators.
>
> [...]
Applied, thanks!
[1/1] block: Fix start and length check added to iov_iter_extract_bvecs()
commit: b0d8d56b7c93ed767eb4f2be9988e7b9dc023566
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-10 20:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 8:06 [PATCH v4] block: Fix start and length check added to iov_iter_extract_bvecs() David Howells
2026-09-10 5:28 ` Christoph Hellwig
2026-09-10 7:20 ` Christian Brauner
2026-09-10 20:55 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®