mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ocfs2: fix potential OOB access in ocfs2_adjust_adjacent_records()
@ 2026-01-18 19:23 Jiasheng Jiang
  2026-01-19  6:37 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2026-01-18 19:23 UTC (permalink / raw)
  To: Mark Fasheh, Joel Becker, Joseph Qi, linux-kernel
  Cc: ocfs2-devel, stable, Jiasheng Jiang

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ocfs2: fix potential OOB access in ocfs2_adjust_adjacent_records()
  2026-01-18 19:23 [PATCH] ocfs2: fix potential OOB access in ocfs2_adjust_adjacent_records() Jiasheng Jiang
@ 2026-01-19  6:37 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-01-19  6:37 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: Mark Fasheh, Joel Becker, Joseph Qi, linux-kernel, ocfs2-devel, stable

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>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-19  6:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-18 19:23 [PATCH] ocfs2: fix potential OOB access in ocfs2_adjust_adjacent_records() Jiasheng Jiang
2026-01-19  6:37 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®