]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: Fix bvec_set_folio() for very large folios
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 12 Jun 2025 14:42:53 +0000 (15:42 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Jun 2025 13:32:33 +0000 (15:32 +0200)
[ Upstream commit 5e223e06ee7c6d8f630041a0645ac90e39a42cc6 ]

Similarly to 26064d3e2b4d ("block: fix adding folio to bio"), if
we attempt to add a folio that is larger than 4GB, we'll silently
truncate the offset and len.  Widen the parameters to size_t, assert
that the length is less than 4GB and set the first page that contains
the interesting data rather than the first page of the folio.

Fixes: 26db5ee15851 (block: add a bvec_set_folio helper)
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/r/20250612144255.2850278-1-willy@infradead.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/bvec.h

index f41c7f0ef91ed53fefec87a1274ef205576ba5ad..a8333b82e766d4c258242b7d6045484d4061cd3a 100644 (file)
@@ -57,9 +57,12 @@ static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
  * @offset:    offset into the folio
  */
 static inline void bvec_set_folio(struct bio_vec *bv, struct folio *folio,
-               unsigned int len, unsigned int offset)
+               size_t len, size_t offset)
 {
-       bvec_set_page(bv, &folio->page, len, offset);
+       unsigned long nr = offset / PAGE_SIZE;
+
+       WARN_ON_ONCE(len > UINT_MAX);
+       bvec_set_page(bv, folio_page(folio, nr), len, offset % PAGE_SIZE);
 }
 
 /**