Skip to content

Commit

Permalink
clone3: switch to copy_struct_from_user()
Browse files Browse the repository at this point in the history
Switch clone3() syscall from it's own copying struct clone_args from
userspace to the new dedicated copy_struct_from_user() helper.

The change is very straightforward, and helps unify the syscall
interface for struct-from-userspace syscalls. Additionally, explicitly
define CLONE_ARGS_SIZE_VER0 to match the other users of the
struct-extension pattern.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
[christian.brauner@ubuntu.com: improve commit message]
Link: https://lore.kernel.org/r/20191001011055.19283-3-cyphar@cyphar.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Aleksa Sarai authored and Christian Brauner committed Oct 1, 2019
1 parent f5a1a53 commit f14c234
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
2 changes: 2 additions & 0 deletions include/uapi/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct clone_args {
__aligned_u64 tls;
};

#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */

/*
* Scheduling policies
*/
Expand Down
34 changes: 7 additions & 27 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -2525,39 +2525,19 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
#ifdef __ARCH_WANT_SYS_CLONE3
noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
struct clone_args __user *uargs,
size_t size)
size_t usize)
{
int err;
struct clone_args args;

if (unlikely(size > PAGE_SIZE))
if (unlikely(usize > PAGE_SIZE))
return -E2BIG;

if (unlikely(size < sizeof(struct clone_args)))
if (unlikely(usize < CLONE_ARGS_SIZE_VER0))
return -EINVAL;

if (unlikely(!access_ok(uargs, size)))
return -EFAULT;

if (size > sizeof(struct clone_args)) {
unsigned char __user *addr;
unsigned char __user *end;
unsigned char val;

addr = (void __user *)uargs + sizeof(struct clone_args);
end = (void __user *)uargs + size;

for (; addr < end; addr++) {
if (get_user(val, addr))
return -EFAULT;
if (val)
return -E2BIG;
}

size = sizeof(struct clone_args);
}

if (copy_from_user(&args, uargs, size))
return -EFAULT;
err = copy_struct_from_user(&args, sizeof(args), uargs, usize);
if (err)
return err;

/*
* Verify that higher 32bits of exit_signal are unset and that
Expand Down

0 comments on commit f14c234

Please sign in to comment.