Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 247948
b: refs/heads/master
c: ba2d016
h: refs/heads/master
v: v3
  • Loading branch information
Oleg Nesterov committed Apr 9, 2011
1 parent e5634ee commit 2e473a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1d1dbf8135ab2f3603cc72e39e0f68784f453c39
refs/heads/master: ba2d01629d0d167598cfea85adc7926822bbfc45
42 changes: 30 additions & 12 deletions trunk/fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,15 @@ int bprm_mm_init(struct linux_binprm *bprm)
return err;
}

static const char __user *
get_user_arg_ptr(const char __user * const __user *argv, int nr)
struct user_arg_ptr {
const char __user *const __user *native;
};

static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
{
const char __user *ptr;

if (get_user(ptr, argv + nr))
if (get_user(ptr, argv.native + nr))
return ERR_PTR(-EFAULT);

return ptr;
Expand All @@ -412,11 +415,11 @@ get_user_arg_ptr(const char __user * const __user *argv, int nr)
/*
* count() counts the number of strings in array ARGV.
*/
static int count(const char __user * const __user * argv, int max)
static int count(struct user_arg_ptr argv, int max)
{
int i = 0;

if (argv != NULL) {
if (argv.native != NULL) {
for (;;) {
const char __user *p = get_user_arg_ptr(argv, i);

Expand All @@ -442,7 +445,7 @@ static int count(const char __user * const __user * argv, int max)
* processes's memory to the new process's stack. The call to get_user_pages()
* ensures the destination page is created and not swapped out.
*/
static int copy_strings(int argc, const char __user *const __user *argv,
static int copy_strings(int argc, struct user_arg_ptr argv,
struct linux_binprm *bprm)
{
struct page *kmapped_page = NULL;
Expand Down Expand Up @@ -533,14 +536,19 @@ static int copy_strings(int argc, const char __user *const __user *argv,
/*
* Like copy_strings, but get argv and its values from kernel memory.
*/
int copy_strings_kernel(int argc, const char *const *argv,
int copy_strings_kernel(int argc, const char *const *__argv,
struct linux_binprm *bprm)
{
int r;
mm_segment_t oldfs = get_fs();
struct user_arg_ptr argv = {
.native = (const char __user *const __user *)__argv,
};

set_fs(KERNEL_DS);
r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
r = copy_strings(argc, argv, bprm);
set_fs(oldfs);

return r;
}
EXPORT_SYMBOL(copy_strings_kernel);
Expand Down Expand Up @@ -1393,10 +1401,10 @@ EXPORT_SYMBOL(search_binary_handler);
/*
* sys_execve() executes a new program.
*/
int do_execve(const char * filename,
const char __user *const __user *argv,
const char __user *const __user *envp,
struct pt_regs * regs)
static int do_execve_common(const char *filename,
struct user_arg_ptr argv,
struct user_arg_ptr envp,
struct pt_regs *regs)
{
struct linux_binprm *bprm;
struct file *file;
Expand Down Expand Up @@ -1503,6 +1511,16 @@ int do_execve(const char * filename,
return retval;
}

int do_execve(const char *filename,
const char __user *const __user *__argv,
const char __user *const __user *__envp,
struct pt_regs *regs)
{
struct user_arg_ptr argv = { .native = __argv };
struct user_arg_ptr envp = { .native = __envp };
return do_execve_common(filename, argv, envp, regs);
}

void set_binfmt(struct linux_binfmt *new)
{
struct mm_struct *mm = current->mm;
Expand Down

0 comments on commit 2e473a9

Please sign in to comment.