diff options
author | Oleg Nesterov <oleg@redhat.com> | 2011-03-06 12:02:37 -0500 |
---|---|---|
committer | Oleg Nesterov <oleg@redhat.com> | 2011-04-09 09:53:53 -0400 |
commit | ba2d01629d0d167598cfea85adc7926822bbfc45 (patch) | |
tree | 703a3f297df7cb4c0317504a58121f9958c0d708 /fs/exec.c | |
parent | 1d1dbf8135ab2f3603cc72e39e0f68784f453c39 (diff) |
exec: introduce struct user_arg_ptr
No functional changes, preparation.
Introduce struct user_arg_ptr, change do_execve() paths to use it
instead of "char __user * const __user *argv".
This makes the argv/envp arguments opaque, we are ready to handle the
compat case which needs argv pointing to compat_uptr_t.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Tested-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Diffstat (limited to 'fs/exec.c')
-rw-r--r-- | fs/exec.c | 42 |
1 files changed, 30 insertions, 12 deletions
@@ -398,12 +398,15 @@ err: | |||
398 | return err; | 398 | return err; |
399 | } | 399 | } |
400 | 400 | ||
401 | static const char __user * | 401 | struct user_arg_ptr { |
402 | get_user_arg_ptr(const char __user * const __user *argv, int nr) | 402 | const char __user *const __user *native; |
403 | }; | ||
404 | |||
405 | static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr) | ||
403 | { | 406 | { |
404 | const char __user *ptr; | 407 | const char __user *ptr; |
405 | 408 | ||
406 | if (get_user(ptr, argv + nr)) | 409 | if (get_user(ptr, argv.native + nr)) |
407 | return ERR_PTR(-EFAULT); | 410 | return ERR_PTR(-EFAULT); |
408 | 411 | ||
409 | return ptr; | 412 | return ptr; |
@@ -412,11 +415,11 @@ get_user_arg_ptr(const char __user * const __user *argv, int nr) | |||
412 | /* | 415 | /* |
413 | * count() counts the number of strings in array ARGV. | 416 | * count() counts the number of strings in array ARGV. |
414 | */ | 417 | */ |
415 | static int count(const char __user * const __user * argv, int max) | 418 | static int count(struct user_arg_ptr argv, int max) |
416 | { | 419 | { |
417 | int i = 0; | 420 | int i = 0; |
418 | 421 | ||
419 | if (argv != NULL) { | 422 | if (argv.native != NULL) { |
420 | for (;;) { | 423 | for (;;) { |
421 | const char __user *p = get_user_arg_ptr(argv, i); | 424 | const char __user *p = get_user_arg_ptr(argv, i); |
422 | 425 | ||
@@ -442,7 +445,7 @@ static int count(const char __user * const __user * argv, int max) | |||
442 | * processes's memory to the new process's stack. The call to get_user_pages() | 445 | * processes's memory to the new process's stack. The call to get_user_pages() |
443 | * ensures the destination page is created and not swapped out. | 446 | * ensures the destination page is created and not swapped out. |
444 | */ | 447 | */ |
445 | static int copy_strings(int argc, const char __user *const __user *argv, | 448 | static int copy_strings(int argc, struct user_arg_ptr argv, |
446 | struct linux_binprm *bprm) | 449 | struct linux_binprm *bprm) |
447 | { | 450 | { |
448 | struct page *kmapped_page = NULL; | 451 | struct page *kmapped_page = NULL; |
@@ -533,14 +536,19 @@ out: | |||
533 | /* | 536 | /* |
534 | * Like copy_strings, but get argv and its values from kernel memory. | 537 | * Like copy_strings, but get argv and its values from kernel memory. |
535 | */ | 538 | */ |
536 | int copy_strings_kernel(int argc, const char *const *argv, | 539 | int copy_strings_kernel(int argc, const char *const *__argv, |
537 | struct linux_binprm *bprm) | 540 | struct linux_binprm *bprm) |
538 | { | 541 | { |
539 | int r; | 542 | int r; |
540 | mm_segment_t oldfs = get_fs(); | 543 | mm_segment_t oldfs = get_fs(); |
544 | struct user_arg_ptr argv = { | ||
545 | .native = (const char __user *const __user *)__argv, | ||
546 | }; | ||
547 | |||
541 | set_fs(KERNEL_DS); | 548 | set_fs(KERNEL_DS); |
542 | r = copy_strings(argc, (const char __user *const __user *)argv, bprm); | 549 | r = copy_strings(argc, argv, bprm); |
543 | set_fs(oldfs); | 550 | set_fs(oldfs); |
551 | |||
544 | return r; | 552 | return r; |
545 | } | 553 | } |
546 | EXPORT_SYMBOL(copy_strings_kernel); | 554 | EXPORT_SYMBOL(copy_strings_kernel); |
@@ -1393,10 +1401,10 @@ EXPORT_SYMBOL(search_binary_handler); | |||
1393 | /* | 1401 | /* |
1394 | * sys_execve() executes a new program. | 1402 | * sys_execve() executes a new program. |
1395 | */ | 1403 | */ |
1396 | int do_execve(const char * filename, | 1404 | static int do_execve_common(const char *filename, |
1397 | const char __user *const __user *argv, | 1405 | struct user_arg_ptr argv, |
1398 | const char __user *const __user *envp, | 1406 | struct user_arg_ptr envp, |
1399 | struct pt_regs * regs) | 1407 | struct pt_regs *regs) |
1400 | { | 1408 | { |
1401 | struct linux_binprm *bprm; | 1409 | struct linux_binprm *bprm; |
1402 | struct file *file; | 1410 | struct file *file; |
@@ -1503,6 +1511,16 @@ out_ret: | |||
1503 | return retval; | 1511 | return retval; |
1504 | } | 1512 | } |
1505 | 1513 | ||
1514 | int do_execve(const char *filename, | ||
1515 | const char __user *const __user *__argv, | ||
1516 | const char __user *const __user *__envp, | ||
1517 | struct pt_regs *regs) | ||
1518 | { | ||
1519 | struct user_arg_ptr argv = { .native = __argv }; | ||
1520 | struct user_arg_ptr envp = { .native = __envp }; | ||
1521 | return do_execve_common(filename, argv, envp, regs); | ||
1522 | } | ||
1523 | |||
1506 | void set_binfmt(struct linux_binfmt *new) | 1524 | void set_binfmt(struct linux_binfmt *new) |
1507 | { | 1525 | { |
1508 | struct mm_struct *mm = current->mm; | 1526 | struct mm_struct *mm = current->mm; |