mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to sanity check on nat_entry.nid in f2fs_get_node_info()
@ 2025-12-15 12:28 Chao Yu
  2025-12-16  1:36 ` [f2fs-dev] " Zhiguo Niu
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2025-12-15 12:28 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu, stable

In order to avoid loading corrupted nat entry from disk.

Cc: stable@kernel.org
Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/node.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index ce471e033774..13c88dfd790d 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -630,14 +630,15 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
 	node_info_from_raw_nat(ni, &ne);
 	f2fs_folio_put(folio, true);
 sanity_check:
-	if (__is_valid_data_blkaddr(ni->blk_addr) &&
+	if (unlikely(ni->nid != nid ||
+		(__is_valid_data_blkaddr(ni->blk_addr) &&
 		!f2fs_is_valid_blkaddr(sbi, ni->blk_addr,
-					DATA_GENERIC_ENHANCE)) {
+					DATA_GENERIC_ENHANCE)))) {
 		set_sbi_flag(sbi, SBI_NEED_FSCK);
 		f2fs_err_ratelimited(sbi,
-			"f2fs_get_node_info of %pS: inconsistent nat entry, "
+			"f2fs_get_node_info of %pS: nid:%u, inconsistent nat entry, "
 			"ino:%u, nid:%u, blkaddr:%u, ver:%u, flag:%u",
-			__builtin_return_address(0),
+			__builtin_return_address(0), nid,
 			ni->ino, ni->nid, ni->blk_addr, ni->version, ni->flag);
 		f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT);
 		return -EFSCORRUPTED;
-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-19  2:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-15 12:28 [PATCH] f2fs: fix to sanity check on nat_entry.nid in f2fs_get_node_info() Chao Yu
2025-12-16  1:36 ` [f2fs-dev] " Zhiguo Niu
2025-12-16  8:49   ` Chao Yu
2025-12-17  1:46     ` Zhiguo Niu
2025-12-17  8:03       ` Chao Yu
2025-12-18  1:30         ` Zhiguo Niu
2025-12-19  2:52           ` Chao Yu

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®