Skip to content

Commit bfb4a2b

Browse files
DerDakonkees
authored andcommitted
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 <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8f6e3f9 commit bfb4a2b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

fs/exec.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,13 @@ int setup_arg_pages(struct linux_binprm *bprm,
843843
* will align it up.
844844
*/
845845
rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK;
846+
847+
stack_expand = min(rlim_stack, stack_size + stack_expand);
848+
846849
#ifdef CONFIG_STACK_GROWSUP
847-
if (stack_size + stack_expand > rlim_stack)
848-
stack_base = vma->vm_start + rlim_stack;
849-
else
850-
stack_base = vma->vm_end + stack_expand;
850+
stack_base = vma->vm_start + stack_expand;
851851
#else
852-
if (stack_size + stack_expand > rlim_stack)
853-
stack_base = vma->vm_end - rlim_stack;
854-
else
855-
stack_base = vma->vm_start - stack_expand;
852+
stack_base = vma->vm_end - stack_expand;
856853
#endif
857854
current->mm->start_stack = bprm->p;
858855
ret = expand_stack(vma, stack_base);

0 commit comments

Comments
 (0)