From: Liam R. Howlett Date: Thu, 17 Nov 2022 19:32:36 +0000 (-0500) Subject: maple_tree: Reduce user error potential X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b723e7bc9bc5b2044f456cd0407b9f91c89346fa;p=users%2Fjedix%2Flinux-maple.git maple_tree: Reduce user error potential 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 --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0da105a6d8a7..b617a5f57ab6 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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);