diff options
author | Oleg Nesterov <oleg@redhat.com> | 2017-07-10 15:49:54 -0700 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2019-05-02 21:42:01 +0100 |
commit | 120d66394f05ec50a018168850a8db6518ea2d9b (patch) | |
tree | 753bf289726863b05f2f683f9b18bbb581ca4d13 /mm | |
parent | 2c716db6f80cef6159972be0dab86892c39de277 (diff) | |
download | linux-stable-120d66394f05ec50a018168850a8db6518ea2d9b.tar.gz linux-stable-120d66394f05ec50a018168850a8db6518ea2d9b.tar.bz2 linux-stable-120d66394f05ec50a018168850a8db6518ea2d9b.zip |
mm/mmap.c: expand_downwards: don't require the gap if !vm_prev
commit 32e4e6d5cbb0c0e427391635991fe65e17797af8 upstream.
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 1be7107fbe18 ("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/20170628175258.GA24881@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Larry Woodman <lwoodman@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/mmap.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/mm/mmap.c b/mm/mmap.c index f557e90fc719..328acb37e23d 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2244,7 +2244,6 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address) { struct vm_area_struct *prev; - unsigned long gap_addr; int error; address &= PAGE_MASK; @@ -2253,15 +2252,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. */ |