cgroup: cgroup: Honor caller's cgroup NS when resolving cgroup id
authorMichal Koutný <mkoutny@suse.com>
Fri, 26 Aug 2022 16:52:36 +0000 (18:52 +0200)
committerTejun Heo <tj@kernel.org>
Fri, 26 Aug 2022 20:57:10 +0000 (10:57 -1000)
commit4534dee941056a4ab9dca4a9e2edff28692800b2
tree4b429a6e6fee0956eda3e3a8539ff68b432e3717
parent74e4b956eb1cac0e4c10c240339b1bbfbc9a4c48
cgroup: cgroup: Honor caller's cgroup NS when resolving cgroup id

Cgroup ids are resolved in the global scope. That may be needed sometime
(in future) but currently it violates virtual view provided through
cgroup namespaces.

There are currently following users of the resolution:
- fc_appid_store
- bpf_iter_attach_cgroup
- mem_cgroup_get_from_ino

None of the is a called on behalf of kernel but the resolution is made
with proper userspace context, hence the default to current->nsproxy
makes sens. (This doesn't rule out cgroup_get_from_id with cgroup NS
parameter in the future.)

Since cgroup ids are defined on v2 hierarchy only, we simply check
existence in the cgroup namespace by looking at ancestry on the default
hierarchy.

Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c