Skip to content

Commit c58a8f0

Browse files
Trond Myklebustvijay-suman
authored andcommitted
filemap: Fix bounds checking in filemap_read()
[ Upstream commit ace149e ] 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 <[email protected]> Fixes: c2a9737 ("vfs,mm: fix a dead loop in truncate_inode_pages_range()") Tested-by: Mike Snitzer <[email protected]> Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> (cherry picked from commit ace149e) [Harshit: Minor conflict resolved due to missing commit: 25d6a23 ("filemap: Convert filemap_get_read_batch() to use a folio_batch") in 5.15.y] Signed-off-by: Harshit Mogalapalli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 6cc52df69e8464811f9f6fc12f7aaa78451eb0b8) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent a2481ef commit c58a8f0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/filemap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
26182618
if (unlikely(!iov_iter_count(iter)))
26192619
return 0;
26202620

2621-
iov_iter_truncate(iter, inode->i_sb->s_maxbytes);
2621+
iov_iter_truncate(iter, inode->i_sb->s_maxbytes - iocb->ki_pos);
26222622
pagevec_init(&pvec);
26232623

26242624
do {

0 commit comments

Comments
 (0)