linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH stable 5.10.y] mm/filemap: fix infinite loop in generic_file_buffered_read()
@ 2023-09-19 23:28 Suraj Jitindar Singh
  0 siblings, 0 replies; only message in thread
From: Suraj Jitindar Singh @ 2023-09-19 23:28 UTC (permalink / raw)
  To: stable
  Cc: linux-kernel, linux-mm, kent.overstreet, axboe, sjitindarsingh,
	Linus Torvalds, Suraj Jitindar Singh

From: Kent Overstreet <kent.overstreet@gmail.com>

commit 3644e2d2dda78e21edd8f5415b6d7ab03f5f54f3 upstream.

If iter->count is 0 and iocb->ki_pos is page aligned, this causes
nr_pages to be 0.

Then in generic_file_buffered_read_get_pages() find_get_pages_contig()
returns 0 - because we asked for 0 pages, so we call
generic_file_buffered_read_no_cached_page() which attempts to add a page
to the page cache, which fails with -EEXIST, and then we loop. Oops...

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Reported-by: Jens Axboe <axboe@kernel.dk>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Suraj Jitindar Singh <surajjs@amazon.com>
---
 mm/filemap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/filemap.c b/mm/filemap.c
index 3a983bc1a71c..3b0d8c6dd587 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2203,6 +2203,9 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,
 
 	if (unlikely(*ppos >= inode->i_sb->s_maxbytes))
 		return 0;
+	if (unlikely(!iov_iter_count(iter)))
+		return 0;
+
 	iov_iter_truncate(iter, inode->i_sb->s_maxbytes);
 
 	index = *ppos >> PAGE_SHIFT;
-- 
2.34.1



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-19 23:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19 23:28 [PATCH stable 5.10.y] mm/filemap: fix infinite loop in generic_file_buffered_read() Suraj Jitindar Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox