fs/ocfs2/alloc.c | 5 +++++ 1 file changed, 5 insertions(+)
In ocfs2_adjust_adjacent_records(), the code dereferences
right_child_el->l_recs[0] without verifying that the extent list
actually contains any records.
If right_child_el->l_next_free_rec is 0 (e.g., due to a corrupted
filesystem image), this results in an out-of-bounds access when
accessing l_recs[0].e_cpos.
In contrast, ocfs2_adjust_rightmost_records() explicitly validates
that l_next_free_rec is non-zero before accessing records.
This patch adds a check to ensure l_next_free_rec is not zero before
proceeding. If the list is empty, we log an error and return to avoid
reading invalid data.
Fixes: dcd0538ff4e8 ("ocfs2: sparse b-tree support")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
fs/ocfs2/alloc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 58bf58b68955..bc6f26613e6e 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -1974,6 +1974,11 @@ static void ocfs2_adjust_adjacent_records(struct ocfs2_extent_rec *left_rec,
{
u32 left_clusters, right_end;
+ if (le16_to_cpu(right_child_el->l_next_free_rec) == 0) {
+ mlog(ML_ERROR, "Extent list has no records\n");
+ return;
+ }
+
/*
* Interior nodes never have holes. Their cpos is the cpos of
* the leftmost record in their child list. Their cluster
--
2.25.1
On Sun, Jan 18, 2026 at 07:23:18PM +0000, Jiasheng Jiang wrote:
> In ocfs2_adjust_adjacent_records(), the code dereferences
> right_child_el->l_recs[0] without verifying that the extent list
> actually contains any records.
>
> If right_child_el->l_next_free_rec is 0 (e.g., due to a corrupted
> filesystem image), this results in an out-of-bounds access when
> accessing l_recs[0].e_cpos.
>
> In contrast, ocfs2_adjust_rightmost_records() explicitly validates
> that l_next_free_rec is non-zero before accessing records.
>
> This patch adds a check to ensure l_next_free_rec is not zero before
> proceeding. If the list is empty, we log an error and return to avoid
> reading invalid data.
>
> Fixes: dcd0538ff4e8 ("ocfs2: sparse b-tree support")
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
> fs/ocfs2/alloc.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index 58bf58b68955..bc6f26613e6e 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -1974,6 +1974,11 @@ static void ocfs2_adjust_adjacent_records(struct ocfs2_extent_rec *left_rec,
> {
> u32 left_clusters, right_end;
>
> + if (le16_to_cpu(right_child_el->l_next_free_rec) == 0) {
> + mlog(ML_ERROR, "Extent list has no records\n");
> + return;
> + }
> +
> /*
> * Interior nodes never have holes. Their cpos is the cpos of
> * the leftmost record in their child list. Their cluster
> --
> 2.25.1
>
>
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
© 2016 - 2026 Red Hat, Inc.