metag: Reduce maximum stack size to 256MB
authorJames Hogan <james.hogan@imgtec.com>
Tue, 13 May 2014 22:58:24 +0000 (23:58 +0100)
committerJiri Slaby <jslaby@suse.cz>
Mon, 9 Jun 2014 13:53:41 +0000 (15:53 +0200)
commit d71f290b4e98a39f49f2595a13be3b4d5ce8e1f1 upstream.

Specify the maximum stack size for arches where the stack grows upward
(parisc and metag) in asm/processor.h rather than hard coding in
fs/exec.c so that metag can specify a smaller value of 256MB rather than
1GB.

This fixes a BUG on metag if the RLIMIT_STACK hard limit is increased
beyond a safe value by root. E.g. when starting a process after running
"ulimit -H -s unlimited" it will then attempt to use a stack size of the
maximum 1GB which is far too big for metag's limited user virtual
address space (stack_top is usually 0x3ffff000):

BUG: failure at fs/exec.c:589/shift_arg_pages()!

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: linux-parisc@vger.kernel.org
Cc: linux-metag@vger.kernel.org
Cc: John David Anglin <dave.anglin@bell.net>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
arch/metag/include/asm/processor.h
arch/parisc/include/asm/processor.h
fs/exec.c

index f16477d1f571cb134a29e3afd13c480401f340ea..3be8581af4956ad7bd559c2c314450eadf7f9750 100644 (file)
@@ -22,6 +22,8 @@
 /* Add an extra page of padding at the top of the stack for the guard page. */
 #define STACK_TOP      (TASK_SIZE - PAGE_SIZE)
 #define STACK_TOP_MAX  STACK_TOP
+/* Maximum virtual space for stack */
+#define STACK_SIZE_MAX (1 << 28)       /* 256 MB */
 
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
index cc2290a3cace1e0d65f8e69be0138c0c09cc8b2a..c6ee86542fecb727c3e71e21bd5f98962b3c733a 100644 (file)
@@ -53,6 +53,8 @@
 #define STACK_TOP      TASK_SIZE
 #define STACK_TOP_MAX  DEFAULT_TASK_SIZE
 
+#define STACK_SIZE_MAX (1 << 30)       /* 1 GB */
+
 #endif
 
 #ifndef __ASSEMBLY__
index bb8afc1d1df425ccfcb1eba43f2d08ede400e39c..95eef54de2b6d7dba724bf0f984a236d3b91aa29 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -657,10 +657,10 @@ int setup_arg_pages(struct linux_binprm *bprm,
        unsigned long rlim_stack;
 
 #ifdef CONFIG_STACK_GROWSUP
-       /* Limit stack size to 1GB */
+       /* Limit stack size */
        stack_base = rlimit_max(RLIMIT_STACK);
-       if (stack_base > (1 << 30))
-               stack_base = 1 << 30;
+       if (stack_base > STACK_SIZE_MAX)
+               stack_base = STACK_SIZE_MAX;
 
        /* Make sure we didn't let the argument array grow too large. */
        if (vma->vm_end - vma->vm_start > stack_base)