Skip to content

Commit d8b9cd5

Browse files
committed
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 0c9cdff commit d8b9cd5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

fs/exec.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,10 @@ static int count(struct user_arg_ptr argv, int max)
448448
return i;
449449
}
450450

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)
453452
{
454453
unsigned long limit, ptr_size;
455454

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-
464455
/*
465456
* Limit to 1/4 of the max stack size or 3/4 of _STK_LIM
466457
* (whichever is smaller) for the argv+env strings.
@@ -1964,7 +1955,17 @@ static int do_execveat_common(int fd, struct filename *filename,
19641955
goto out_ret;
19651956
}
19661957

1967-
retval = prepare_arg_pages(bprm, argv, envp);
1958+
retval = count(argv, MAX_ARG_STRINGS);
1959+
if (retval < 0)
1960+
goto out_free;
1961+
bprm->argc = retval;
1962+
1963+
retval = count(envp, MAX_ARG_STRINGS);
1964+
if (retval < 0)
1965+
goto out_free;
1966+
bprm->envc = retval;
1967+
1968+
retval = bprm_stack_limits(bprm);
19681969
if (retval < 0)
19691970
goto out_free;
19701971

0 commit comments

Comments
 (0)