Commit 3c5533e1 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

[PATCH] do_munmap() hugetlb fix

The hugetlb_page test in do_munmap is too permissive.  It checks start vma,
but forgets that end vma might be different and huge though start is not:
so hits unmap_hugepage_range BUG if misaligned end was given.

And it's too restrictive: munmap has always succeeded on unmapped areas
within its range, why should it behave differently near a hugepage vma?

And the additional checks in is_aligned_hugepage_range are irrelevant here,
when the hugepage vma already exists.  But the function is still required
(on some arches), as the default for prepare_hugepage_range - leave
renaming cleanup to another occasion.
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Acked-by: default avatarWilliam Irwin <wli@holomorphy.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c2a7650d
......@@ -1808,13 +1808,6 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
return 0;
/* we have start < mpnt->vm_end */
if (is_vm_hugetlb_page(mpnt)) {
int ret = is_aligned_hugepage_range(start, len);
if (ret)
return ret;
}
/* if it doesn't overlap, we have nothing.. */
end = start + len;
if (mpnt->vm_start >= end)
......@@ -1828,6 +1821,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
* places tmp vma above, and higher split_vma places tmp vma below.
*/
if (start > mpnt->vm_start) {
if (is_vm_hugetlb_page(mpnt) && (start & ~HPAGE_MASK))
return -EINVAL;
if (split_vma(mm, mpnt, start, 0))
return -ENOMEM;
prev = mpnt;
......@@ -1836,6 +1831,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
/* Does it split the last one? */
last = find_vma(mm, end);
if (last && end > last->vm_start) {
if (is_vm_hugetlb_page(last) && (end & ~HPAGE_MASK))
return -EINVAL;
if (split_vma(mm, last, end, 1))
return -ENOMEM;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment