Skip to content

Commit

Permalink
exec: simplify the copy_strings_kernel calling convention
Browse files Browse the repository at this point in the history
copy_strings_kernel is always used with a single argument,
adjust the calling convention to that.

Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Alexander Viro <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Christoph Hellwig authored and torvalds committed Jun 5, 2020
1 parent eac2cec commit 986db2d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions fs/binfmt_em86.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ static int load_em86(struct linux_binprm *bprm)
* user environment and arguments are stored.
*/
remove_arg_zero(bprm);
retval = copy_strings_kernel(1, &bprm->filename, bprm);
retval = copy_string_kernel(bprm->filename, bprm);
if (retval < 0) return retval;
bprm->argc++;
if (i_arg) {
retval = copy_strings_kernel(1, &i_arg, bprm);
retval = copy_string_kernel(i_arg, bprm);
if (retval < 0) return retval;
bprm->argc++;
}
retval = copy_strings_kernel(1, &i_name, bprm);
retval = copy_string_kernel(i_name, bprm);
if (retval < 0) return retval;
bprm->argc++;

Expand Down
4 changes: 2 additions & 2 deletions fs/binfmt_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ static int load_misc_binary(struct linux_binprm *bprm)
bprm->file = NULL;
}
/* make argv[1] be the path to the binary */
retval = copy_strings_kernel(1, &bprm->interp, bprm);
retval = copy_string_kernel(bprm->interp, bprm);
if (retval < 0)
goto error;
bprm->argc++;

/* add the interp as argv[0] */
retval = copy_strings_kernel(1, &fmt->interpreter, bprm);
retval = copy_string_kernel(fmt->interpreter, bprm);
if (retval < 0)
goto error;
bprm->argc++;
Expand Down
6 changes: 3 additions & 3 deletions fs/binfmt_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ static int load_script(struct linux_binprm *bprm)
retval = remove_arg_zero(bprm);
if (retval)
return retval;
retval = copy_strings_kernel(1, &bprm->interp, bprm);
retval = copy_string_kernel(bprm->interp, bprm);
if (retval < 0)
return retval;
bprm->argc++;
if (i_arg) {
retval = copy_strings_kernel(1, &i_arg, bprm);
retval = copy_string_kernel(i_arg, bprm);
if (retval < 0)
return retval;
bprm->argc++;
}
retval = copy_strings_kernel(1, &i_name, bprm);
retval = copy_string_kernel(i_name, bprm);
if (retval)
return retval;
bprm->argc++;
Expand Down
13 changes: 6 additions & 7 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,24 +588,23 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
}

/*
* Like copy_strings, but get argv and its values from kernel memory.
* Copy and argument/environment string from the kernel to the processes stack.
*/
int copy_strings_kernel(int argc, const char *const *__argv,
struct linux_binprm *bprm)
int copy_string_kernel(const char *arg, struct linux_binprm *bprm)
{
int r;
mm_segment_t oldfs = get_fs();
struct user_arg_ptr argv = {
.ptr.native = (const char __user *const __user *)__argv,
.ptr.native = (const char __user *const __user *)&arg,
};

set_fs(KERNEL_DS);
r = copy_strings(argc, argv, bprm);
r = copy_strings(1, argv, bprm);
set_fs(oldfs);

return r;
}
EXPORT_SYMBOL(copy_strings_kernel);
EXPORT_SYMBOL(copy_string_kernel);

#ifdef CONFIG_MMU

Expand Down Expand Up @@ -1865,7 +1864,7 @@ static int __do_execve_file(int fd, struct filename *filename,
if (retval < 0)
goto out;

retval = copy_strings_kernel(1, &bprm->filename, bprm);
retval = copy_string_kernel(bprm->filename, bprm);
if (retval < 0)
goto out;

Expand Down
3 changes: 1 addition & 2 deletions include/linux/binfmts.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ extern int setup_arg_pages(struct linux_binprm * bprm,
extern int transfer_args_to_stack(struct linux_binprm *bprm,
unsigned long *sp_location);
extern int bprm_change_interp(const char *interp, struct linux_binprm *bprm);
extern int copy_strings_kernel(int argc, const char *const *argv,
struct linux_binprm *bprm);
int copy_string_kernel(const char *arg, struct linux_binprm *bprm);
extern void install_exec_creds(struct linux_binprm *bprm);
extern void set_binfmt(struct linux_binfmt *new);
extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
Expand Down

0 comments on commit 986db2d

Please sign in to comment.