From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>,
stable@kernel.org
Subject: [PATCH] f2fs: fix to sanity check on nat_entry.nid in f2fs_get_node_info()
Date: Mon, 15 Dec 2025 20:28:30 +0800 [thread overview]
Message-ID: <20251215122830.3495475-1-chao@kernel.org> (raw)
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
next reply other threads:[~2025-12-15 12:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 12:28 Chao Yu [this message]
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
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=20251215122830.3495475-1-chao@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@kernel.org \
/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®