Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exec: Factor bprm_stack_limits out of prepare_arg_pages

In preparation for implementiong kernel_execve (which will take kernel
pointers not userspace pointers) factor out bprm_stack_limits out of
prepare_arg_pages. This separates the counting which depends upon the
getting data from userspace from the calculations of the stack limits
which is usable in kernel_execve.

The remove prepare_args_pages and compute bprm->argc and bprm->envc
directly in do_execveat_common, before bprm_stack_limits is called.

Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lkml.kernel.org/r/87365u6x60.fsf@x220.int.ebiederm.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+12 -11
+12 -11
fs/exec.c
··· 448 448 return i; 449 449 } 450 450 451 - static int prepare_arg_pages(struct linux_binprm *bprm, 452 - struct user_arg_ptr argv, struct user_arg_ptr envp) 451 + static int bprm_stack_limits(struct linux_binprm *bprm) 453 452 { 454 453 unsigned long limit, ptr_size; 455 - 456 - bprm->argc = count(argv, MAX_ARG_STRINGS); 457 - if (bprm->argc < 0) 458 - return bprm->argc; 459 - 460 - bprm->envc = count(envp, MAX_ARG_STRINGS); 461 - if (bprm->envc < 0) 462 - return bprm->envc; 463 454 464 455 /* 465 456 * Limit to 1/4 of the max stack size or 3/4 of _STK_LIM ··· 1955 1964 goto out_ret; 1956 1965 } 1957 1966 1958 - retval = prepare_arg_pages(bprm, argv, envp); 1967 + retval = count(argv, MAX_ARG_STRINGS); 1968 + if (retval < 0) 1969 + goto out_free; 1970 + bprm->argc = retval; 1971 + 1972 + retval = count(envp, MAX_ARG_STRINGS); 1973 + if (retval < 0) 1974 + goto out_free; 1975 + bprm->envc = retval; 1976 + 1977 + retval = bprm_stack_limits(bprm); 1959 1978 if (retval < 0) 1960 1979 goto out_free; 1961 1980