]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix null expand into ULONG_MAX causing incorrect metadata
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 10 May 2022 02:37:55 +0000 (22:37 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 11 May 2022 14:46:53 +0000 (10:46 -0400)
When expanding a null write to ULONG_MAX, it may cause the metadata
calculation to be off by one.  Fix this issue by detecting the offset
with write maple state end_piv instead of reading the node data.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 1bd8a4c2504ed384a2fdf5cdea71a0c8c1dec9ec..aee76fb39bfa3d9b4c6a066907251ed6a6960819 100644 (file)
@@ -3985,8 +3985,7 @@ static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas)
 
                new_end++;
        } else {
-               if (mas_safe_pivot(mas, wr_mas->pivots, wr_mas->offset_end,
-                                  wr_mas->type) == mas->last)
+               if (wr_mas->end_piv == mas->last)
                        wr_mas->offset_end++;
 
                new_end -= wr_mas->offset_end - offset - 1;
@@ -4150,6 +4149,7 @@ static inline void mas_wr_extend_null(struct ma_wr_state *wr_mas)
                        mas->last = mas->max;
                else
                        mas->last = wr_mas->pivots[wr_mas->offset_end];
+               wr_mas->end_piv = mas->last;
        } else if ((mas->last > wr_mas->end_piv) &&
                   !wr_mas->slots[wr_mas->offset_end]) {
                mas->last = wr_mas->end_piv;