libprocessgroup: Reject JoinCgroup actions for v2 controllers

A JoinCgroup action for a v2 cgroup controller migrates a process or task
from the uid_%d/pid_%d cgroup into another cgroup, e.g. the root cgroup.
This may make services unkillable because Service::Stop() only stops a
service if the uid_%d/pid_%d cgroup still exists when Service::Stop() is
called.

Bug: 309674654
Change-Id: I20b797afdf596125ff5a6ed41cb33fe59b84ac88
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Bart Van Assche 2023-11-14 07:33:00 -08:00
parent b190d94469
commit 2953a9273e

View file

@ -868,7 +868,13 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) {
auto controller = cg_map.FindController(controller_name);
if (controller.HasValue()) {
profile->Add(std::make_unique<SetCgroupAction>(controller, path));
if (controller.version() == 1) {
profile->Add(std::make_unique<SetCgroupAction>(controller, path));
} else {
LOG(WARNING) << "A JoinCgroup action in the " << profile_name
<< " profile is used for controller " << controller_name
<< " in the cgroup v2 hierarchy and will be ignored";
}
} else {
LOG(WARNING) << "JoinCgroup: controller " << controller_name << " is not found";
}