Skip to content

Commit e123805

Browse files
committed
oci: fix segfault when cgroup cannot be configured
avoid a segfault if the cgroup hierarchy could not be configured. It happens every time with rootless mode as we cannot configure cgroups, but it is not restricted to rootless. Closes: cri-o#2205 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 0379aed commit e123805

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

oci/oci_linux.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ func (r *runtimeOCI) createContainerPlatform(c *Container, cgroupParent string,
3636
logrus.Warnf("Failed to add conmon to cgroupfs sandbox cgroup: %v", err)
3737
}
3838

39-
// Here we should defer a crio-connmon- cgroup hierarchy deletion, but it will
40-
// always fail as conmon's pid is still there.
41-
// Fortunately, kubelet takes care of deleting this for us, so the leak will
42-
// only happens in corner case where one does a manual deletion of the container
43-
// through e.g. runc. This should be handled by implementing a conmon monitoring
44-
// routine that does the cgroup cleanup once conmon is terminated.
45-
if err := control.Add(cgroups.Process{Pid: pid}); err != nil {
46-
logrus.Warnf("Failed to add conmon to cgroupfs sandbox cgroup: %v", err)
39+
if control != nil {
40+
// Here we should defer a crio-connmon- cgroup hierarchy deletion, but it will
41+
// always fail as conmon's pid is still there.
42+
// Fortunately, kubelet takes care of deleting this for us, so the leak will
43+
// only happens in corner case where one does a manual deletion of the container
44+
// through e.g. runc. This should be handled by implementing a conmon monitoring
45+
// routine that does the cgroup cleanup once conmon is terminated.
46+
if err := control.Add(cgroups.Process{Pid: pid}); err != nil {
47+
logrus.Warnf("Failed to add conmon to cgroupfs sandbox cgroup: %v", err)
48+
}
4749
}
4850
}
4951

0 commit comments

Comments
 (0)