From nobody Sat Feb 7 15:12:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 578A222A4D6 for ; Fri, 19 Dec 2025 02:51:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766112675; cv=none; b=XOF0CvmxMWdCIC8kFh8ykQaYKQU1I/320hZQHFrwyAC3ivLpjixpqZ0/5D2iSiZlD8aiajVesbd5HX1T52lt0Dju+uCc4nMMgKi0+bsB5xhDR810IH3s3oiuiFDxYKQ94CafSJpaJMCHP4dnl1uBxzX/bZF6ylP5EkZ52D/jLOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766112675; c=relaxed/simple; bh=7nwCctVE0n04bviYWEMRF8gtPwvj7IsimGq8Wj7WUl8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Jpw2YlleCLP/wusOs9QTLjIDTyznMinmAD+js6KwYVKemxv0erKwjpXcOo0udYlxKtdc8Z9Hi1bZfw0gFBIMCk4XsibiaUjPw+P3WsmEt/ho+0SUsfl7iN3iWM0cdh6+C6y+h2/J1qOgwXTY7wfvRuzQHENxUA9/AHajaMYAw/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I0P7tJux; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I0P7tJux" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2D61C4CEFB; Fri, 19 Dec 2025 02:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766112673; bh=7nwCctVE0n04bviYWEMRF8gtPwvj7IsimGq8Wj7WUl8=; h=From:To:Cc:Subject:Date:From; b=I0P7tJuxD56IXkEonlbp43xxYNj4EXaxS8vprt8+3XlEF4zh4ed6w+qI2jky72n7I QklXFJGFGOOMuzN+vg0QLK+3Udjg2rSnBG5vGWWRy+1bItAnhzpSiRHcZQMfTlYPnJ HwOX5D8hCigSMCTVNBa05FRm03slQ35v2q5Sb+8gNplYM9vMSsrmYFoe8+yQyv2v1P 0El6c0iFLGtk0nSAlivjAbAGcFJ2/zgCTfqYYkf3x5TxCYAdNFjSFdS9dMvlN0jyzY P+LfDtcBN6vdpysYPcGBEdljULSImkHOj1aDot5gYHq10QLBK/cik1P0Kjx3HAO1+/ dHPz7ZZLx1XOQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Zhiguo Niu Subject: [PATCH] f2fs: fix to do sanity check on nat entry of quota inode Date: Fri, 19 Dec 2025 10:51:04 +0800 Message-Id: <20251219025104.12256-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As Zhiguo reported, nat entry of quota inode could be corrupted: "ino/block_addr=3DNULL_ADDR in nid=3D4 entry" We'd better to do sanity check on quota inode to detect and record nat.blk_addr inconsistency, so that we can have a chance to repair it w/ later fsck. Reported-by: Zhiguo Niu Signed-off-by: Chao Yu Reviewed-by: Zhiguo Niu --- fs/f2fs/f2fs.h | 6 +++--- fs/f2fs/inode.c | 2 +- fs/f2fs/node.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 65ca1a5eaa88..c458df92bb0d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4928,16 +4928,16 @@ static inline bool is_journalled_quota(struct f2fs_= sb_info *sbi) return false; } =20 -static inline bool f2fs_quota_file(struct inode *inode) +static inline bool f2fs_quota_file(struct f2fs_sb_info *sbi, nid_t ino) { #ifdef CONFIG_QUOTA int i; =20 - if (!f2fs_sb_has_quota_ino(F2FS_I_SB(inode))) + if (!f2fs_sb_has_quota_ino(sbi)) return false; =20 for (i =3D 0; i < MAXQUOTAS; i++) { - if (f2fs_qf_ino(F2FS_I_SB(inode)->sb, i) =3D=3D inode->i_ino) + if (f2fs_qf_ino(sbi->sb, i) =3D=3D ino) return true; } #endif diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 921fb02c0f49..d1270b25ad7d 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -621,7 +621,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigne= d long ino) inode->i_fop =3D &f2fs_file_operations; inode->i_mapping->a_ops =3D &f2fs_dblock_aops; if (IS_IMMUTABLE(inode) && !f2fs_compressed_file(inode) && - !f2fs_quota_file(inode)) + !f2fs_quota_file(sbi, inode->i_ino)) mapping_set_folio_min_order(inode->i_mapping, 0); } else if (S_ISDIR(inode->i_mode)) { inode->i_op =3D &f2fs_dir_inode_operations; diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 7feead595ba5..f1e6fa2dccc9 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -643,6 +643,17 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t= nid, return -EFSCORRUPTED; } =20 + if (unlikely(f2fs_quota_file(sbi, ni->nid) && + !__is_valid_data_blkaddr(ni->blk_addr))) { + set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_err_ratelimited(sbi, + "f2fs_get_node_info of %pS: inconsistent nat entry from qf_ino, " + "ino:%u, nid:%u, blkaddr:%u, ver:%u, flag:%u", + __builtin_return_address(0), + ni->ino, ni->nid, ni->blk_addr, ni->version, ni->flag); + f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT); + } + /* cache nat entry */ if (need_cache) cache_nat_entry(sbi, nid, &ne); --=20 2.40.1