summaryrefslogtreecommitdiff
path: root/lib/maple_tree.c
diff options
context:
space:
mode:
authorLiam R. Howlett <Liam.Howlett@Oracle.com>2023-01-20 19:26:04 +0300
committerAndrew Morton <akpm@linux-foundation.org>2023-02-10 03:51:30 +0300
commit50e81c82ad947045c7ed26ddc9acb17276b653b6 (patch)
treee3e72a797d5ee9c6c2f90d19c44cff8a8d5cee02 /lib/maple_tree.c
parent65be6f058b0eba98dc6c6f197ea9f62c9b6a519f (diff)
downloadlinux-50e81c82ad947045c7ed26ddc9acb17276b653b6.tar.xz
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. Link: https://lkml.kernel.org/r/20230120162650.984577-4-Liam.Howlett@oracle.com Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib/maple_tree.c')
-rw-r--r--lib/maple_tree.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 7e3cf5b7e68b..5804c5997598 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->index = mas->last = limit;
+ mas_pause(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->index = mas->last = min;
+ mas_pause(mas);
+ return NULL;
+ }
retry:
while (likely(!mas_is_none(mas))) {
entry = mas_prev_nentry(mas, min, mas->index);