Skip to content

Commit 9b0240b

Browse files
committed
netns: use stable inode number for initial mount ns
Apart from the network and mount namespace all other namespaces expose a stable inode number and userspace has been relying on that for a very long time now. It's very much heavily used API. Align the network namespace and use a stable inode number from the reserved procfs inode number space so this is consistent across all namespaces. Link: https://lore.kernel.org/[email protected] Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 6a9e2fb commit 9b0240b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

include/linux/proc_ns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum {
4747
PROC_PID_INIT_INO = PID_NS_INIT_INO,
4848
PROC_CGROUP_INIT_INO = CGROUP_NS_INIT_INO,
4949
PROC_TIME_INIT_INO = TIME_NS_INIT_INO,
50+
PROC_NET_INIT_INO = NET_NS_INIT_INO,
5051
};
5152

5253
#ifdef CONFIG_PROC_FS

include/uapi/linux/nsfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum init_ns_ino {
4949
PID_NS_INIT_INO = 0xEFFFFFFCU,
5050
CGROUP_NS_INIT_INO = 0xEFFFFFFBU,
5151
TIME_NS_INIT_INO = 0xEFFFFFFAU,
52+
NET_NS_INIT_INO = 0xEFFFFFF9U,
5253
};
5354

5455
#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)