Forwarded: [PATCH] gfs2: fix hung task in gfs2_jhead_process_page

syzbot posted 1 patch 1 week, 3 days ago
There is a newer version of this series
fs/gfs2/lops.c | 5 +++++
1 file changed, 5 insertions(+)
Forwarded: [PATCH] gfs2: fix hung task in gfs2_jhead_process_page
Posted by syzbot 1 week, 3 days ago
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] gfs2: fix hung task in gfs2_jhead_process_page
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master


filemap_get_folio() can return an ERR_PTR if the folio is not
present in the page cache. This can happen when a crafted or
corrupted GFS2 filesystem image is mounted and journal recovery
is triggered.

gfs2_jhead_process_page() calls filemap_get_folio() without
checking the return value, and passes the result directly to
folio_wait_locked(). When an ERR_PTR is passed to
folio_wait_locked(), the kernel task gets stuck in uninterruptible
sleep (state D) forever, triggering the hung task watchdog.

This was reported by syzbot. The reproducer mounts a crafted GFS2
image which causes gfs2_find_jhead() to call
gfs2_jhead_process_page() on a page that was never properly
submitted for I/O, causing filemap_get_folio() to return
ERR_PTR(-ENOENT).

Fix this by checking the return value of filemap_get_folio() and
marking the journal head search as done if the folio is not found,
allowing the caller to return an error gracefully.

Reported-by: syzbot+9013411dc43f3582823a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9013411dc43f3582823a
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
 fs/gfs2/lops.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 797931eb5845..c2bb262318bb 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -467,6 +467,11 @@ static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index,
 
 	folio = filemap_get_folio(jd->jd_inode->i_mapping, index);
 
+	if (IS_ERR(folio)) { 
+		*done = true;
+		return ;
+	}
+
 	folio_wait_locked(folio);
 	if (!folio_test_uptodate(folio))
 		*done = true;
-- 
2.43.0