]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Reduce user error potential
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 17 Nov 2022 19:32:36 +0000 (14:32 -0500)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Mon, 28 Nov 2022 20:58:17 +0000 (15:58 -0500)
When iterating, a user may modify the tree and cause the iterator to be
out of range.  Detect this scenario and correct it by setting to the
limit and invalidating the state.

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

index ff28bd6d47455c4ad7474ac0d83642a0c63a3c95..440539ff0d118541b874dcdd9da74da940f9624e 100644 (file)
@@ -4735,6 +4735,11 @@ static inline void *mas_next_entry(struct ma_state *mas, unsigned long limit)
        unsigned long last;
        enum maple_type mt;
 
+       if (mas->index > limit) {
+               mas->index = mas->last = limit;
+               mas_pause(mas);
+               return NULL;
+       }
        last = mas->last;
 retry:
        offset = mas->offset;
@@ -4841,6 +4846,11 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min)
 {
        void *entry;
 
+       if (mas->index < min) {
+               mas->index = mas->last = min;
+               mas_pause(mas);
+               return NULL;
+       }
 retry:
        while (likely(!mas_is_none(mas))) {
                entry = mas_prev_nentry(mas, min, mas->index);