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=1535c813e5a95d31db776898cc354f51c5065b3f;p=users%2Fjedix%2Flinux-maple.git maple_tree: Reduce user error potential When iterating, a user may operate on the tree and cause the maple state to be altered and left in an unintuitive state. Detect this scenario and correct it by setting to the limit and invalidating the state. Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index ff28bd6d4745..440539ff0d11 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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);