Linux network filesystem support library
 help / color / mirror / Atom feed
* [PATCH] block: Fix start and length check added to iov_iter_extract_bvecs()
@ 2026-08-26 18:18 David Howells
  2026-08-26 18:34 ` Keith Busch
  2026-08-26 20:46 ` [PATCH v2] " David Howells
  0 siblings, 2 replies; 10+ messages in thread
From: David Howells @ 2026-08-26 18:18 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 should not be used with
ITER_BVEC, ITER_KVEC, ITER_FOLIOQ, ITER_XARRAY or ITER_DISCARD iterators.

This change proved 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")
cc: Keith Busch <kbusch@kernel.org>
cc: Jens Axboe <axboe@kernel.dk>
cc: Hannes Reinecke <hare@kernel.org>
cc: Christoph Hellwig <hch@lst.de>
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
---

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 6665372ecf71..6df716e19247 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1921,15 +1921,19 @@ 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)
+	if (iov_iter_alignment(iter) & mem_align_mask) {
+		pr_warn("%u %zx %x\n",
+			iter->iter_type,
+			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 related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-08-26 20:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-26 18:18 [PATCH] block: Fix start and length check added to iov_iter_extract_bvecs() David Howells
2026-08-26 18:34 ` Keith Busch
2026-08-26 19:24   ` David Howells
2026-08-26 19:47     ` Keith Busch
2026-08-26 20:23       ` David Howells
2026-08-26 19:49   ` David Howells
2026-08-26 20:02     ` Keith Busch
2026-08-26 20:46 ` [PATCH v2] " David Howells
2026-08-26 20:52   ` Keith Busch
2026-08-26 20:54   ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox