From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>,
Jeff Layton <jlayton@kernel.org>, Karel Zak <kzak@redhat.com>,
Stephane Graber <stgraber@stgraber.org>,
Christian Brauner <brauner@kernel.org>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>
Subject: [PATCH RFC 2/5] fs: allow mount namespace fd
Date: Fri, 19 Jul 2024 13:41:49 +0200 [thread overview]
Message-ID: <20240719-work-mount-namespace-v1-2-834113cab0d2@kernel.org> (raw)
In-Reply-To: <20240719-work-mount-namespace-v1-0-834113cab0d2@kernel.org>
We already allow a mount namespace id, enable mount namespace file
descriptors as well.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/namespace.c | 39 ++++++++++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 328087a4df8a..3ee8adb7f215 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5243,12 +5243,37 @@ static int copy_mnt_id_req(const struct mnt_id_req __user *req,
* that, or if not simply grab a passive reference on our mount namespace and
* return that.
*/
-static struct mnt_namespace *grab_requested_mnt_ns(u64 mnt_ns_id)
+static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq)
{
- if (mnt_ns_id)
- return lookup_mnt_ns(mnt_ns_id);
- refcount_inc(¤t->nsproxy->mnt_ns->passive);
- return current->nsproxy->mnt_ns;
+ struct mnt_namespace *mnt_ns;
+
+ if (kreq->mnt_ns_id && kreq->spare)
+ return ERR_PTR(-EINVAL);
+
+ if (kreq->mnt_ns_id)
+ return lookup_mnt_ns(kreq->mnt_ns_id);
+
+ if (kreq->spare) {
+ struct ns_common *ns;
+
+ CLASS(fd, f)(kreq->spare);
+ if (!f.file)
+ return ERR_PTR(-EBADF);
+
+ if (!proc_ns_file(f.file))
+ return ERR_PTR(-EINVAL);
+
+ ns = get_proc_ns(file_inode(f.file));
+ if (ns->ops->type != CLONE_NEWNS)
+ return ERR_PTR(-EINVAL);
+
+ mnt_ns = to_mnt_ns(ns);
+ } else {
+ mnt_ns = current->nsproxy->mnt_ns;
+ }
+
+ refcount_inc(&mnt_ns->passive);
+ return mnt_ns;
}
SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
@@ -5269,7 +5294,7 @@ SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
if (ret)
return ret;
- ns = grab_requested_mnt_ns(kreq.mnt_ns_id);
+ ns = grab_requested_mnt_ns(&kreq);
if (!ns)
return -ENOENT;
@@ -5396,7 +5421,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
if (!kmnt_ids)
return -ENOMEM;
- ns = grab_requested_mnt_ns(kreq.mnt_ns_id);
+ ns = grab_requested_mnt_ns(&kreq);
if (!ns)
return -ENOENT;
--
2.43.0
next prev parent reply other threads:[~2024-07-19 11:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 11:41 [PATCH RFC 0/5] nsfs: iterate through mount namespaces Christian Brauner
2024-07-19 11:41 ` [PATCH RFC 1/5] fs: use all available ids Christian Brauner
2024-07-19 11:41 ` Christian Brauner [this message]
2024-07-19 11:41 ` [PATCH RFC 3/5] fs: add put_mnt_ns() cleanup helper Christian Brauner
2024-07-19 11:41 ` [PATCH RFC 4/5] file: add fput() " Christian Brauner
2024-07-19 11:41 ` [PATCH RFC 5/5] nsfs: iterate through mount namespaces Christian Brauner
2024-07-19 14:53 ` [PATCH RFC 0/5] " Josef Bacik
2024-07-22 14:42 ` Jeff Layton
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=20240719-work-mount-namespace-v1-2-834113cab0d2@kernel.org \
--to=brauner@kernel.org \
--cc=alexander@mihalicyn.com \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kzak@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=stgraber@stgraber.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).