lib/maple_tree: fix swapped arguments in mas_safe_pivot() call
Subsystems (3)
PATCH v2 1/1 lib/maple_tree: fix swapped arguments in mas_safe_pivot() call
From: Josh Law <[email protected]>
The call to mas_safe_pivot() in mas_wr_extend_null() has the pivot index and maple type arguments swapped. The function signature expects (mas, pivots, piv, type) but the call passes (mas, pivots, type, piv).
This causes the pivot index to be interpreted as a maple node type and vice versa, leading to incorrect pivot lookups. In practice, this means a null-extending store into a maple tree node can read the wrong pivot value, potentially corrupting the range tracked by the maple state. For a VMA maple tree, this could cause an incorrect vm_area_struct range to be returned during operations like mmap or munmap, leading to silent memory mapping corruption.
Every other mas_safe_pivot() call site in the file passes the arguments in the correct (piv, type) order; this is the only one with them reversed.
--- lib/maple_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +1 -1
@@ -3279,7 +3279,7 @@ static inline void mas_extend_spanning_null(struct ma_wr_state *l_wr_mas, (r_mas->last < r_mas->max) && !mas_slot_locked(r_mas, r_wr_mas->slots, r_mas->offset + 1)) { r_mas->last =mas_safe_pivot (r_mas, r_wr_mas->pivots, - r_wr_mas->type, r_mas->offset +1 ); + r_mas->offset +1 , r_wr_mas->type); r_mas->offset++; } }
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 14 lines · On Fri, 6 Mar 2026 22:32:19 +0000 Josh Law <[email protected]> wrote:
From: Josh Law <[email protected]>
The call to
mas_safe_pivot()inmas_wr_extend_null()has the pivot index and maple type arguments swapped. The function signature expects (mas, pivots, piv, type) but the call passes (mas, pivots, type, piv).This causes the pivot index to be interpreted as a maple node type and vice versa, leading to incorrect pivot lookups. In practice, this means a null-extending store into a maple tree node can read the wrong pivot value, potentially corrupting the range tracked by the maple state. For a VMA maple tree, this could cause an incorrect
vm_area_structrange to be returned during operations like mmap or munmap, leading to silent memory mapping corruption.
Quoted 3 lines
Every other
mas_safe_pivot()call site in the file passes the arguments in the correct (piv, type) order; this is the only one with them reversed.
This all appears to be identical to v1?
Quoted 9 lines
Fixes 54a611b60590 ("Maple Tree: add new data structure")Signed-off-by Josh Law <[email protected]>Cc Alice Ryhl <[email protected]>Cc Andrew Ballance <[email protected]>Cc Liam Howlett <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
Right here after the --- is where people add their what-i-changed-since-last time notes.
Quoted 2 lines
lib/maple_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
6 Mar 2026 22:57:21 Andrew Morton <[email protected]>:
Quoted 32 lines · On Fri, 6 Mar 2026 22:32:19 +0000 Josh Law <[email protected]> wrote:
Quoted 15 lines
From: Josh Law <[email protected]>
The call to
mas_safe_pivot()inmas_wr_extend_null()has the pivot index and maple type arguments swapped. The function signature expects (mas, pivots, piv, type) but the call passes (mas, pivots, type, piv).This causes the pivot index to be interpreted as a maple node type and vice versa, leading to incorrect pivot lookups. In practice, this means a null-extending store into a maple tree node can read the wrong pivot value, potentially corrupting the range tracked by the maple state. For a VMA maple tree, this could cause an incorrect
vm_area_structrange to be returned during operations like mmap or munmap, leading to silent memory mapping corruption.Quoted 3 lines
Every other
mas_safe_pivot()call site in the file passes the arguments in the correct (piv, type) order; this is the only one with them reversed.This all appears to be identical to v1?
Quoted 9 lines
Fixes 54a611b60590 ("Maple Tree: add new data structure")Signed-off-by Josh Law <[email protected]>Cc Alice Ryhl <[email protected]>Cc Andrew Ballance <[email protected]>Cc Liam Howlett <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
Quoted 5 lines
Right here after the --- is where people add their what-i-changed-since-last time notes.
Quoted 2 lines
lib/maple_tree.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Fixed on V3
Only the cc stable was changed so you don't have to do much haha
V/R
Josh law