Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7668711ybn; Mon, 30 Sep 2019 18:15:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNgQjs1cn4G09m4I3gOEozzuUdaQckMZ/naeT0Z1DCc7izUAOHjBX0eaE0XTzMRWepeaDB X-Received: by 2002:a50:ea8c:: with SMTP id d12mr22832340edo.87.1569892522193; Mon, 30 Sep 2019 18:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569892522; cv=none; d=google.com; s=arc-20160816; b=h2J85mbBcOZJM9mCuJzu2QGkbY0fYGWRpQ8GU2xSdM2RnA6K9VDY7vqmYTj36TOXjP 2uOgW9/HiyuL2Ezf2WmHA34xrMTqssJHa04xrpCSrC+tsh6amYGtc6NfNDq8rbtUZEcB QfrrJYqJC5qMjVkQXlm5RnEzX1XdcNmR9XaudYXq/QPUWc+fffdlk5PgwpMJghB75lMI bWkctLqW0vfufPRPBKmnKwFSpDPeTGzMr1xRdebRgCYboa2zrFYg0426NUantFmUVhnk BC+9Jh5egshkyQtCCzADuGqmczhTqP2gyig45GBrpyxDdvvCWURQYQX4XtCI6Sqc4u93 dpJw== 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=GZQdrPQ2IAS2wwduqAqVV9RkrEnD1uaFZGl5ZWQgxaU=; b=M/iVLStSqMKtdPrEqr+zCmopaKTeAyFZCMsbgp3eqkHoqXdwYWBDGQoN0ML8doTMyo KlC5NvURgjv3Uja/NFzzjf35eT3lGBfLwSEix/ixZXXsF2sQbDieQk0I2KUB2YvX19l4 ezGW2xGxYeqsH9hVFFvwrsuZDTDb/r95/5nv3hPOSJ3/gwFywd4xIQnhHPoxz4C0Otdq J/k5ESZQrWH9rXhEjK83et1J4Eb1tc4prQRl5Jg8GLZFDoEivzt9zsVMudngupLAOw/q /NSH5Xss4XaxvOC0BK96H4+KOgotJhlJR1qZ1+cJ42v5U13jbQVWVym18+r/VMCZXoZo kTzw== 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 fk4si8430533ejb.161.2019.09.30.18.14.57; Mon, 30 Sep 2019 18:15:22 -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 S1730309AbfJABMM (ORCPT + 99 others); Mon, 30 Sep 2019 21:12:12 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:38570 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726314AbfJABMM (ORCPT ); Mon, 30 Sep 2019 21:12:12 -0400 Received: from smtp2.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id E6989A18A5; Tue, 1 Oct 2019 03:12:09 +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 hp3Ahb8J0EYh; Tue, 1 Oct 2019 03:12:06 +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 v4 2/4] clone3: switch to copy_struct_from_user() Date: Tue, 1 Oct 2019 11:10:53 +1000 Message-Id: <20191001011055.19283-3-cyphar@cyphar.com> In-Reply-To: <20191001011055.19283-1-cyphar@cyphar.com> References: <20191001011055.19283-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. Reviewed-by: Kees Cook 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