Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sargun Dhillon <sargun@sargun.me>
To: linux-kernel@vger.kernel.org,
containers@lists.linux-foundation.org, linux-api@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Cc: Sargun Dhillon <sargun@sargun.me>,
tycho@tycho.ws, christian.brauner@ubuntu.com
Subject: [PATCH 1/4] pid: Add pidfd_create_file helper
Date: Fri, 24 Jan 2020 01:17:40 -0800 [thread overview]
Message-ID: <20200124091743.3357-2-sargun@sargun.me> (raw)
In-Reply-To: <20200124091743.3357-1-sargun@sargun.me>
This helper allow for creation of pidfd files. The existing helper
(pidfd_create) creates file descriptors directly, which cannot
be used without race conditions when there is an intermediate
step between creation, and informing userspace the fd has been
created.
Signed-off-by: Sargun Dhillon <sargun@sargun.me>
---
include/linux/pid.h | 1 +
kernel/pid.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 998ae7d24450..70d4725cf8da 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -75,6 +75,7 @@ extern const struct file_operations pidfd_fops;
struct file;
extern struct pid *pidfd_pid(const struct file *file);
+extern struct file *pidfd_create_file(struct pid *pid);
static inline struct pid *get_pid(struct pid *pid)
{
diff --git a/kernel/pid.c b/kernel/pid.c
index 2278e249141d..2a34db290128 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -521,6 +521,28 @@ static int pidfd_create(struct pid *pid)
return fd;
}
+/**
+ * pidfd_create_file() - Create a new pidfd file.
+ *
+ * @pid: struct pid that the pidfd will reference
+ *
+ * This creates a new pidfd file.
+ *
+ * Return: On success, a cloexec pidfd file is returned
+ * On error, an err ptr will be returned.
+ */
+struct file *pidfd_create_file(struct pid *pid)
+{
+ struct file *f;
+
+ f = anon_inode_getfile("[pidfd]", &pidfd_fops, get_pid(pid),
+ O_RDWR | O_CLOEXEC);
+ if (IS_ERR(f))
+ put_pid(pid);
+
+ return f;
+}
+
/**
* pidfd_open() - Open new pid file descriptor.
*
--
2.20.1
next prev parent reply other threads:[~2020-01-24 9:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-24 9:17 [PATCH 0/4] Add the ability to get a pidfd on seccomp user notifications Sargun Dhillon
2020-01-24 9:17 ` Sargun Dhillon [this message]
2020-01-24 9:17 ` [PATCH 2/4] fork: Use newly created pidfd_create_file helper Sargun Dhillon
2020-01-24 9:17 ` [PATCH 3/4] seccomp: Add SECCOMP_USER_NOTIF_FLAG_PIDFD to get pidfd on listener trap Sargun Dhillon
2020-01-24 18:03 ` Tycho Andersen
2020-01-24 20:09 ` Sargun Dhillon
2020-01-26 4:10 ` Aleksa Sarai
2020-01-26 5:42 ` Tycho Andersen
[not found] ` <CAMp4zn_Xv2iicmH2Nc4-EZceD7T8AFe9PQRNX4bNEiAuoKs+vA@mail.gmail.com>
2020-05-15 11:58 ` Christian Brauner
2020-01-26 4:03 ` Aleksa Sarai
2020-01-26 4:14 ` Aleksa Sarai
2020-01-27 5:06 ` Sargun Dhillon
2020-01-24 9:17 ` [PATCH 4/4] selftests/seccomp: test SECCOMP_USER_NOTIF_FLAG_PIDFD Sargun Dhillon
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=20200124091743.3357-2-sargun@sargun.me \
--to=sargun@sargun.me \
--cc=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tycho@tycho.ws \
--subject='Re: [PATCH 1/4] pid: Add pidfd_create_file helper' \
/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).