Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1143344ybe; Wed, 4 Sep 2019 13:22:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIfFzoB74R4wboutfOfryrJNdVYxAtOrJwKkbEvb3EQsf+gcJBVqjb+sQtaB8VYjKr59S2 X-Received: by 2002:a63:9245:: with SMTP id s5mr37417280pgn.123.1567628521840; Wed, 04 Sep 2019 13:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567628521; cv=none; d=google.com; s=arc-20160816; b=wBLE0CJzgQolLUC0alpQDWR0sM+hOo6r8Yf86HHhjZNEulsTRVt4YwrExzd3wMkBJl +H3aBRjhdnGzhEb5FZukTUdhkI3W5S6ob1kF1zV61NX4Oci1ZtyNkTJ4k8+ZbchTMJbk +gLDotm0IOg3dBx6KfuBHMW8PdrxzMRU9/CKRDf3uIkyUV9EOeEbX5zMKGXjkqQ09JF6 Af8vqZF1uSNcRYjeYH+qi2VnuiUdHClc3sq0I7TaE50KNe80cxv9R08HXPoWffj9sezQ 4XlL9Nuw0uMzibEvrJTlPTUD3MKeD/xqZzWTgdKa3swhGo6Vacfm+zjxq3HpRWy7r3Ym RKzg== 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=jdrCXfOp7BvrFbNRTMglOEA6Ko4QSvYWDwP0MIcy094=; b=khVY2Gq/DQqzPVmLkLrokeA0/uEW5VSj2zVn/g44uXkfses7c0NGacQpS+V6IsicjK 3hou/oWUFPFFtxRRaY2gwk7+ileXUBfiabbVZFRHP56IJTOGdQn075I7u89syCzHH/sD 9x+rRymX+SZXbjDylDKYlLp92i+O3s0VZ8cXJ62/O6ZU8ZcUQ3KlBkRyheXruBGWRqE/ bgk4vAVyMIbeb2tBqM2YSCDTcN/0B4y1cudf6F8pn1iAaMSX+R3ypt2/a2EFPEC70fbS ifFjEbtfK6FGdEJBuI3bRmKwJ1tWcr+Ci8OQPvBisX0a9MlnSMymZTgFz5agsLqzCYm3 6rDQ== 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 c6si77030pjr.77.2019.09.04.13.21.45; Wed, 04 Sep 2019 13:22:01 -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 S1730299AbfIDUUr (ORCPT + 99 others); Wed, 4 Sep 2019 16:20:47 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:62092 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730214AbfIDUUq (ORCPT ); Wed, 4 Sep 2019 16:20:46 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2: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 50DC1A1169; Wed, 4 Sep 2019 22:20:41 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id NLDvBaFlidIu; Wed, 4 Sep 2019 22:20:38 +0200 (CEST) From: Aleksa Sarai To: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Christian Brauner Cc: Aleksa Sarai , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Aleksa Sarai , Linus Torvalds , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: [PATCH v12 02/12] clone3: switch to copy_struct_from_user() Date: Thu, 5 Sep 2019 06:19:23 +1000 Message-Id: <20190904201933.10736-3-cyphar@cyphar.com> In-Reply-To: <20190904201933.10736-1-cyphar@cyphar.com> References: <20190904201933.10736-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 takes advantage of the (very minor) efficiency improvements in copy_struct_from_user() -- that the memchr_inv() check is done on a buffer instead of one-at-at-time with get_user(). Additionally, explicitly define CLONE_ARGS_SIZE_VER0 to match the other users of the struct-extension pattern. Cc: Christian Brauner Signed-off-by: Aleksa Sarai --- include/uapi/linux/sched.h | 2 ++ kernel/fork.c | 34 ++++++---------------------------- 2 files changed, 8 insertions(+), 28 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 2852d0e76ea3..70c10d9b429a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2528,39 +2528,17 @@ 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)) - 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; *kargs = (struct kernel_clone_args){ .flags = args.flags, -- 2.23.0