Skip to content

Commit af5e456

Browse files
josephhzakpm00
authored andcommitted
ocfs2: validate extent block list fields during block read
Add extent list validation to ocfs2_validate_extent_block() so that corrupted on-disk fields are caught early at block read time rather than during extent tree traversal. Two checks are added: - l_count must equal the expected value from ocfs2_extent_recs_per_eb(), catching blocks with a corrupted record count before any array iteration. - l_next_free_rec must not exceed l_count, preventing out-of-bounds access when iterating over extent records. Link: https://lkml.kernel.org/r/20260403090803.3860971-4-joseph.qi@linux.alibaba.com Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Heming Zhao <heming.zhao@suse.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Joel Becker <jlbec@evilplan.org> Cc: Jun Piao <piaojun@huawei.com> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Mark Fasheh <mark@fasheh.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 4ae9cca commit af5e456

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

fs/ocfs2/alloc.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,11 +917,32 @@ static int ocfs2_validate_extent_block(struct super_block *sb,
917917
goto bail;
918918
}
919919

920-
if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation)
920+
if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation) {
921921
rc = ocfs2_error(sb,
922922
"Extent block #%llu has an invalid h_fs_generation of #%u\n",
923923
(unsigned long long)bh->b_blocknr,
924924
le32_to_cpu(eb->h_fs_generation));
925+
goto bail;
926+
}
927+
928+
if (le16_to_cpu(eb->h_list.l_count) != ocfs2_extent_recs_per_eb(sb)) {
929+
rc = ocfs2_error(sb,
930+
"Extent block #%llu has invalid l_count %u (expected %u)\n",
931+
(unsigned long long)bh->b_blocknr,
932+
le16_to_cpu(eb->h_list.l_count),
933+
ocfs2_extent_recs_per_eb(sb));
934+
goto bail;
935+
}
936+
937+
if (le16_to_cpu(eb->h_list.l_next_free_rec) > le16_to_cpu(eb->h_list.l_count)) {
938+
rc = ocfs2_error(sb,
939+
"Extent block #%llu has invalid l_next_free_rec %u (l_count %u)\n",
940+
(unsigned long long)bh->b_blocknr,
941+
le16_to_cpu(eb->h_list.l_next_free_rec),
942+
le16_to_cpu(eb->h_list.l_count));
943+
goto bail;
944+
}
945+
925946
bail:
926947
return rc;
927948
}

0 commit comments

Comments
 (0)