Skip to content

Commit d71f290

Browse files
author
James Hogan
committed
metag: Reduce maximum stack size to 256MB
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> Cc: stable@vger.kernel.org # only needed for >= v3.9 (arch/metag)
1 parent 2425ce8 commit d71f290

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎arch/metag/include/asm/processor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
/* Add an extra page of padding at the top of the stack for the guard page. */
2323
#define STACK_TOP (TASK_SIZE - PAGE_SIZE)
2424
#define STACK_TOP_MAX STACK_TOP
25+
/* Maximum virtual space for stack */
26+
#define STACK_SIZE_MAX (1 << 28) /* 256 MB */
2527

2628
/* This decides where the kernel will search for a free chunk of vm
2729
* space during mmap's.

‎arch/parisc/include/asm/processor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#define STACK_TOP TASK_SIZE
5656
#define STACK_TOP_MAX DEFAULT_TASK_SIZE
5757

58+
#define STACK_SIZE_MAX (1 << 30) /* 1 GB */
59+
5860
#endif
5961

6062
#ifndef __ASSEMBLY__

‎fs/exec.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,10 @@ int setup_arg_pages(struct linux_binprm *bprm,
657657
unsigned long rlim_stack;
658658

659659
#ifdef CONFIG_STACK_GROWSUP
660-
/* Limit stack size to 1GB */
660+
/* Limit stack size */
661661
stack_base = rlimit_max(RLIMIT_STACK);
662-
if (stack_base > (1 << 30))
663-
stack_base = 1 << 30;
662+
if (stack_base > STACK_SIZE_MAX)
663+
stack_base = STACK_SIZE_MAX;
664664

665665
/* Make sure we didn't let the argument array grow too large. */
666666
if (vma->vm_end - vma->vm_start > stack_base)

0 commit comments

Comments
 (0)