mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: don't BUG_ON an inconsistent node ino in roll-forward recovery
@ 2026-11-25  7:39 Zhan Xusheng
  0 siblings, 0 replies; only message in thread
From: Zhan Xusheng @ 2026-11-25  7:39 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: yangguikun19, linux-f2fs-devel, linux-kernel, zhanxusheng, stable

From: Zhan Xusheng <zhanxusheng@xiaomi.com>

do_recover_data() asserts that the ino in the NAT entry of the node it
recovers into matches the ino in the footer of the fsynced node block.
Both are read from disk and nothing checks one against the other
before, so mounting an image with a wrong ino in that NAT entry hits
the f2fs_bug_on(): a kernel BUG with CONFIG_F2FS_CHECK_FS, and without
it a warning, after which the NAT ino is written into the footer of the
recovered node.

To reproduce, create a file, sync, write and fsync it, crash, and change
the ino of the file's entry in the NAT journal of the checkpoint pack.
The next mount gives:

  kernel BUG at fs/f2fs/recovery.c:698!

Fail the recovery with -EFSCORRUPTED instead, as the ofs_of_node check
right after it does.

Reported-by: Guikun Yang <yangguikun19@qq.com>
Closes: https://lore.kernel.org/all/tencent_5CEF90115E2715D386A8349FCA28D7D4D607@qq.com/
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
Tested on f2fs/dev b61a029304bb with CONFIG_F2FS_CHECK_FS and KASAN.
With the ino of the victim's NAT journal entry changed from 4 to 5:

  unfixed  kernel BUG at fs/f2fs/recovery.c:698
  fixed    "Inconsistent ino_of_node, nid:4, ino:5, 4", recovery fails
           with -EFSCORRUPTED, the mount is retried without
           roll-forward and succeeds, and fsck.f2fs reports the same
           mismatch for nid 4

The unmodified image recovers the same way with and without the patch.

 fs/f2fs/recovery.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 54b5246609de..c92da18f553f 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -695,7 +695,14 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
 	if (err)
 		goto err;
 
-	f2fs_bug_on(sbi, ni.ino != ino_of_node(sbi, entry));
+	if (ni.ino != ino_of_node(sbi, entry)) {
+		f2fs_warn(sbi, "Inconsistent ino_of_node, nid:%u, ino:%u, %u",
+			  dn.nid, ni.ino, ino_of_node(sbi, entry));
+		err = -EFSCORRUPTED;
+		f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER);
+		fserror_report_file_metadata(dn.inode, err, GFP_NOFS);
+		goto err;
+	}
 
 	if (ofs_of_node(sbi, dn.node_entry) != ofs_of_node(sbi, entry)) {
 		f2fs_warn(sbi, "Inconsistent ofs_of_node, ino:%llu, ofs:%u, %u",
-- 
2.43.0


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

only message in thread, other threads:[~2026-11-25  7:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25  7:39 [PATCH] f2fs: don't BUG_ON an inconsistent node ino in roll-forward recovery Zhan Xusheng

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

all inboxes | Powered by JetHome®