]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: detect more inconsistent cases in sanity_check_node_footer()
authorChao Yu <chao@kernel.org>
Mon, 12 Jan 2026 07:49:17 +0000 (15:49 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 17 Jan 2026 00:00:35 +0000 (00:00 +0000)
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 <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/node.c

index efd4f176a1f447e2ba4dccf5c327fcc9e8a08a44..63252ff1e5c3b901841c1e889cc4dd0bd713a5b3 100644 (file)
@@ -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: