Commit 0d59a01bc461bbab4017ff449b8401151ef44cf6

Authored by Adam Litke
Committed by Linus Torvalds
1 parent bcdddfb66c

[PATCH] Don't allow the stack to grow into hugetlb reserved regions

When expanding the stack, we don't currently check if the VMA will cross
into an area of the address space that is reserved for hugetlb pages.
Subsequent faults on the expanded portion of such a VMA will confuse the
low-level MMU code, resulting in an OOPS.  Check for this.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: William Lee Irwin III <wli@holomorphy.com>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 7 additions and 0 deletions Side-by-side Diff

... ... @@ -1477,6 +1477,7 @@
1477 1477 {
1478 1478 struct mm_struct *mm = vma->vm_mm;
1479 1479 struct rlimit *rlim = current->signal->rlim;
  1480 + unsigned long new_start;
1480 1481  
1481 1482 /* address space limit tests */
1482 1483 if (!may_expand_vm(mm, grow))
... ... @@ -1495,6 +1496,12 @@
1495 1496 if (locked > limit && !capable(CAP_IPC_LOCK))
1496 1497 return -ENOMEM;
1497 1498 }
  1499 +
  1500 + /* Check to ensure the stack will not grow into a hugetlb-only region */
  1501 + new_start = (vma->vm_flags & VM_GROWSUP) ? vma->vm_start :
  1502 + vma->vm_end - size;
  1503 + if (is_hugepage_only_range(vma->vm_mm, new_start, size))
  1504 + return -EFAULT;
1498 1505  
1499 1506 /*
1500 1507 * Overcommit.. This must be the final test, as it will