Skip to content

Commit 7b9d14a

Browse files
committed
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/[email protected] Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 720261c commit 7b9d14a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

fs/namespace.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5243,12 +5243,37 @@ static int copy_mnt_id_req(const struct mnt_id_req __user *req,
52435243
* that, or if not simply grab a passive reference on our mount namespace and
52445244
* return that.
52455245
*/
5246-
static struct mnt_namespace *grab_requested_mnt_ns(u64 mnt_ns_id)
5246+
static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq)
52475247
{
5248-
if (mnt_ns_id)
5249-
return lookup_mnt_ns(mnt_ns_id);
5250-
refcount_inc(&current->nsproxy->mnt_ns->passive);
5251-
return current->nsproxy->mnt_ns;
5248+
struct mnt_namespace *mnt_ns;
5249+
5250+
if (kreq->mnt_ns_id && kreq->spare)
5251+
return ERR_PTR(-EINVAL);
5252+
5253+
if (kreq->mnt_ns_id)
5254+
return lookup_mnt_ns(kreq->mnt_ns_id);
5255+
5256+
if (kreq->spare) {
5257+
struct ns_common *ns;
5258+
5259+
CLASS(fd, f)(kreq->spare);
5260+
if (!f.file)
5261+
return ERR_PTR(-EBADF);
5262+
5263+
if (!proc_ns_file(f.file))
5264+
return ERR_PTR(-EINVAL);
5265+
5266+
ns = get_proc_ns(file_inode(f.file));
5267+
if (ns->ops->type != CLONE_NEWNS)
5268+
return ERR_PTR(-EINVAL);
5269+
5270+
mnt_ns = to_mnt_ns(ns);
5271+
} else {
5272+
mnt_ns = current->nsproxy->mnt_ns;
5273+
}
5274+
5275+
refcount_inc(&mnt_ns->passive);
5276+
return mnt_ns;
52525277
}
52535278

52545279
SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
@@ -5269,7 +5294,7 @@ SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
52695294
if (ret)
52705295
return ret;
52715296

5272-
ns = grab_requested_mnt_ns(kreq.mnt_ns_id);
5297+
ns = grab_requested_mnt_ns(&kreq);
52735298
if (!ns)
52745299
return -ENOENT;
52755300

@@ -5396,7 +5421,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
53965421
if (!kmnt_ids)
53975422
return -ENOMEM;
53985423

5399-
ns = grab_requested_mnt_ns(kreq.mnt_ns_id);
5424+
ns = grab_requested_mnt_ns(&kreq);
54005425
if (!ns)
54015426
return -ENOENT;
54025427

0 commit comments

Comments
 (0)