linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/maple_tree: fix swapped arguments in mas_safe_pivot() call
@ 2026-03-06 20:08 Josh Law
  2026-03-06 21:33 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Josh Law @ 2026-03-06 20:08 UTC (permalink / raw)
  To: Liam.Howlett, akpm
  Cc: aliceryhl, andrewjballance, maple-tree, linux-mm, linux-kernel, Josh Law

From: Josh Law <objecting@objecting.org>

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.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 5aa4c9500018..f82000821293 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -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++;
 	}
 }
-- 
2.43.0



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

end of thread, other threads:[~2026-03-06 23:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-06 20:08 [PATCH] lib/maple_tree: fix swapped arguments in mas_safe_pivot() call Josh Law
2026-03-06 21:33 ` Andrew Morton
2026-03-06 22:11   ` Josh Law
2026-03-06 22:54     ` Andrew Morton
2026-03-06 23:38       ` Josh Law

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