fs/exec.c: simplify initial stack size expansion
Subsystems (3)
PATCH 1/1 fs/exec.c: 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.
--- fs/exec.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/exec.c +5 -8
@@ -840,16 +840,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);
Signature · 11 lines
2.37.3 -- Rolf Eike Beer, emlix GmbH, https://www.emlix.com Fon +49 551 30664-0, Fax +49 551 30664-11 Gothaer Platz 3, 37083 Göttingen, Germany Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160 Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055 emlix - smart embedded open source
Kees Cook
AppliedQuoted 8 lines · Rolf Eike Beer
I had a hard time trying to understand completely why it is using
vm_endin one side of the expression andvm_startin 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 thestack_sizevariable that was used in the "if" clause is the difference betweenvm_startandvm_end, which is not far away but makes this thing harder to read than it must be.[...]
Applied to for-next/execve, thanks!
[1/1] fs/exec.c: simplify initial stack size expansion
https://git.kernel.org/kees/c/bfb4a2b95875
Signature · 1 line
Kees Cook