From: Christian Brauner <christian@brauner.io> 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 <christian@brauner.io>, Kees Cook <keescook@chromium.org> Subject: [PATCH v1 1/2] proc: get process file descriptor from /proc/<pid> Date: Mon, 19 Nov 2018 11:32:38 +0100 [thread overview] Message-ID: <20181119103241.5229-2-christian@brauner.io> (raw) In-Reply-To: <20181119103241.5229-1-christian@brauner.io> With this patch an open() call on /proc/<pid> will give userspace a handle to struct pid of the process associated with /proc/<pid>. 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" <ebiederm@xmission.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Jann Horn <jannh@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirsky <luto@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Aleksa Sarai <cyphar@cyphar.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Christian Brauner <christian@brauner.io> --- 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
next prev parent reply other threads:[~2018-11-19 10:33 UTC|newest] Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-11-19 10:32 [PATCH v1 0/2] proc: allow signaling processes via file descriptors Christian Brauner 2018-11-19 10:32 ` Christian Brauner [this message] 2018-11-19 15:32 ` [PATCH v1 1/2] proc: get process file descriptor from /proc/<pid> Andy Lutomirski 2018-11-19 18:20 ` Christian Brauner 2018-11-19 10:32 ` [PATCH v1 2/2] signal: add procfd_signal() syscall Christian Brauner 2018-11-19 15:45 ` Andy Lutomirski 2018-11-19 15:57 ` Daniel Colascione 2018-11-19 18:39 ` Christian Brauner 2018-11-19 15:59 ` Daniel Colascione 2018-11-19 18:29 ` Christian Brauner 2018-11-19 19:02 ` Eric W. Biederman 2018-11-19 19:31 ` Christian Brauner 2018-11-19 19:39 ` Daniel Colascione 2018-11-19 17:10 ` Eugene Syromiatnikov 2018-11-19 18:23 ` Christian Brauner 2018-11-19 17:14 ` Eugene Syromiatnikov 2018-11-19 20:28 ` Aleksa Sarai 2018-11-19 20:55 ` Christian Brauner 2018-11-19 21:13 ` Christian Brauner 2018-11-19 21:18 ` Aleksa Sarai 2018-11-19 21:20 ` Christian Brauner 2018-11-19 21:21 ` Christian Brauner 2018-11-19 21:25 ` Aleksa Sarai 2018-11-19 21:26 ` Daniel Colascione 2018-11-19 21:36 ` Aleksa Sarai 2018-11-19 21:37 ` Christian Brauner 2018-11-19 21:41 ` Daniel Colascione 2018-11-20 4:59 ` Eric W. Biederman 2018-11-20 10:31 ` Christian Brauner 2018-11-21 21:39 ` Serge E. Hallyn 2018-11-19 21:23 ` Aleksa Sarai 2018-11-22 7:41 ` Serge E. Hallyn 2018-11-19 22:39 ` Tycho Andersen 2018-11-19 22:49 ` Daniel Colascione 2018-11-19 23:07 ` Tycho Andersen 2018-11-20 0:27 ` Andy Lutomirski 2018-11-20 0:32 ` Christian Brauner 2018-11-20 0:34 ` Andy Lutomirski 2018-11-20 0:49 ` Daniel Colascione 2018-11-22 7:48 ` Serge E. Hallyn 2018-11-19 23:35 ` kbuild test robot 2018-11-19 23:37 ` kbuild test robot 2018-11-19 23:45 ` Christian Brauner 2018-11-28 21:45 ` Joey Pabalinas 2018-11-28 22:05 ` Christian Brauner 2018-11-28 23:02 ` Joey Pabalinas 2018-11-19 10:32 ` [PATCH] procfd_signal.2: document procfd_signal syscall Christian Brauner 2018-11-20 13:29 ` Michael Kerrisk (man-pages) 2018-11-28 20:59 ` Florian Weimer 2018-11-28 21:12 ` Christian Brauner
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20181119103241.5229-2-christian@brauner.io \ --to=christian@brauner.io \ --cc=akpm@linux-foundation.org \ --cc=cyphar@cyphar.com \ --cc=dancol@google.com \ --cc=ebiederm@xmission.com \ --cc=jannh@google.com \ --cc=keescook@chromium.org \ --cc=linux-api@vger.kernel.org \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-man@vger.kernel.org \ --cc=luto@kernel.org \ --cc=oleg@redhat.com \ --cc=serge@hallyn.com \ --cc=timmurray@google.com \ --cc=viro@zeniv.linux.org.uk \ --subject='Re: [PATCH v1 1/2] proc: get process file descriptor from /proc/<pid>' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).