Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2564760imu; Mon, 19 Nov 2018 02:35:59 -0800 (PST) X-Google-Smtp-Source: AJdET5cY9VskHV1Zm79utdwA6G+JvcYUEJasXweTFDOf0uHSoE6wH8oCqtIwU7bzlc3F17NZ+rKo X-Received: by 2002:a63:a401:: with SMTP id c1mr19698664pgf.403.1542623759769; Mon, 19 Nov 2018 02:35:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542623759; cv=none; d=google.com; s=arc-20160816; b=ahykbwtU++7fLckeQFHoZ+eWtf+Rr5pUC/IMtye0IACr6j8ExZ8qPAFBcqKrHfL+mk MG1EvWGiQx65LJpxpbop4L2vZbR6uwCNQBxEgSb4CGbABlY91XHyJffpVLFmpMb16NmW 77P3quMrMmaaibmsJHQ8c1/Kzx4VNiaVAQJx1WbFArVZy3Lb6pxvUbVpJISoQPpj2Nm6 l63fc2oj/EStMNwYCdRL6qMh/K3fIzruqHxRxmfiBxXfsowog3UKbpwwPJ4GokjsJgyY 0C6lrFTVau4csoEHkbyH+HIkwdJdmGA64XLrSB6QmmmeB3q0jtmEMvT5NlnUSjCGSVRu lzLA== 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 :dkim-signature; bh=Pfk17pduLrrmmy1RCURdhpMiDwOWVPCBsvdRFX8G//Y=; b=HNbWQc1yUH3oJAT2QkU6Up0sJmIKougntCAm+291zxVKd16WI072aqbjr8JFT7VGkA aXR1WHm6N1YKCeVlVNCrH7/aD5cwIliVgnkkbTZJOr9GPeNABOpkrNCrihw6DgxrfdMT u/aQtTX57jyCN3Z6/NQJMs6l32sIytkLiRhelPEM/Lq+tDWN2OUuMM8j6gAIRCKOncG0 t1Pvjnm4zrAnUpQA+LjQeRLc/5Z+hpSSDL5MEiAFL14GDwA2J+tT9PVeBRdN79Jd8WX6 sNPK9PLCoJh+mfVGF+PHsyF77B+B+Ue0k9ZQaWeb7jj1qSfBMfO0/7cxUZgBxFqNhziB 0UVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=BBwNgxcS; 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 o28si36520522pgm.238.2018.11.19.02.35.45; Mon, 19 Nov 2018 02:35:59 -0800 (PST) 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; dkim=pass header.i=@brauner.io header.s=google header.b=BBwNgxcS; 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 S1727974AbeKSU4y (ORCPT + 99 others); Mon, 19 Nov 2018 15:56:54 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40750 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727947AbeKSU4x (ORCPT ); Mon, 19 Nov 2018 15:56:53 -0500 Received: by mail-pg1-f193.google.com with SMTP id z10so13659674pgp.7 for ; Mon, 19 Nov 2018 02:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pfk17pduLrrmmy1RCURdhpMiDwOWVPCBsvdRFX8G//Y=; b=BBwNgxcS+t4Ebk4vrZvTFSNs9/zXdIwZlcPQhEpiz45Wc4gH408AAAxSOHtCliu4xH SXAF2XL0zGSwoyrnyXuQ7QYugfPVeegiZzGw46Az5kSeVVFHgIhy8JDEWYCyEjXrBb0N VKsXtzt9w3e1KjAeF3Q5Ztlc27KJ2PGxQLG49xV4ksZiU96hQzaf9unC3scauJShPhdp NITbxwTpqa624dT7LpI10mH8/TtxKKYDFwBk0uzCbMKxAHSt0UxPLlxrtSYo9BC+d+gd RqcEuFfG0cF7dGGKFhBZHiYA1qqQWlHhHnVRxGLTUXtveEa1rJdhE2tuNBO7V6LNVOHb 0sFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pfk17pduLrrmmy1RCURdhpMiDwOWVPCBsvdRFX8G//Y=; b=tUmy0VrmjYD2v497BZqaYBIlwSQrwRugZCLEsuLcWCrrGaeL77uHM91x8E4jViuOnJ kwLfJQnVyWD3deCg0w3VAV76hv5pyHn0VtdGhhEjY2Ge4+1WJAJT/yYw/mszy71Lsiev FJGFBce0FuMXXvIeVhdL8UaaLf1AxKXpVOLrRMMPLMzItSFKN8Kw7BmVnkPftk66Ppeg n5v56dzqVV2BAyEj/vyETrYKVaOdf4IpNpdxOXSnzxPlbym5HHo6Bpj+wB72AjdgWllL R5BYY0RcLjFxP+pfohCMH+rMfeRgXwAPSoIpfrMYx7Kdb8pVB43N5SwJqc33QnkanCnq jh4Q== X-Gm-Message-State: AGRZ1gKfTY84BTA2hWHPWOwEQbK+pjmT7/+VIP2godnEuupnejidZ/hN vWIkQdTVxt5bwh7n62OxdeYlvQ== X-Received: by 2002:a62:ed09:: with SMTP id u9-v6mr21926577pfh.188.1542623620044; Mon, 19 Nov 2018 02:33:40 -0800 (PST) Received: from localhost.localdomain ([2404:4404:133a:4500:9d11:de0b:446c:8485]) by smtp.gmail.com with ESMTPSA id d21sm32958139pgv.37.2018.11.19.02.33.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 02:33:39 -0800 (PST) From: Christian Brauner To: ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: serge@hallyn.com, jannh@google.com, luto@kernel.org, akpm@linux-foundation.org, oleg@redhat.com, cyphar@cyphar.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, dancol@google.com, timmurray@google.com, linux-man@vger.kernel.org, Christian Brauner , Kees Cook Subject: [PATCH v1 1/2] proc: get process file descriptor from /proc/ Date: Mon, 19 Nov 2018 11:32:38 +0100 Message-Id: <20181119103241.5229-2-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119103241.5229-1-christian@brauner.io> References: <20181119103241.5229-1-christian@brauner.io> 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 With this patch an open() call on /proc/ will give userspace a handle to struct pid of the process associated with /proc/. This allows to maintain a stable handle on a process. I have been discussing various approaches extensively during technical conferences this year culminating in a long argument with Eric at Linux Plumbers. The general consensus was that having a handle on a process should be something that is very simple and easy to maintain with the option of being extensible via a more advanced api if the need arises. I believe that this patch is the most simple, dumb, and therefore maintainable solution. [1]: https://lkml.org/lkml/2018/10/30/118 Cc: "Eric W. Biederman" Cc: Serge Hallyn Cc: Jann Horn Cc: Kees Cook Cc: Andy Lutomirsky Cc: Andrew Morton Cc: Oleg Nesterov Cc: Aleksa Sarai Cc: Al Viro Signed-off-by: Christian Brauner --- Changelog: v1: - remove ioctl() to signal processes and replace with a dedicated syscall in the next patch --- fs/proc/base.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index ce3465479447..6365a4fea314 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3032,10 +3032,27 @@ static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx) tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff)); } +static int proc_tgid_open(struct inode *inode, struct file *file) +{ + /* grab reference to struct pid and stash the pointer away */ + file->private_data = get_pid(proc_pid(inode)); + return 0; +} + +static int proc_tgid_release(struct inode *inode, struct file *file) +{ + struct pid *pid = file->private_data; + /* drop reference to struct pid */ + put_pid(pid); + return 0; +} + static const struct file_operations proc_tgid_base_operations = { + .open = proc_tgid_open, .read = generic_read_dir, .iterate_shared = proc_tgid_base_readdir, .llseek = generic_file_llseek, + .release = proc_tgid_release, }; static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) -- 2.19.1