Skip to content

Commit

Permalink
mm/mmap.c: expand_downwards: don't require the gap if !vm_prev
Browse files Browse the repository at this point in the history
expand_stack(vma) fails if address < stack_guard_gap even if there is no
vma->vm_prev.  I don't think this makes sense, and we didn't do this
before the recent commit 1be7107 ("mm: larger stack guard gap,
between vmas").

We do not need a gap in this case, any address is fine as long as
security_mmap_addr() doesn't object.

This also simplifies the code, we know that address >= prev->vm_end and
thus underflow is not possible.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Larry Woodman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Jul 10, 2017
1 parent 561b5e0 commit 32e4e6d
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2316,7 +2316,6 @@ int expand_downwards(struct vm_area_struct *vma,
{
struct mm_struct *mm = vma->vm_mm;
struct vm_area_struct *prev;
unsigned long gap_addr;
int error;

address &= PAGE_MASK;
Expand All @@ -2325,15 +2324,12 @@ int expand_downwards(struct vm_area_struct *vma,
return error;

/* Enforce stack_guard_gap */
gap_addr = address - stack_guard_gap;
if (gap_addr > address)
return -ENOMEM;
prev = vma->vm_prev;
if (prev && prev->vm_end > gap_addr &&
/* Check that both stack segments have the same anon_vma? */
if (prev && !(prev->vm_flags & VM_GROWSDOWN) &&
(prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
if (!(prev->vm_flags & VM_GROWSDOWN))
if (address - prev->vm_end < stack_guard_gap)
return -ENOMEM;
/* Check that both stack segments have the same anon_vma? */
}

/* We must make sure the anon_vma is allocated. */
Expand Down

0 comments on commit 32e4e6d

Please sign in to comment.