From mboxrd@z Thu Jan 1 00:00:00 1970 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 2B5553446BB for ; Mon, 12 Jan 2026 08:03:18 +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=1768204999; cv=none; b=uLF4eWS/ftRal+pWLHZdrm1czEcFCnpT9MAIHJ94vH75jjbNbZQfVlS1isR8LDf7wsZQ+jt6A4RaR1R+pXUt42MkivstAioryf9JqlXBaUIaCaKfqTDmbsKxl6T0P2JaoA4aT/Q4fSnsXL70Cr7sJKCroqL8dGcYPF+LQeuqz4U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768204999; c=relaxed/simple; bh=+S81VkDwUjl2ErYw3m0WiPBfUE/SwQLze82OjbLOVoY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GZocYAxXIL62tCSSsLuIsc+A7vQ0PycndMna9Gk7UTFfaAodWbIPo1IDPSuSJ6qc7629837CqYh66h0cIUaACjTbnS/6CeGrdg0brhE5dii0aPBy2eobH3f/+QDY4Xoes1kPVXRzNVpRJSW+BmA+uvBUb2bG+oB+YP14i+aUebE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mlnoW9+v; 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="mlnoW9+v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2098C19422; Mon, 12 Jan 2026 08:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768204998; bh=+S81VkDwUjl2ErYw3m0WiPBfUE/SwQLze82OjbLOVoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mlnoW9+vPazu+kFEXnuFloiRzRMdrom+4ASnXCkIzukmXfASkjQZibM374/nx4wi5 b36wUmu+qHwi2lviib5R2EzgBZmRCyIUmz1ClCsMWf6h7M4bzHPHgQwgjsrOG3CZne 6lGtrXfEbFB5N2c2w9vrSeVB/Nz1nYmhomuTz4jwDVpxHiOKJRqi14meMNtolih3i0 VsUArtw1fisrhtPaYhk1ORTBkMi4ZClmrUL+w4f4B3zLupBG5GBZGfpy5lesTHY7RE cH0ysrM6OTC5+B2O+QquULndeTvpPgMUnIMZfYyzT9mUti8CJVV5yennZBjMDSSgqJ bp+5jynNU/mqg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v5 3/3] f2fs: detect more inconsistent cases in sanity_check_node_footer() Date: Mon, 12 Jan 2026 15:49:17 +0800 Message-Id: <20260112074917.40107-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20260112074917.40107-1-chao@kernel.org> References: <20260112074917.40107-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Let's enhance sanity_check_node_footer() to detect more inconsistent cases as below: Node Type Node Footer Info =================== ============================= NODE_TYPE_REGULAR inode = true and xnode = true NODE_TYPE_INODE inode = false or xnode = true NODE_TYPE_XATTR inode = true or xnode = false NODE_TYPE_NON_INODE inode = false Signed-off-by: Chao Yu --- v5: - split original patch 1/2 to two, in this patch, fix to not sanity check on uninitialized i_mode for new inode page, instead, let's enhance sanity_check_node_footer() to detect more inconsistent cases in node footer. fs/f2fs/node.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e8b2618fcac7..c79af2bc5728 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1515,20 +1515,29 @@ int f2fs_sanity_check_node_footer(struct f2fs_sb_info *sbi, struct folio *folio, pgoff_t nid, enum node_type ntype, bool in_irq) { + bool is_inode, is_xnode; + if (unlikely(nid != nid_of_node(folio))) goto out_err; + is_inode = IS_INODE(folio); + is_xnode = f2fs_has_xattr_block(ofs_of_node(folio)); + switch (ntype) { + case NODE_TYPE_REGULAR: + if (is_inode && is_xnode) + goto out_err; + break; case NODE_TYPE_INODE: - if (!IS_INODE(folio)) + if (!is_inode || is_xnode) goto out_err; break; case NODE_TYPE_XATTR: - if (!f2fs_has_xattr_block(ofs_of_node(folio))) + if (is_inode || !is_xnode) goto out_err; break; case NODE_TYPE_NON_INODE: - if (IS_INODE(folio)) + if (is_inode) goto out_err; break; default: -- 2.40.1