Skip to content

Commit 1419430

Browse files
howlettakpm00
authored andcommitted
mmap: fix vma_iterator in error path of vma_merge()
During the error path, the vma iterator may not be correctly positioned or set to the correct range. Undo the vma_prev() call by resetting to the passed in address. Re-walking to the same range will fix the range to the area previously passed in. Users would notice increased cycles as vma_merge() would be called an extra time with vma == prev, and thus would fail to merge and return. Link: https://lore.kernel.org/linux-mm/CAG48ez12VN1JAOtTNMY+Y2YnsU45yL5giS-Qn=ejtiHpgJAbdQ@mail.gmail.com/ Link: https://lkml.kernel.org/r/[email protected] Fixes: 18b098a ("vma_merge: set vma iterator to correct position.") Signed-off-by: Liam R. Howlett <[email protected]> Reported-by: Jann Horn <[email protected]> Closes: https://lore.kernel.org/linux-mm/CAG48ez12VN1JAOtTNMY+Y2YnsU45yL5giS-Qn=ejtiHpgJAbdQ@mail.gmail.com/ Reviewed-by: Lorenzo Stoakes <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e0f81ab commit 1419430

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mm/mmap.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
975975

976976
/* Error in anon_vma clone. */
977977
if (err)
978-
return NULL;
978+
goto anon_vma_fail;
979979

980980
if (vma_start < vma->vm_start || vma_end > vma->vm_end)
981981
vma_expanded = true;
@@ -988,7 +988,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
988988
}
989989

990990
if (vma_iter_prealloc(vmi, vma))
991-
return NULL;
991+
goto prealloc_fail;
992992

993993
init_multi_vma_prep(&vp, vma, adjust, remove, remove2);
994994
VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma &&
@@ -1016,6 +1016,12 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
10161016
vma_complete(&vp, vmi, mm);
10171017
khugepaged_enter_vma(res, vm_flags);
10181018
return res;
1019+
1020+
prealloc_fail:
1021+
anon_vma_fail:
1022+
vma_iter_set(vmi, addr);
1023+
vma_iter_load(vmi);
1024+
return NULL;
10191025
}
10201026

10211027
/*

0 commit comments

Comments
 (0)