From: Klara Modin Date: Mon, 14 Jul 2025 22:34:12 +0000 (+0200) Subject: mm-filemap-align-last_index-to-folio-size-fix X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2976d7c112478abd0d7e991b53f79f35c742331f;p=users%2Fjedix%2Flinux-maple.git mm-filemap-align-last_index-to-folio-size-fix fix overflow on 32-bit iocb->ki_pos is loff_t (long long) while pgoff_t is unsigned long and this overflow seems to happen in practice, resulting in last_index being before index. Link: https://lkml.kernel.org/r/yru7qf5gvyzccq5ohhpylvxug5lr5tf54omspbjh4sm6pcdb2r@fpjgj2pxw7va Signed-off-by: Klara Modin Cc: Chi Zhiling Cc: David Hildenbrand Cc: Jan Kara Cc: Matthew Wilcox (Oracle) Cc: Ryan Roberts Cc: Youling Tang Cc: Youling Tang Signed-off-by: Andrew Morton --- diff --git a/mm/filemap.c b/mm/filemap.c index 48b3515e1171..344ab106c21c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2601,8 +2601,8 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, int err = 0; /* "last_index" is the index of the folio beyond the end of the read */ - last_index = round_up(iocb->ki_pos + count, mapping_min_folio_nrbytes(mapping)); - last_index >>= PAGE_SHIFT; + last_index = round_up(iocb->ki_pos + count, + mapping_min_folio_nrbytes(mapping)) >> PAGE_SHIFT; retry: if (fatal_signal_pending(current)) return -EINTR;