Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1823564ybn; Thu, 26 Sep 2019 02:46:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhpf+cU+KRTI8gTmCQjDCIrVhs9b23htq76L6w39YNaQsXUI0+mRGeKnMLGMFan49calu5 X-Received: by 2002:aa7:d789:: with SMTP id s9mr2558181edq.62.1569491215394; Thu, 26 Sep 2019 02:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569491215; cv=none; d=google.com; s=arc-20160816; b=hWPx97uIVJ7QZzGMGVHPeM5yQnif7iwD/ueTlMY/mQfpW3kZlOW74gXKdQI5wKF+Un fnDkzWAdAMEQcTYFz/PCbAJ9fnZlZDtpEZ+vwVlCUUOfLYB1vKj4LLqR/60erSU3WbUc +kkNvFR1pn5YWafV2Ew2BOwZ5yWVtKPPxI7+VqzOYI1wbw3QZ7aWLhPtY60V0dNSORWP f1YKL0HbNLWmWm1MUnM//5rMKJOBWlaqSVoaXz4ohn0r8dYl3KzscYA3xQu6EP5Nb4lX CiCqsq6dvEXoiVkUc31/UnoXcya2V4YPSftJyjq63+J2rkNWF/z0SccB/YmlO0Eyst79 sdWQ== 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=VNDPPQ6eN1rCLMv27VTPWe90ZNajX5LmvXFAl0NG1qjBRPKZP9WRIlBh6WfWzuhIsb st9R9SmHE5ubMqumszEtpRAg4K8s7qg3l39VPhsGs8ThOGQBZWzUmhZ4mKuNW8PAIz5z XBSlAGWRlJN6HXUCPbHG+qoDIXjvIKrxocMV6ZmbESZABXdfbBBUJjWq9pbfzXg4trYb 8yldC329PbrI+7GCTIUgJjw61bAO+yp2TaIjlA7gKJ1ZgC4rBHvLbQYd69JcRgsImBwq FJAf7GKaJ1rxrmPGVga93ExYPsnbIXiGgbMIBIaTID4jldIGhp2BwfOGpQ3PBW2JthCk FQfw== 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 x25si975395edr.128.2019.09.26.02.46.32; Thu, 26 Sep 2019 02:46:55 -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 S2392194AbfIYRAS (ORCPT + 99 others); Wed, 25 Sep 2019 13:00:18 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:11662 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440084AbfIYRAR (ORCPT ); Wed, 25 Sep 2019 13:00:17 -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 5CD2AA1C4D; Wed, 25 Sep 2019 19:00:14 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id R9YPquIgVEuV; Wed, 25 Sep 2019 19:00:10 +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 v1 2/4] clone3: switch to copy_struct_from_user() Date: Wed, 25 Sep 2019 18:59:13 +0200 Message-Id: <20190925165915.8135-3-cyphar@cyphar.com> In-Reply-To: <20190925165915.8135-1-cyphar@cyphar.com> References: <20190925165915.8135-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