Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6504628ybi; Wed, 29 May 2019 08:45:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGMUh8eA2sFHpeSO05eW47e8BwbGLKvbn0E4YpIxkylQFfsTLOQ+5j6SYaaTfrpidwDYfs X-Received: by 2002:a17:90a:3848:: with SMTP id l8mr13360658pjf.142.1559144758627; Wed, 29 May 2019 08:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559144758; cv=none; d=google.com; s=arc-20160816; b=Iw1M53MeyU21r3hQzP1tiM8/vOVV7UZo5hhGYnrI6xNj7HCZDHH/4zZzkhlllED9+y PsgBMz2Rc5VZEu8j9aMjWE8dUxxRlUyUXhePq6/zloTZjhszlhrhKHZcikqpgkdQYWf0 oKnGFJiOBcMgFLG6N24aB3db9MrHMhCynZXX4v5Wo6OOJnoG/LNuQD03lSYo6QlTgWV1 bZo+CZKQyEpysiou5SSaPIhTkpZaqzkuqgLyUdLajIGoEV0ce8Eavt/aKNysX7x2mmHv QwqXql5W1ieueorjb2VyJpuBKidv04tWlwWb+zz926geEjX1XGw90BRnt5yiYcWtnvPE +hpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:user-agent:organization:references:in-reply-to:date:cc :to:from:message-id; bh=Wl3jNB7araKGSzhuHsisBpxZQdGhDi0tBBEBx8rXBGs=; b=GffP2MknILHP6BsejBg/34pnmLbjj7nPoSIMuPRXnS4+vAds7PFakJGDdfp4ypiy/4 flFFvCHdCOErbB84HXygiv0/nlmFdQUKClH+/nS1ao4PVYz9nWph0i1Qi1fSexRHFA+w jsvUjMSCCBF4i+s7JroGD7jC2zSzm+rS3vAX+jr9P3jSXR1NndjazhBp4ZiNu3Pl/4MJ L7u9Tx7Jomdu0pSVvLxVB7/ODpSO/KkUqSzFMmoWiEaoKtEqLaA9pBlOox/lkxtLDXkA XerFbQVImzPf6G+q5hupwj0x3Axus92LYAn/FgX6/6jK1yTRxZv/tI/JJY+8EGIJMk2t kh0Q== 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 h1si26314954pgs.290.2019.05.29.08.45.41; Wed, 29 May 2019 08:45: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 S1726649AbfE2PnW (ORCPT + 99 others); Wed, 29 May 2019 11:43:22 -0400 Received: from ou.quest-ce.net ([195.154.187.82]:48665 "EHLO ou.quest-ce.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726097AbfE2PnW (ORCPT ); Wed, 29 May 2019 11:43:22 -0400 Received: from [2a01:e35:39f2:1220:9dd7:c176:119b:4c9d] (helo=opteyam2) by ou.quest-ce.net with esmtpsa (TLS1.1:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1hW0iU-000B3I-RX; Wed, 29 May 2019 17:42:15 +0200 Message-ID: <1058006e0df4b52b3e53c7b3202c04140899aeb5.camel@opteya.com> From: Yann Droneaud To: Christian Brauner , viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, jannh@google.com Cc: fweimer@redhat.com, oleg@redhat.com, arnd@arndb.de, dhowells@redhat.com, Pavel Emelyanov , Andrew Morton , Adrian Reber , Andrei Vagin , linux-api@vger.kernel.org Date: Wed, 29 May 2019 17:42:14 +0200 In-Reply-To: <20190529152237.10719-1-christian@brauner.io> References: <20190529152237.10719-1-christian@brauner.io> Organization: OPTEYA Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.2 (3.32.2-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a01:e35:39f2:1220:9dd7:c176:119b:4c9d X-SA-Exim-Mail-From: ydroneaud@opteya.com X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on ou.quest-ce.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.2 Subject: Re: [PATCH v1 1/2] fork: add clone3 X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on ou.quest-ce.net) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le mercredi 29 mai 2019 à 17:22 +0200, Christian Brauner a écrit : > This adds the clone3 system call. > > > diff --git a/kernel/fork.c b/kernel/fork.c > index b4cba953040a..6bc3e3d17150 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -2472,7 +2475,96 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, > unsigned long, tls) > #endif > { > - return _do_fork(clone_flags, newsp, 0, parent_tidptr, child_tidptr, tls); > + struct kernel_clone_args args = { > + .flags = clone_flags, > + .stack = newsp, > + .pidfd = parent_tidptr, > + .parent_tidptr = parent_tidptr, > + .tls = tls, > + .child_tidptr = child_tidptr, > + }; > + > + /* clone(CLONE_PIDFD) uses parent_tidptr to return a pidfd */ > + if ((clone_flags & CLONE_PIDFD) && (clone_flags & CLONE_PARENT_SETTID)) > + return -EINVAL; > + > + return _do_fork(&args); > +} > + > +static bool clone3_flags_valid(u64 flags) > +{ > + if (flags & CLONE_DETACHED) > + return false; > + > + if (flags & ~CLONE_MAX) > + return false; > + > + return true; > +} > + > +static int copy_clone_args_from_user(struct kernel_clone_args *kargs, > + struct clone_args __user *uargs, > + size_t size) > +{ > + struct clone_args args; > + > + if (unlikely(size > PAGE_SIZE)) > + return -E2BIG; > + > + if (unlikely(size < sizeof(struct clone_args))) > + 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; Should be -EINVAL: having something after the structure should be handled just like an invalid flags, while still allowing future userspace program to probe for support for newer feature. > + } > + > + size = sizeof(struct clone_args); > + } > + > + if (copy_from_user(&args, uargs, size)) > + return -EFAULT; > + > + if (!clone3_flags_valid(args.flags)) > + return -EINVAL; > + > + memset(kargs, 0, sizeof(*kargs)); > + > + kargs->flags = args.flags; > + kargs->child_tidptr = u64_to_user_ptr(args.child_tidptr); > + kargs->parent_tidptr = u64_to_user_ptr(args.parent_tidptr); > + kargs->pidfd = u64_to_user_ptr(args.pidfd); > + kargs->stack = args.stack; > + kargs->stack_size = args.stack_size; > + kargs->tls = args.tls; > + > + return 0; > +} > + > +SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size) > +{ > + int err; > + > + struct kernel_clone_args kargs; > + > + err = copy_clone_args_from_user(&kargs, uargs, size); > + if (err) > + return err; > + > + return _do_fork(&kargs); > } > #endif > Regards. -- Yann Droneaud OPTEYA