Skip to content

Commit b2a0b19

Browse files
committed
mnt: expose pointer to init_mnt_ns
There's various scenarios where we need to know whether we are in the initial set of namespaces or not to e.g., shortcut permission checking. All namespaces expose that information. Let's do that too. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 93f67a7 commit b2a0b19

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

fs/namespace.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6008,35 +6008,40 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
60086008
return ret;
60096009
}
60106010

6011+
struct mnt_namespace init_mnt_ns = {
6012+
.ns.inum = PROC_MNT_INIT_INO,
6013+
.ns.ops = &mntns_operations,
6014+
.user_ns = &init_user_ns,
6015+
.ns.count = REFCOUNT_INIT(1),
6016+
.passive = REFCOUNT_INIT(1),
6017+
.mounts = RB_ROOT,
6018+
.poll = __WAIT_QUEUE_HEAD_INITIALIZER(init_mnt_ns.poll),
6019+
};
6020+
60116021
static void __init init_mount_tree(void)
60126022
{
60136023
struct vfsmount *mnt;
60146024
struct mount *m;
6015-
struct mnt_namespace *ns;
60166025
struct path root;
60176026

60186027
mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL);
60196028
if (IS_ERR(mnt))
60206029
panic("Can't create rootfs");
60216030

6022-
ns = alloc_mnt_ns(&init_user_ns, true);
6023-
if (IS_ERR(ns))
6024-
panic("Can't allocate initial namespace");
6025-
ns->ns.inum = PROC_MNT_INIT_INO;
60266031
m = real_mount(mnt);
6027-
ns->root = m;
6028-
ns->nr_mounts = 1;
6029-
mnt_add_to_ns(ns, m);
6030-
init_task.nsproxy->mnt_ns = ns;
6031-
get_mnt_ns(ns);
6032+
init_mnt_ns.root = m;
6033+
init_mnt_ns.nr_mounts = 1;
6034+
mnt_add_to_ns(&init_mnt_ns, m);
6035+
init_task.nsproxy->mnt_ns = &init_mnt_ns;
6036+
get_mnt_ns(&init_mnt_ns);
60326037

60336038
root.mnt = mnt;
60346039
root.dentry = mnt->mnt_root;
60356040

60366041
set_fs_pwd(current->fs, &root);
60376042
set_fs_root(current->fs, &root);
60386043

6039-
ns_tree_add(ns);
6044+
ns_tree_add(&init_mnt_ns);
60406045
}
60416046

60426047
void __init mnt_init(void)

include/linux/mnt_namespace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct fs_struct;
1111
struct user_namespace;
1212
struct ns_common;
1313

14+
extern struct mnt_namespace init_mnt_ns;
15+
1416
extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
1517
struct user_namespace *, struct fs_struct *);
1618
extern void put_mnt_ns(struct mnt_namespace *ns);

0 commit comments

Comments
 (0)