Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp641792yba; Wed, 15 May 2019 07:32:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDTt/Sn9w8FHBDCaSBwrM0HLg3O83qlXCv8d0+jhftvgn+Cj3fWWQ9qP9MYce5AWOkfp1I X-Received: by 2002:a63:1d02:: with SMTP id d2mr45109542pgd.26.1557930725346; Wed, 15 May 2019 07:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557930725; cv=none; d=google.com; s=arc-20160816; b=QbyC6b5cbSwXAp6FiBsBKPiSattPqCnxjSmqdzuP7rbnRjDZIksVD4qnuP8tN7gCvc jBZIlSAROYq9MrDYq36bXm63XJDmghPaTChdNR0MOk8PYKDrd/wsTqHgQ8s3/A/x7mS1 1YmVCBTCMLOjWwpf1pAf808B5wOVS2sZilAyrizVboHshJE3Xp8VgFVuIt3CE3hIHiyc ksKkJRfkwl3K8hQ3G+Fs7QtM1j0qKiBj0GOiGBD3P+glEMV8Sx8c0Alq2YBd5vzT+aNQ J4SKOLEP/dc+ValDZrpxhBxFtFFkkABG15RVnD4uQ5bjXBmYBlgItrP9tAb3q8Z6Q1MR 2PfA== 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=A3ecQvg95X0HZ7FdmSDC67MJ6bQys1r8rWeHPyUBss0=; b=rdIPhL2iFUSRInpz+wFLREfkrrdCIbT1o5I+gwBqp5i8uZZsuPMxcWHwO9YbOzEOzU 4VDsVkr6G7JL4E51lWwLyJNlvXjqw+doq5HvRbD5vhO6AsTb/4dcak6m19Ll5hSKJ+vn puY2B1/pc2llgmoXJ1A5gxHMxHpw825HAYRwkXxCm6VkgC/eeFKk2evKosSetkIUmkTd AqUz1rgz/DDrOQ3ixqDapFQDQkSoshQFeQ8vNlZjCLgLYfa4yEo9zmBzArpXrB2rcwSV stYeMLyY/lz8N5yzqXt9P0hT3Ftok1tD4vwKY0EHIOXtqtj+Uzudum/2e4YqHzWsMSg4 mmiA== 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 b5si1907946pgw.359.2019.05.15.07.31.50; Wed, 15 May 2019 07:32:05 -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 S1728203AbfEOO3R (ORCPT + 99 others); Wed, 15 May 2019 10:29:17 -0400 Received: from ou.quest-ce.net ([195.154.187.82]:38486 "EHLO ou.quest-ce.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfEOO3Q (ORCPT ); Wed, 15 May 2019 10:29:16 -0400 X-Greylist: delayed 1655 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 May 2019 10:29:13 EDT Received: from [2a01:e35:39f2:1220:2452:dd6c:fe2f:be2c] (helo=opteyam2) by ou.quest-ce.net with esmtpsa (TLS1.1:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1hQuSD-0003J6-UX; Wed, 15 May 2019 16:00:22 +0200 Message-ID: <4c5ae46657e1931a832def5645db61eb0bf1accd.camel@opteya.com> From: Yann Droneaud To: Christian Brauner , jannh@google.com, oleg@redhat.com, viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, arnd@arndb.de, dhowells@redhat.com Cc: akpm@linux-foundation.org, cyphar@cyphar.com, ebiederm@xmission.com, elena.reshetova@intel.com, keescook@chromium.org, luto@amacapital.net, luto@kernel.org, tglx@linutronix.de, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@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, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Wed, 15 May 2019 16:00:20 +0200 In-Reply-To: <20190515100400.3450-1-christian@brauner.io> References: <20190515100400.3450-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:2452:dd6c:fe2f:be2c 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 1/2] pid: add pidfd_open() 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 Hi, Le mercredi 15 mai 2019 à 12:03 +0200, Christian Brauner a écrit : > > diff --git a/kernel/pid.c b/kernel/pid.c > index 20881598bdfa..237d18d6ecb8 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -451,6 +452,53 @@ struct pid *find_ge_pid(int nr, struct > pid_namespace *ns) > return idr_get_next(&ns->idr, &nr); > } > > +/** > + * pidfd_open() - Open new pid file descriptor. > + * > + * @pid: pid for which to retrieve a pidfd > + * @flags: flags to pass > + * > + * This creates a new pid file descriptor with the O_CLOEXEC flag set for > + * the process identified by @pid. Currently, the process identified by > + * @pid must be a thread-group leader. This restriction currently exists > + * for all aspects of pidfds including pidfd creation (CLONE_PIDFD cannot > + * be used with CLONE_THREAD) and pidfd polling (only supports thread group > + * leaders). > + * Would it be possible to create file descriptor with "restricted" operation ? - O_RDONLY: waiting for process completion allowed (for example) - O_WRONLY: sending process signal allowed For example, a process could send over a Unix socket a process a pidfd, allowing this to only wait for completion, but not sending signal ? I see the permission check is not done in pidfd_open(), so what prevent a user from sending a signal to another user owned process ? If it's in pidfd_send_signal(), then, passing the socket through SCM_RIGHT won't be useful if the target process is not owned by the same user, or root. > + * Return: On success, a cloexec pidfd is returned. > + * On error, a negative errno number will be returned. > + */ > +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) > +{ > + int fd, ret; > + struct pid *p; > + struct task_struct *tsk; > + > + if (flags) > + return -EINVAL; > + > + if (pid <= 0) > + return -EINVAL; > + > + p = find_get_pid(pid); > + if (!p) > + return -ESRCH; > + > + rcu_read_lock(); > + tsk = pid_task(p, PIDTYPE_PID); > + if (!tsk) > + ret = -ESRCH; > + else if (unlikely(!thread_group_leader(tsk))) > + ret = -EINVAL; > + else > + ret = 0; > + rcu_read_unlock(); > + > + fd = ret ?: pidfd_create(p); > + put_pid(p); > + return fd; > +} > + > void __init pid_idr_init(void) > { > /* Verify no one has done anything silly: */ Regards. -- Yann Droneaud OPTEYA