Skip to content

Commit c803059

Browse files
Matthew Wilcox (Oracle)Sasha Levin
authored andcommitted
block: Fix bvec_set_folio() for very large folios
[ Upstream commit 5e223e0 ] Similarly to 26064d3 ("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: 26db5ee (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>
1 parent aedeaf9 commit c803059

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/linux/bvec.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
5757
* @offset: offset into the folio
5858
*/
5959
static inline void bvec_set_folio(struct bio_vec *bv, struct folio *folio,
60-
unsigned int len, unsigned int offset)
60+
size_t len, size_t offset)
6161
{
62-
bvec_set_page(bv, &folio->page, len, offset);
62+
unsigned long nr = offset / PAGE_SIZE;
63+
64+
WARN_ON_ONCE(len > UINT_MAX);
65+
bvec_set_page(bv, folio_page(folio, nr), len, offset % PAGE_SIZE);
6366
}
6467

6568
/**

0 commit comments

Comments
 (0)