[PATCH] ocfs2: fix slab-out-of-bounds in ocfs2_rotate_requires_path_adjustment

From: Jiasheng Jiang

Date: Fri Jan 16 2026 - 12:21:16 EST


In ocfs2_rotate_requires_path_adjustment(), the variable 'next_free' is
assigned the value of 'left_el->l_next_free_rec'. This value is then used
to index the 'l_recs' array as 'next_free - 1'.

If the filesystem is corrupted or in an unexpected state such that
'l_next_free_rec' is 0, this leads to an array index of -1, triggering
a slab-out-of-bounds access.

Other functions in alloc.c, such as ocfs2_rotate_leaf() and
ocfs2_update_edge_lengths(), effectively guard against this condition.
This patch adds a similar check to return 0 immediately if 'next_free'
is 0, preventing the out-of-bounds access.

Signed-off-by: Jiasheng Jiang <jiashengjiangcool@xxxxxxxxx>
---
fs/ocfs2/alloc.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 58bf58b68955..b15c6f751d99 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -2327,6 +2327,10 @@ static int ocfs2_rotate_requires_path_adjustment(struct ocfs2_path *left_path,

left_el = path_leaf_el(left_path);
next_free = le16_to_cpu(left_el->l_next_free_rec);
+
+ if (unlikely(next_free == 0))
+ return 0;
+
rec = &left_el->l_recs[next_free - 1];

if (insert_cpos > le32_to_cpu(rec->e_cpos))
--
2.25.1