Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7441969ybn; Mon, 30 Sep 2019 14:01:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYrfGc5ko3PMHDA9TXmhuEn1fGB8eTt3/TdS623HDX0gIHYllgIt6GmWhilsMZf8LQnvh4 X-Received: by 2002:a17:906:11c3:: with SMTP id o3mr21527813eja.297.1569877318119; Mon, 30 Sep 2019 14:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569877318; cv=none; d=google.com; s=arc-20160816; b=nyhS9HcXg3tIWnarqzblo6ZKH5s6WctWQ/6+UwZSpkbcYg6QY5JP/5XdeNabbaP97t 2B8dH66hxXKIkRpF1iwI5OSwiEoXC99Fl/CDXR5X8FmmONh+s7YuWPkXMuFpn8zjJQ8j +JOr6QEwsuL9jsTqOOzoFP5WYFVzPsLTYvMs21azM2YW9ytPIMuSB5xCUFwycMRSHElJ nWZ6eNYLYpdOdannZF9BTb0qUbct+xk45HB7XHKgTBvfYlzQwlPygYFvjzxmKuFF4EHj nPgNLlhYYVRylyPzi/b/vcm+E/d2PcmJjz5z4vG8Z52Q6rn8sr7NByQ+3/pkgHpK+6I7 f+Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YgRuxtvhLYlTbiZ9fnFonmw0U98161311IvRKHH54qg=; b=Xlg4cplFxCKUeNtgE/FlHx/RfUEg4cX+qC4Ixd/wus1StFAlTAMLVR1F9ZZp3CfEIg bF0Ewx3buc3MO58a3V/FsxV8R/pvt1cnN28kuX+HmYSY648HxOpdVYBhoMyvvwDV3oG7 bxXunp1HeSbHfTSgnVyXF9zTcIsRxjnUnPS3qI4STOScVD5Oo4FT0p225V5bazHDWexu Xiq/wgR+oeFz3HV9thJUTHNmSQZi695sNj0XMYfpQmF2GVHkoQKgEbVt8Rhw6wZ/iQ8+ GHJ8cKtiQIc87+KmzgW+UUBptTxF8HZvyM20Ze+r3jxo8/p/zdxkTOjQRFr1wOrmNslB Ao7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k24si7651324ejz.284.2019.09.30.14.01.31; Mon, 30 Sep 2019 14:01:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731833AbfI3U6O (ORCPT + 99 others); Mon, 30 Sep 2019 16:58:14 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:54494 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbfI3U6O (ORCPT ); Mon, 30 Sep 2019 16:58:14 -0400 Received: from smtp2.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 54DF3A19C6; Mon, 30 Sep 2019 20:28:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id URdz_XAhm__8; Mon, 30 Sep 2019 20:28:51 +0200 (CEST) From: Aleksa Sarai To: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Kees Cook Cc: Aleksa Sarai , Rasmus Villemoes , Al Viro , Linus Torvalds , libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] clone3: switch to copy_struct_from_user() Date: Tue, 1 Oct 2019 04:28:08 +1000 Message-Id: <20190930182810.6090-3-cyphar@cyphar.com> In-Reply-To: <20190930182810.6090-1-cyphar@cyphar.com> References: <20190930182810.6090-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/uapi/linux/sched.h | 2 ++ kernel/fork.c | 34 +++++++--------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index b3105ac1381a..0945805982b4 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -47,6 +47,8 @@ struct clone_args { __aligned_u64 tls; }; +#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */ + /* * Scheduling policies */ diff --git a/kernel/fork.c b/kernel/fork.c index f9572f416126..2ef529869c64 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -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 -- 2.23.0