Merge tag 'net-next-6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev...
[linux-2.6-microblaze.git] / kernel / cgroup / cgroup.c
index 4b249f8..ae51816 100644 (file)
@@ -1465,8 +1465,18 @@ static struct cgroup *current_cgns_cgroup_dfl(void)
 {
        struct css_set *cset;
 
-       cset = current->nsproxy->cgroup_ns->root_cset;
-       return __cset_cgroup_from_root(cset, &cgrp_dfl_root);
+       if (current->nsproxy) {
+               cset = current->nsproxy->cgroup_ns->root_cset;
+               return __cset_cgroup_from_root(cset, &cgrp_dfl_root);
+       } else {
+               /*
+                * NOTE: This function may be called from bpf_cgroup_from_id()
+                * on a task which has already passed exit_task_namespaces() and
+                * nsproxy == NULL. Fall back to cgrp_dfl_root which will make all
+                * cgroups visible for lookups.
+                */
+               return &cgrp_dfl_root.cgrp;
+       }
 }
 
 /* look up cgroup associated with given css_set on the specified hierarchy */