]> 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:18:33 +0000 (15:18 -0500)
When iterating, a user may modify the tree and cause the iterator to be
out of range.  Detect this scenario and walk to the limit, then return
NULL

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

index 0da105a6d8a73708da607f97cee50825cb182658..b617a5f57ab69dfade387fa3915b2cfc56de2e6f 100644 (file)
@@ -4732,6 +4732,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_set(mas, limit);
+               mas_walk(mas);
+               return NULL;
+       }
        last = mas->last;
 retry:
        offset = mas->offset;
@@ -4838,6 +4843,11 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min)
 {
        void *entry;
 
+       if (mas->index < min) {
+               mas_set(mas, min);
+               mas_walk(mas);
+               return NULL;
+       }
 retry:
        while (likely(!mas_is_none(mas))) {
                entry = mas_prev_nentry(mas, min, mas->index);