]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/mmap: Correctly position vma_iterator in __split_vma()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 19 Apr 2024 13:57:51 +0000 (09:57 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 7 Jun 2024 14:32:18 +0000 (10:32 -0400)
The vma iterator may be left pointing to the newly created vma.  This
happens when inserting the new vma at the end of the old vma
(!new_below).

The incorrect position in the vma iterator is not exposed currently
since the vma iterator is repositioned in the munmap path and is not
reused in any of the other paths.

This has limited impact in the current code, but is required for future
changes.

Fixes: b2b3b886738f ("mm: don't use __vma_adjust() in __split_vma()")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
mm/mmap.c

index 83b4682ec85cfa0398ab0e50f9c4c8f35f993d90..4a9929bc18bda805a0384836e2ac5c2b8396065e 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2373,7 +2373,7 @@ static void unmap_region(struct mm_struct *mm, struct ma_state *mas,
 /*
  * __split_vma() bypasses sysctl_max_map_count checking.  We use this where it
  * has already been checked or doesn't make sense to fail.
- * VMA Iterator will point to the end VMA.
+ * VMA Iterator will point to the original vma.
  */
 static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
                       unsigned long addr, int new_below)
@@ -2442,6 +2442,9 @@ static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
        /* Success. */
        if (new_below)
                vma_next(vmi);
+       else
+               vma_prev(vmi);
+
        return 0;
 
 out_free_mpol: