Skip to content

Commit cd267cd

Browse files
committed
Merge patch series "nsfs: expose the stable inode numbers in a public header"
Christian Brauner <[email protected]> says: Userspace heavily relies on the root inode numbers for namespaces to identify the initial namespaces. That's already a hard dependency. So we cannot change that anymore. Move the initial inode numbers to a public header and align the only two namespaces that currently don't do that with all the other namespaces. * patches from https://lore.kernel.org/[email protected]: mntns: use stable inode number for initial mount ns netns: use stable inode number for initial mount ns nsfs: move root inode number to uapi Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents 19272b3 + 7f4f229 commit cd267cd

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

fs/namespace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6203,9 +6203,11 @@ static void __init init_mount_tree(void)
62036203
if (IS_ERR(mnt))
62046204
panic("Can't create rootfs");
62056205

6206-
ns = alloc_mnt_ns(&init_user_ns, false);
6206+
ns = alloc_mnt_ns(&init_user_ns, true);
62076207
if (IS_ERR(ns))
62086208
panic("Can't allocate initial namespace");
6209+
ns->seq = atomic64_inc_return(&mnt_ns_seq);
6210+
ns->ns.inum = PROC_MNT_INIT_INO;
62096211
m = real_mount(mnt);
62106212
ns->root = m;
62116213
ns->nr_mounts = 1;

include/linux/proc_ns.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define _LINUX_PROC_NS_H
77

88
#include <linux/ns_common.h>
9+
#include <uapi/linux/nsfs.h>
910

1011
struct pid_namespace;
1112
struct nsset;
@@ -40,12 +41,14 @@ extern const struct proc_ns_operations timens_for_children_operations;
4041
*/
4142
enum {
4243
PROC_ROOT_INO = 1,
43-
PROC_IPC_INIT_INO = 0xEFFFFFFFU,
44-
PROC_UTS_INIT_INO = 0xEFFFFFFEU,
45-
PROC_USER_INIT_INO = 0xEFFFFFFDU,
46-
PROC_PID_INIT_INO = 0xEFFFFFFCU,
47-
PROC_CGROUP_INIT_INO = 0xEFFFFFFBU,
48-
PROC_TIME_INIT_INO = 0xEFFFFFFAU,
44+
PROC_IPC_INIT_INO = IPC_NS_INIT_INO,
45+
PROC_UTS_INIT_INO = UTS_NS_INIT_INO,
46+
PROC_USER_INIT_INO = USER_NS_INIT_INO,
47+
PROC_PID_INIT_INO = PID_NS_INIT_INO,
48+
PROC_CGROUP_INIT_INO = CGROUP_NS_INIT_INO,
49+
PROC_TIME_INIT_INO = TIME_NS_INIT_INO,
50+
PROC_NET_INIT_INO = NET_NS_INIT_INO,
51+
PROC_MNT_INIT_INO = MNT_NS_INIT_INO,
4952
};
5053

5154
#ifdef CONFIG_PROC_FS

include/uapi/linux/nsfs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@ struct mnt_ns_info {
4242
/* Get previous namespace. */
4343
#define NS_MNT_GET_PREV _IOR(NSIO, 12, struct mnt_ns_info)
4444

45+
enum init_ns_ino {
46+
IPC_NS_INIT_INO = 0xEFFFFFFFU,
47+
UTS_NS_INIT_INO = 0xEFFFFFFEU,
48+
USER_NS_INIT_INO = 0xEFFFFFFDU,
49+
PID_NS_INIT_INO = 0xEFFFFFFCU,
50+
CGROUP_NS_INIT_INO = 0xEFFFFFFBU,
51+
TIME_NS_INIT_INO = 0xEFFFFFFAU,
52+
NET_NS_INIT_INO = 0xEFFFFFF9U,
53+
MNT_NS_INIT_INO = 0xEFFFFFF8U,
54+
};
55+
4556
#endif /* __LINUX_NSFS_H */

net/core/net_namespace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,19 @@ static __net_init int net_ns_net_init(struct net *net)
796796
#ifdef CONFIG_NET_NS
797797
net->ns.ops = &netns_operations;
798798
#endif
799+
if (net == &init_net) {
800+
net->ns.inum = PROC_NET_INIT_INO;
801+
return 0;
802+
}
799803
return ns_alloc_inum(&net->ns);
800804
}
801805

802806
static __net_exit void net_ns_net_exit(struct net *net)
803807
{
808+
/*
809+
* Initial network namespace doesn't exit so we don't need any
810+
* special checks here.
811+
*/
804812
ns_free_inum(&net->ns);
805813
}
806814

0 commit comments

Comments
 (0)