]> git.hungrycats.org Git - linux/commitdiff
filemap: Fix bounds checking in filemap_read()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 13 Sep 2024 17:57:04 +0000 (13:57 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 Nov 2024 12:15:17 +0000 (13:15 +0100)
commit ace149e0830c380ddfce7e466fe860ca502fe4ee 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: 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/filemap.c

index d3b925232a59e8d71af64ddda3abd78c4eb814dd..dc23b1336a8bd5809be4d1f7f0c51b65477241f3 100644 (file)
@@ -2738,7 +2738,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
        if (unlikely(!iov_iter_count(iter)))
                return 0;
 
-       iov_iter_truncate(iter, inode->i_sb->s_maxbytes);
+       iov_iter_truncate(iter, inode->i_sb->s_maxbytes - iocb->ki_pos);
        folio_batch_init(&fbatch);
 
        do {