summaryrefslogtreecommitdiff
path: root/fs/exec.c
diff options
context:
space:
mode:
authorRolf Eike Beer <eb@emlix.com>2022-10-19 09:32:35 +0200
committerKees Cook <keescook@chromium.org>2022-10-25 15:19:48 -0700
commitbfb4a2b95875a47a01234f2de113ec089d524e71 (patch)
tree5504d985271fe5c15cb193423169553bdc4acd3b /fs/exec.c
parent8f6e3f9e5a0f58e458a348b7e36af11d0e9702af (diff)
downloadlwn-bfb4a2b95875a47a01234f2de113ec089d524e71.tar.gz
lwn-bfb4a2b95875a47a01234f2de113ec089d524e71.zip
exec: simplify initial stack size expansion
I had a hard time trying to understand completely why it is using vm_end in one side of the expression and vm_start in the other one, and using something in the "if" clause that is not an exact copy of what is used below. The whole point is that the stack_size variable that was used in the "if" clause is the difference between vm_start and vm_end, which is not far away but makes this thing harder to read than it must be. Signed-off-by: Rolf Eike Beer <eb@emlix.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/2017429.gqNitNVd0C@mobilepool36.emlix.com
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 1644bf10fb9d..9585bc1bc970 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -843,16 +843,13 @@ int setup_arg_pages(struct linux_binprm *bprm,
* will align it up.
*/
rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK;
+
+ stack_expand = min(rlim_stack, stack_size + stack_expand);
+
#ifdef CONFIG_STACK_GROWSUP
- if (stack_size + stack_expand > rlim_stack)
- stack_base = vma->vm_start + rlim_stack;
- else
- stack_base = vma->vm_end + stack_expand;
+ stack_base = vma->vm_start + stack_expand;
#else
- if (stack_size + stack_expand > rlim_stack)
- stack_base = vma->vm_end - rlim_stack;
- else
- stack_base = vma->vm_start - stack_expand;
+ stack_base = vma->vm_end - stack_expand;
#endif
current->mm->start_stack = bprm->p;
ret = expand_stack(vma, stack_base);