]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cgroup: support ns lookup
authorChristian Brauner <brauner@kernel.org>
Fri, 12 Sep 2025 11:52:42 +0000 (13:52 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 19 Sep 2025 12:26:15 +0000 (14:26 +0200)
Support the generic ns lookup infrastructure to support file handles for
namespaces.

Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
kernel/cgroup/cgroup.c
kernel/cgroup/namespace.c

index 312c6a8b55bb73d2780ca4b3ed02669bb3062bb9..092e6bf081ed1fc6fca3d3f7f859ea47b76d053f 100644 (file)
@@ -59,6 +59,7 @@
 #include <linux/sched/cputime.h>
 #include <linux/sched/deadline.h>
 #include <linux/psi.h>
+#include <linux/nstree.h>
 #include <net/sock.h>
 
 #define CREATE_TRACE_POINTS
@@ -6312,6 +6313,7 @@ int __init cgroup_init(void)
        WARN_ON(register_filesystem(&cpuset_fs_type));
 #endif
 
+       ns_tree_add(&init_cgroup_ns);
        return 0;
 }
 
index 0391b6ab0bf1bef0a65af6d10c1c84323b0178bb..fc12c416dfeb34a4c312413eaf02135fed306e8b 100644 (file)
@@ -5,7 +5,7 @@
 #include <linux/slab.h>
 #include <linux/nsproxy.h>
 #include <linux/proc_ns.h>
-
+#include <linux/nstree.h>
 
 /* cgroup namespaces */
 
@@ -30,16 +30,19 @@ static struct cgroup_namespace *alloc_cgroup_ns(void)
        ret = ns_common_init(&new_ns->ns, &cgroupns_operations, true);
        if (ret)
                return ERR_PTR(ret);
+       ns_tree_add(new_ns);
        return no_free_ptr(new_ns);
 }
 
 void free_cgroup_ns(struct cgroup_namespace *ns)
 {
+       ns_tree_remove(ns);
        put_css_set(ns->root_cset);
        dec_cgroup_namespaces(ns->ucounts);
        put_user_ns(ns->user_ns);
        ns_free_inum(&ns->ns);
-       kfree(ns);
+       /* Concurrent nstree traversal depends on a grace period. */
+       kfree_rcu(ns, ns.ns_rcu);
 }
 EXPORT_SYMBOL(free_cgroup_ns);