Skip to content

Commit

Permalink
mm/mempolicy: fix mbind_range() arguments to vma_merge()
Browse files Browse the repository at this point in the history
Fuzzing produced an invalid argument to vma_merge() which was caught by
the newly added verification of the number of VMAs being removed on
process exit.  Analyzing the failure eventually resulted in finding an
issue with the search of a VMA that started at address 0, which caused an
underflow and thus the loss of many VMAs being tracked in the tree.  Fix
the underflow by changing the search of the maple tree to use the start
address directly.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 66850be ("mm/mempolicy: use vma iterator & maple state instead of vma linked list")
Signed-off-by: Liam R. Howlett <[email protected]>
Reported-by: kernel test robot <[email protected]>
  Link: https://lore.kernel.org/r/[email protected]
Cc: Yu Zhao <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
howlett authored and akpm00 committed Oct 21, 2022
1 parent cef408e commit 7329e3e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mm/mempolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,17 +787,22 @@ static int vma_replace_policy(struct vm_area_struct *vma,
static int mbind_range(struct mm_struct *mm, unsigned long start,
unsigned long end, struct mempolicy *new_pol)
{
MA_STATE(mas, &mm->mm_mt, start - 1, start - 1);
MA_STATE(mas, &mm->mm_mt, start, start);
struct vm_area_struct *prev;
struct vm_area_struct *vma;
int err = 0;
pgoff_t pgoff;

prev = mas_find_rev(&mas, 0);
if (prev && (start < prev->vm_end))
vma = prev;
else
vma = mas_next(&mas, end - 1);
prev = mas_prev(&mas, 0);
if (unlikely(!prev))
mas_set(&mas, start);

vma = mas_find(&mas, end - 1);
if (WARN_ON(!vma))
return 0;

if (start > vma->vm_start)
prev = vma;

for (; vma; vma = mas_next(&mas, end - 1)) {
unsigned long vmstart = max(start, vma->vm_start);
Expand Down

0 comments on commit 7329e3e

Please sign in to comment.