Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1893822ybn; Thu, 26 Sep 2019 03:56:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrfmqCUxgVj6YNmkj6EFG1SZpqBMEEnW+NKEWOPYxxAXOiRRJGgSZk243Ntr4yc3BSKwGi X-Received: by 2002:a17:906:3644:: with SMTP id r4mr2479161ejb.92.1569495385436; Thu, 26 Sep 2019 03:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569495385; cv=none; d=google.com; s=arc-20160816; b=Y/xlSsL3uBZVfH/XYi6wUkv7SlRCD1UH5aRCQiQxb2UaPNjiRi1yxgUre70Vstd7fd 4ShVBG2/HfGX1flLsZHmETBERo1N23DxlCsqBEM61EqoF/6vYYSdNQbrhTiyL49lTtX2 HVLp7itwoM0E5c/jE6rFyUkUbjQnYp4kYh5+2GSuq97C10DXnibjB+GqX43gI1ENBMfD 5GLPzoY9XnQlO55QpgRW9W4bP6TwovVez9SePhggDTrmqt7X7qOwlf0JXyFZTH6PRbRo pKc4zNY10YylXOLD/0d3sGUa+rMHjhGxRmGWkinjvIJEHyPrLHihxhzx3xhN2OshDSlL wVOQ== 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=04zVYCv++sdzGVwW+3FS500xTQpyo9LweCOsD34X1bo=; b=pztyESEcTd+t7ylzOt3xFApnqem0UfdSFVBGNEX5XJLWOnWaqz8g8u7pX+AhoHZU5L NVLoyWrgN66hFwdGgkyuXIEqs9T4fOcZWJU6rc9yu5xIcf/s7l9dZtig7Vmk0Tb0OVE1 HMtg8qpDKIx2SpHxOfmpHEEqFtecxF3bhcKCmpqj1oHKYKHNSWN+wLWv8P19lm/MPU8i eMr0cLOHR1LWG4KWCFgsPqAUBj4fTP/EUh5Ci6NV4dsTgyIFG/g67wtmvuaxgsoZFs5j 8yzl7Yi62SG2HjwdU+onUYniJqvzxjzc/B6ZRQ4sbZnHFikSo+vEx4Y/6g27MAOwb5+M PJ5g== 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 w43si1113755edd.332.2019.09.26.03.56.02; Thu, 26 Sep 2019 03:56:25 -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 S1730905AbfIYXEl (ORCPT + 99 others); Wed, 25 Sep 2019 19:04:41 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:27472 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbfIYXEk (ORCPT ); Wed, 25 Sep 2019 19:04:40 -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 D1142A17F3; Thu, 26 Sep 2019 01:04:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.240]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id jdqja7C_Y_pA; Thu, 26 Sep 2019 01:04:35 +0200 (CEST) From: Aleksa Sarai To: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner 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 v2 2/4] clone3: switch to copy_struct_from_user() Date: Thu, 26 Sep 2019 01:03:30 +0200 Message-Id: <20190925230332.18690-3-cyphar@cyphar.com> In-Reply-To: <20190925230332.18690-1-cyphar@cyphar.com> References: <20190925230332.18690-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 541fd805fb88..a86e3841ee4e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2530,39 +2530,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