mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
fs: allow mount namespace fd
We already allow a mount namespace id, enable mount namespace file descriptors as well. Link: https://lore.kernel.org/r/20240719-work-mount-namespace-v1-2-834113cab0d2@kernel.org Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
@@ -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
|
* that, or if not simply grab a passive reference on our mount namespace and
|
||||||
* return that.
|
* 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)
|
struct mnt_namespace *mnt_ns;
|
||||||
return lookup_mnt_ns(mnt_ns_id);
|
|
||||||
refcount_inc(¤t->nsproxy->mnt_ns->passive);
|
if (kreq->mnt_ns_id && kreq->spare)
|
||||||
return current->nsproxy->mnt_ns;
|
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,
|
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)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ns = grab_requested_mnt_ns(kreq.mnt_ns_id);
|
ns = grab_requested_mnt_ns(&kreq);
|
||||||
if (!ns)
|
if (!ns)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
@@ -5396,7 +5421,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
|
|||||||
if (!kmnt_ids)
|
if (!kmnt_ids)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ns = grab_requested_mnt_ns(kreq.mnt_ns_id);
|
ns = grab_requested_mnt_ns(&kreq);
|
||||||
if (!ns)
|
if (!ns)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user