]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
maple_tree: fix mas_prev() and mas_find() state handling
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 11 Apr 2023 15:10:46 +0000 (11:10 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Apr 2023 15:02:58 +0000 (17:02 +0200)
commit 17dc622c7b0f94e49bed030726df4db12ecaa6b5 upstream.

When mas_prev() does not find anything, set the state to MAS_NONE.

Handle the MAS_NONE in mas_find() like a MAS_START.

Link: https://lkml.kernel.org/r/20230120162650.984577-7-Liam.Howlett@oracle.com
Cc: <Stable@vger.kernel.org>
Fixes: 54a611b60590 ("Maple Tree: add new data structure")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reported-by: <syzbot+502859d610c661e56545@syzkaller.appspotmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/maple_tree.c

index 6041f74af1a358dfa45618ffb2ea0538716f9ed6..480e7fbf21cc786369fbba6e0ed3a48ddbcda58f 100644 (file)
@@ -4849,7 +4849,7 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min)
 
        if (mas->index < min) {
                mas->index = mas->last = min;
-               mas_pause(mas);
+               mas->node = MAS_NONE;
                return NULL;
        }
 retry:
@@ -5911,6 +5911,7 @@ void *mas_prev(struct ma_state *mas, unsigned long min)
        if (!mas->index) {
                /* Nothing comes before 0 */
                mas->last = 0;
+               mas->node = MAS_NONE;
                return NULL;
        }
 
@@ -6001,6 +6002,9 @@ void *mas_find(struct ma_state *mas, unsigned long max)
                mas->index = ++mas->last;
        }
 
+       if (unlikely(mas_is_none(mas)))
+               mas->node = MAS_START;
+
        if (unlikely(mas_is_start(mas))) {
                /* First run or continue */
                void *entry;