mm/mremap: fix dup_anon_vma() in vma_merge() case 4
authorVlastimil Babka <vbabka@suse.cz>
Tue, 28 Feb 2023 01:00:14 +0000 (17:00 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 28 Feb 2023 01:00:14 +0000 (17:00 -0800)
In case 4, we are shrinking 'prev' (PPPP in the comment) and expanding
'mid' (NNNN).  So we need to make sure 'mid' clones the anon_vma from
'prev', if it doesn't have any.  After commit 0503ea8f5ba7 ("mm/mmap:
remove __vma_adjust()") we can fail to do that due to wrong parameters for
dup_anon_vma().  The call is a no-op because res == next, adjust == mid
and mid == next.  Fix it.

Link: https://lkml.kernel.org/r/ad91d62b-37eb-4b73-707a-3c45c9e16256@suse.cz
Fixes: 0503ea8f5ba7 ("mm/mmap: remove __vma_adjust()")
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c

index 20f21f0949ddb1eb0324dc75f9149009df238a69..740b54be3ed4140f16a6731a275ab49f3a8b256f 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -973,7 +973,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
                        vma_end = addr;
                        adjust = mid;
                        adj_next = -(vma->vm_end - addr);
-                       err = dup_anon_vma(res, adjust);
+                       err = dup_anon_vma(adjust, prev);
                } else {
                        vma = next;                     /* case 3 */
                        vma_start = addr;