Skip to content

Commit ba2d016

Browse files
committed
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>
1 parent 1d1dbf8 commit ba2d016

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

‎fs/exec.c‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,15 @@ int bprm_mm_init(struct linux_binprm *bprm)
398398
return err;
399399
}
400400

401-
static const char __user *
402-
get_user_arg_ptr(const char __user * const __user *argv, int nr)
401+
struct user_arg_ptr {
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)
403406
{
404407
const char __user *ptr;
405408

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

409412
return ptr;
@@ -412,11 +415,11 @@ get_user_arg_ptr(const char __user * const __user *argv, int nr)
412415
/*
413416
* count() counts the number of strings in array ARGV.
414417
*/
415-
static int count(const char __user * const __user * argv, int max)
418+
static int count(struct user_arg_ptr argv, int max)
416419
{
417420
int i = 0;
418421

419-
if (argv != NULL) {
422+
if (argv.native != NULL) {
420423
for (;;) {
421424
const char __user *p = get_user_arg_ptr(argv, i);
422425

@@ -442,7 +445,7 @@ static int count(const char __user * const __user * argv, int max)
442445
* processes's memory to the new process's stack. The call to get_user_pages()
443446
* ensures the destination page is created and not swapped out.
444447
*/
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,
446449
struct linux_binprm *bprm)
447450
{
448451
struct page *kmapped_page = NULL;
@@ -533,14 +536,19 @@ static int copy_strings(int argc, const char __user *const __user *argv,
533536
/*
534537
* Like copy_strings, but get argv and its values from kernel memory.
535538
*/
536-
int copy_strings_kernel(int argc, const char *const *argv,
539+
int copy_strings_kernel(int argc, const char *const *__argv,
537540
struct linux_binprm *bprm)
538541
{
539542
int r;
540543
mm_segment_t oldfs = get_fs();
544+
struct user_arg_ptr argv = {
545+
.native = (const char __user *const __user *)__argv,
546+
};
547+
541548
set_fs(KERNEL_DS);
542-
r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
549+
r = copy_strings(argc, argv, bprm);
543550
set_fs(oldfs);
551+
544552
return r;
545553
}
546554
EXPORT_SYMBOL(copy_strings_kernel);
@@ -1393,10 +1401,10 @@ EXPORT_SYMBOL(search_binary_handler);
13931401
/*
13941402
* sys_execve() executes a new program.
13951403
*/
1396-
int do_execve(const char * filename,
1397-
const char __user *const __user *argv,
1398-
const char __user *const __user *envp,
1399-
struct pt_regs * regs)
1404+
static int do_execve_common(const char *filename,
1405+
struct user_arg_ptr argv,
1406+
struct user_arg_ptr envp,
1407+
struct pt_regs *regs)
14001408
{
14011409
struct linux_binprm *bprm;
14021410
struct file *file;
@@ -1503,6 +1511,16 @@ int do_execve(const char * filename,
15031511
return retval;
15041512
}
15051513

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+
15061524
void set_binfmt(struct linux_binfmt *new)
15071525
{
15081526
struct mm_struct *mm = current->mm;

0 commit comments

Comments
 (0)