Skip to content

Commit f41512c

Browse files
hdellergregkh
authored andcommitted
Allow stack to grow up to address space limit
commit bd726c90b6b8ce87602208701b208a208e6d5600 upstream. Fix expand_upwards() on architectures with an upward-growing stack (parisc, metag and partly IA-64) to allow the stack to reliably grow exactly up to the address space limit given by TASK_SIZE. Signed-off-by: Helge Deller <deller@gmx.de> Acked-by: Hugh Dickins <hughd@google.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4b35943 commit f41512c

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

mm/mmap.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,16 +2172,19 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
21722172
if (!(vma->vm_flags & VM_GROWSUP))
21732173
return -EFAULT;
21742174

2175-
/* Guard against wrapping around to address 0. */
2175+
/* Guard against exceeding limits of the address space. */
21762176
address &= PAGE_MASK;
2177-
address += PAGE_SIZE;
2178-
if (!address)
2177+
if (address >= TASK_SIZE)
21792178
return -ENOMEM;
2179+
address += PAGE_SIZE;
21802180

21812181
/* Enforce stack_guard_gap */
21822182
gap_addr = address + stack_guard_gap;
2183-
if (gap_addr < address)
2184-
return -ENOMEM;
2183+
2184+
/* Guard against overflow */
2185+
if (gap_addr < address || gap_addr > TASK_SIZE)
2186+
gap_addr = TASK_SIZE;
2187+
21852188
next = vma->vm_next;
21862189
if (next && next->vm_start < gap_addr) {
21872190
if (!(next->vm_flags & VM_GROWSUP))

0 commit comments

Comments
 (0)