filemap: Fix bounds checking in filemap_read()

If the caller supplies an iocb->ki_pos value that is close to the
filesystem upper limit, and an iterator with a count that causes us to
overflow that limit, then filemap_read() enters an infinite loop.

This behaviour was discovered when testing xfstests generic/525 with the
"localio" optimisation for loopback NFS mounts.

Reported-by: Mike Snitzer <snitzer@kernel.org>
Fixes: c2a9737f45e2 ("vfs,mm: fix a dead loop in truncate_inode_pages_range()")
Tested-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Trond Myklebust and committed by Linus Torvalds ace149e0 a9cda7c0

Changed files
+1 -1
mm
+1 -1
mm/filemap.c
··· 2625 2625 if (unlikely(!iov_iter_count(iter))) 2626 2626 return 0; 2627 2627 2628 - iov_iter_truncate(iter, inode->i_sb->s_maxbytes); 2628 + iov_iter_truncate(iter, inode->i_sb->s_maxbytes - iocb->ki_pos); 2629 2629 folio_batch_init(&fbatch); 2630 2630 2631 2631 do {