mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
fs/exec.c: restrict initial stack space expansion to rlimit
When reserving stack space for a new process, make sure we're not attempting to expand the stack by more than rlimit allows. This fixes a bug caused byb6a2fea393("mm: variable length argument support") and unmasked byfc63cf2370("exec: setup_arg_pages() fails to return errors"). This bug means that when limiting the stack to less the 20*PAGE_SIZE (eg. 80K on 4K pages or 'ulimit -s 79') all processes will be killed before they start. This is particularly bad with 64K pages, where a ulimit below 1280K will kill every process. To test, do: 'ulimit -s 15; ls' before and after the patch is applied. Before it's applied, 'ls' should be killed. After the patch is applied, 'ls' should no longer be killed. A stack limit of 15KB since it's small enough to trigger 20*PAGE_SIZE. Also 15KB not a multiple of PAGE_SIZE, which is a trickier case to handle correctly with this code. 4K pages should be fine to test with. [[email protected]: cleanup] [[email protected]: cleanup cleanup] Signed-off-by: Michael Neuling <[email protected]> Signed-off-by: KOSAKI Motohiro <[email protected]> Cc: Americo Wang <[email protected]> Cc: Anton Blanchard <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: James Morris <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Serge Hallyn <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
4cfbafd33f
commit
803bf5ec25
1 changed files with 19 additions and 2 deletions
21
fs/exec.c
21
fs/exec.c
|
|
@ -571,6 +571,9 @@ int setup_arg_pages(struct linux_binprm *bprm,
|
|||
struct vm_area_struct *prev = NULL;
|
||||
unsigned long vm_flags;
|
||||
unsigned long stack_base;
|
||||
unsigned long stack_size;
|
||||
unsigned long stack_expand;
|
||||
unsigned long rlim_stack;
|
||||
|
||||
#ifdef CONFIG_STACK_GROWSUP
|
||||
/* Limit stack size to 1GB */
|
||||
|
|
@ -627,10 +630,24 @@ int setup_arg_pages(struct linux_binprm *bprm,
|
|||
goto out_unlock;
|
||||
}
|
||||
|
||||
stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
|
||||
stack_size = vma->vm_end - vma->vm_start;
|
||||
/*
|
||||
* Align this down to a page boundary as expand_stack
|
||||
* will align it up.
|
||||
*/
|
||||
rlim_stack = rlimit(RLIMIT_STACK) & PAGE_MASK;
|
||||
rlim_stack = min(rlim_stack, stack_size);
|
||||
#ifdef CONFIG_STACK_GROWSUP
|
||||
stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
|
||||
if (stack_size + stack_expand > rlim_stack)
|
||||
stack_base = vma->vm_start + rlim_stack;
|
||||
else
|
||||
stack_base = vma->vm_end + stack_expand;
|
||||
#else
|
||||
stack_base = vma->vm_start - EXTRA_STACK_VM_PAGES * PAGE_SIZE;
|
||||
if (stack_size + stack_expand > rlim_stack)
|
||||
stack_base = vma->vm_end - rlim_stack;
|
||||
else
|
||||
stack_base = vma->vm_start - stack_expand;
|
||||
#endif
|
||||
ret = expand_stack(vma, stack_base);
|
||||
if (ret)
|
||||
|
|
|
|||
Loading…
Reference in a new issue