2a20abb57689fd38c40ac1fcbf6c2466c2553751
[AGL/meta-agl.git] / meta-agl-bsp / meta-raspberrypi / recipes-kernel / linux / linux-raspberrypi-4.9 / 0002-Allow-stack-to-grow-up-to-address-space-limit.patch
1 From 88aa347d26911cffd84ac3dd2a8341f1ba7e3444 Mon Sep 17 00:00:00 2001
2 From: Helge Deller <deller@gmx.de>
3 Date: Mon, 19 Jun 2017 17:34:05 +0200
4 Subject: [PATCH 2/3] Allow stack to grow up to address space limit
5
6 commit bd726c90b6b8ce87602208701b208a208e6d5600 upstream.
7
8 Fix expand_upwards() on architectures with an upward-growing stack (parisc,
9 metag and partly IA-64) to allow the stack to reliably grow exactly up to
10 the address space limit given by TASK_SIZE.
11
12 Signed-off-by: Helge Deller <deller@gmx.de>
13 Acked-by: Hugh Dickins <hughd@google.com>
14 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17  mm/mmap.c | 13 ++++++++-----
18  1 file changed, 8 insertions(+), 5 deletions(-)
19
20 diff --git a/mm/mmap.c b/mm/mmap.c
21 index 26542b3..d71a61e 100644
22 --- a/mm/mmap.c
23 +++ b/mm/mmap.c
24 @@ -2224,16 +2224,19 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
25         if (!(vma->vm_flags & VM_GROWSUP))
26                 return -EFAULT;
27  
28 -       /* Guard against wrapping around to address 0. */
29 +       /* Guard against exceeding limits of the address space. */
30         address &= PAGE_MASK;
31 -       address += PAGE_SIZE;
32 -       if (!address)
33 +       if (address >= TASK_SIZE)
34                 return -ENOMEM;
35 +       address += PAGE_SIZE;
36  
37         /* Enforce stack_guard_gap */
38         gap_addr = address + stack_guard_gap;
39 -       if (gap_addr < address)
40 -               return -ENOMEM;
41 +
42 +       /* Guard against overflow */
43 +       if (gap_addr < address || gap_addr > TASK_SIZE)
44 +               gap_addr = TASK_SIZE;
45 +
46         next = vma->vm_next;
47         if (next && next->vm_start < gap_addr) {
48                 if (!(next->vm_flags & VM_GROWSUP))
49 -- 
50 2.1.4
51