Skip to content

Commit 6450e73

Browse files
Trond Myklebustgregkh
authored andcommitted
filemap: Fix bounds checking in filemap_read()
commit ace149e upstream. 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: c2a9737 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 622ad10 commit 6450e73

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

mm/filemap.c

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

2612-
iov_iter_truncate(iter, inode->i_sb->s_maxbytes);
2612+
iov_iter_truncate(iter, inode->i_sb->s_maxbytes - iocb->ki_pos);
26132613
folio_batch_init(&fbatch);
26142614

26152615
do {

0 commit comments

Comments
 (0)