aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/mmap.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index 37a1fcac029d..2664a47cec93 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2185,9 +2185,28 @@ int expand_downwards(struct vm_area_struct *vma,
2185 return error; 2185 return error;
2186} 2186}
2187 2187
2188/*
2189 * Note how expand_stack() refuses to expand the stack all the way to
2190 * abut the next virtual mapping, *unless* that mapping itself is also
2191 * a stack mapping. We want to leave room for a guard page, after all
2192 * (the guard page itself is not added here, that is done by the
2193 * actual page faulting logic)
2194 *
2195 * This matches the behavior of the guard page logic (see mm/memory.c:
2196 * check_stack_guard_page()), which only allows the guard page to be
2197 * removed under these circumstances.
2198 */
2188#ifdef CONFIG_STACK_GROWSUP 2199#ifdef CONFIG_STACK_GROWSUP
2189int expand_stack(struct vm_area_struct *vma, unsigned long address) 2200int expand_stack(struct vm_area_struct *vma, unsigned long address)
2190{ 2201{
2202 struct vm_area_struct *next;
2203
2204 address &= PAGE_MASK;
2205 next = vma->vm_next;
2206 if (next && next->vm_start == address + PAGE_SIZE) {
2207 if (!(next->vm_flags & VM_GROWSUP))
2208 return -ENOMEM;
2209 }
2191 return expand_upwards(vma, address); 2210 return expand_upwards(vma, address);
2192} 2211}
2193 2212
@@ -2209,6 +2228,14 @@ find_extend_vma(struct mm_struct *mm, unsigned long addr)
2209#else 2228#else
2210int expand_stack(struct vm_area_struct *vma, unsigned long address) 2229int expand_stack(struct vm_area_struct *vma, unsigned long address)
2211{ 2230{
2231 struct vm_area_struct *prev;
2232
2233 address &= PAGE_MASK;
2234 prev = vma->vm_prev;
2235 if (prev && prev->vm_end == address) {
2236 if (!(prev->vm_flags & VM_GROWSDOWN))
2237 return -ENOMEM;
2238 }
2212 return expand_downwards(vma, address); 2239 return expand_downwards(vma, address);
2213} 2240}
2214 2241