[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251215122830.3495475-1-chao@kernel.org>
Date: Mon, 15 Dec 2025 20:28:30 +0800
From: Chao Yu <chao@...nel.org>
To: jaegeuk@...nel.org
Cc: linux-f2fs-devel@...ts.sourceforge.net,
linux-kernel@...r.kernel.org,
Chao Yu <chao@...nel.org>,
stable@...nel.org
Subject: [PATCH] f2fs: fix to sanity check on nat_entry.nid in f2fs_get_node_info()
In order to avoid loading corrupted nat entry from disk.
Cc: stable@...nel.org
Signed-off-by: Chao Yu <chao@...nel.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
Powered by blists - more mailing lists