public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Taerang Kim <kth5965@gmail.com>
To: jaegeuk@kernel.org, chao@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org,
	syzbot+fc026e87558558f75c00@syzkaller.appspotmail.com,
	Taerang Kim <kth5965@gmail.com>
Subject: [PATCH] f2fs: evict: truncate page cache before clear_inode
Date: Wed, 25 Feb 2026 01:06:54 +0900	[thread overview]
Message-ID: <20260224160654.448538-1-kth5965@gmail.com> (raw)

syzbot reports a BUG_ON(inode->i_data.nrpages) in clear_inode() when
mounting a corrupted f2fs image.

I agree with Dmitry's RFC that dropping page #0 in f2fs_truncate()
can address this reproducer, since f2fs_convert_inline_inode() may
grab page #0 via f2fs_grab_cache_folio() and leave it cached on the
clear_out success path.

However, clear_inode() requires the inode mapping to be empty, and it
is hard to guarantee that the page cache can only be populated from
this truncate/inline-conversion path.
Make f2fs_evict_inode() defensively truncate any remaining page cache
before calling clear_inode(), so nrpages is guaranteed to be 0
regardless of how the cache was populated.

Link: https://lore.kernel.org/linux-f2fs-devel/20260206092958.578191-1-dmantipov@yandex.ru/
Reported-by: syzbot+fc026e87558558f75c00@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fc026e87558558f75c00
Signed-off-by: Taerang Kim <kth5965@gmail.com>
---
 fs/f2fs/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 38b8994bc1b2..5527bd76f62a 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -1001,6 +1001,13 @@ void f2fs_evict_inode(struct inode *inode)
 out_clear:
 	fscrypt_put_encryption_info(inode);
 	fsverity_cleanup_inode(inode);
+	/*
+	 * Defensively truncate any remaining page cache, e.g.
+	 * f2fs_convert_inline_inode() called from f2fs_truncate()
+	 * may leave page #0 behind in the page cache when the
+	 * inline conversion takes the clear_out success path.
+	 */
+	truncate_inode_pages_final(&inode->i_data);
 	clear_inode(inode);
 }
 
-- 
2.43.0


             reply	other threads:[~2026-02-24 16:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24 16:06 Taerang Kim [this message]
2026-02-24 16:54 ` [PATCH v2] f2fs: evict: truncate page cache before clear_inode Taerang Kim
2026-03-09  7:44   ` Chao Yu
2026-03-09 14:25     ` [f2fs-dev] " kth5965
2026-03-13  7:45       ` Chao Yu
2026-03-17 15:28     ` kth5965
2026-03-18  3:40       ` Chao Yu
2026-03-19 15:11         ` kth5965
2026-03-23  3:14           ` Chao Yu
2026-03-31 15:24             ` kth5965

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260224160654.448538-1-kth5965@gmail.com \
    --to=kth5965@gmail.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+fc026e87558558f75c00@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox