UPSTREAM: clone3: switch to copy_struct_from_user()
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. Change-Id: Ib09f7bf0cdfed775b606fb7f1698e12515cd0a6b 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>
This commit is contained in:
1 parent
6bff7e64cc
commit
a5ad964284
1 file changed
+7
-27
+7
-27
@@ -2561,40 +2561,20 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
|
|||||||
#ifdef __ARCH_WANT_SYS_CLONE3
|
#ifdef __ARCH_WANT_SYS_CLONE3
|
||||||
noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
|
noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
|
||||||
struct clone_args __user *uargs,
|
struct clone_args __user *uargs,
|
||||||
size_t size)
|
size_t usize)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
struct clone_args args;
|
struct clone_args args;
|
||||||
pid_t *kset_tid = kargs->set_tid;
|
pid_t *kset_tid = kargs->set_tid;
|
||||||
|
|
||||||
if (unlikely(size > PAGE_SIZE))
|
if (unlikely(usize > PAGE_SIZE))
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
|
if (unlikely(usize < CLONE_ARGS_SIZE_VER0))
|
||||||
if (unlikely(size < sizeof(struct clone_args)))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (unlikely(!access_ok(VERIFY_READ, uargs, size)))
|
err = copy_struct_from_user(&args, sizeof(args), uargs, usize);
|
||||||
return -EFAULT;
|
if (err)
|
||||||
|
return err;
|
||||||
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;
|
|
||||||
|
|
||||||
if (unlikely(args.set_tid_size > MAX_PID_NS_LEVEL))
|
if (unlikely(args.set_tid_size > MAX_PID_NS_LEVEL))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|||||||
Reference in new issue
Block a user