]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
netns: use stable inode number for initial mount ns
authorChristian Brauner <brauner@kernel.org>
Fri, 6 Jun 2025 09:45:08 +0000 (11:45 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 11 Jun 2025 09:59:08 +0000 (11:59 +0200)
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/20250606-work-nsfs-v1-2-b8749c9a8844@kernel.org
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/proc_ns.h
include/uapi/linux/nsfs.h
net/core/net_namespace.c

index e77a37b23ca7ec000481708dfac3ffa69d6d88e1..3ff0bd381704b7c18de9e37265b4a32933ce6d58 100644 (file)
@@ -47,6 +47,7 @@ enum {
        PROC_PID_INIT_INO       = PID_NS_INIT_INO,
        PROC_CGROUP_INIT_INO    = CGROUP_NS_INIT_INO,
        PROC_TIME_INIT_INO      = TIME_NS_INIT_INO,
+       PROC_NET_INIT_INO       = NET_NS_INIT_INO,
 };
 
 #ifdef CONFIG_PROC_FS
index 6683e7ca39960ecdad5241f78ff5d0c9ece3cb06..393778489d85e56ba10ddcf9a12b65617171cdf8 100644 (file)
@@ -49,6 +49,7 @@ enum init_ns_ino {
        PID_NS_INIT_INO         = 0xEFFFFFFCU,
        CGROUP_NS_INIT_INO      = 0xEFFFFFFBU,
        TIME_NS_INIT_INO        = 0xEFFFFFFAU,
+       NET_NS_INIT_INO         = 0xEFFFFFF9U,
 };
 
 #endif /* __LINUX_NSFS_H */
index ae54f26709ca242567e5d62d7b5dcc7f6303da57..03cf87d3b3801273841fbd6223ac5226fa4af5cb 100644 (file)
@@ -796,11 +796,19 @@ static __net_init int net_ns_net_init(struct net *net)
 #ifdef CONFIG_NET_NS
        net->ns.ops = &netns_operations;
 #endif
+       if (net == &init_net) {
+               net->ns.inum = PROC_NET_INIT_INO;
+               return 0;
+       }
        return ns_alloc_inum(&net->ns);
 }
 
 static __net_exit void net_ns_net_exit(struct net *net)
 {
+       /*
+        * Initial network namespace doesn't exit so we don't need any
+        * special checks here.
+        */
        ns_free_inum(&net->ns);
 }