mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: jaegeuk@kernel.org, chao@kernel.org
Cc: yangguikun19@qq.com, linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com,
	stable@vger.kernel.org
Subject: [PATCH] f2fs: don't BUG_ON an inconsistent node ino in roll-forward recovery
Date: Wed, 25 Nov 2026 15:39:56 +0800	[thread overview]
Message-ID: <20261125073956.2927907-1-zhanxusheng1024@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-25  7:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125073956.2927907-1-zhanxusheng1024@gmail.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yangguikun19@qq.com \
    --cc=zhanxusheng@xiaomi.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

all inboxes | Powered by JetHome®