Skip to content

Commit 0abb964

Browse files
howlettakpm00
authored andcommitted
maple_tree: fix mas_spanning_rebalance() on insufficient data
Mike Rapoport contacted me off-list with a regression in running criu. Periodic tests fail with an RCU stall during execution. Although rare, it is possible to hit this with other uses so this patch should be backported to fix the regression. This patchset adds the fix and a test case to the maple tree test suite. This patch (of 2): An insufficient node was causing an out-of-bounds access on the node in mas_leaf_max_gap(). The cause was the faulty detection of the new node being a root node when overwriting many entries at the end of the tree. Fix the detection of a new root and ensure there is sufficient data prior to entering the spanning rebalance loop. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 54a611b ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett <[email protected]> Reported-by: Mike Rapoport <[email protected]> Tested-by: Mike Rapoport <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Muhammad Usama Anjum <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e700898 commit 0abb964

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/maple_tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,9 @@ static int mas_spanning_rebalance(struct ma_state *mas,
29942994
mast->free = &free;
29952995
mast->destroy = &destroy;
29962996
l_mas.node = r_mas.node = m_mas.node = MAS_NONE;
2997-
if (!(mast->orig_l->min && mast->orig_r->max == ULONG_MAX) &&
2997+
2998+
/* Check if this is not root and has sufficient data. */
2999+
if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) &&
29983000
unlikely(mast->bn->b_end <= mt_min_slots[mast->bn->type]))
29993001
mast_spanning_rebalance(mast);
30003002

0 commit comments

Comments
 (0)