mirror of
https://github.com/opencontainers/runc.git
synced 2025-12-24 11:50:58 +08:00
libct: Signal: honor RootlessCgroups
`signalAllProcesses()` depends on the cgroup and is expected to fail when runc is running in rootless without an access to the cgroup. When `RootlessCgroups` is set to `true`, runc just ignores the error from `signalAllProcesses` and may leak some processes running. (See the comments in PR 4395) In the future, runc should walk the process tree to avoid such a leak. Note that `RootlessCgroups` is a misnomer; it is set to `false` despite the name when cgroup v2 delegation is configured. This is expected to be renamed in a separate commit. Fix issue 4394 Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
@@ -388,11 +388,21 @@ func (c *Container) Signal(s os.Signal) error {
|
||||
// leftover processes. Handle this special case here.
|
||||
if s == unix.SIGKILL && !c.config.Namespaces.IsPrivate(configs.NEWPID) {
|
||||
if err := signalAllProcesses(c.cgroupManager, unix.SIGKILL); err != nil {
|
||||
if c.config.RootlessCgroups { // may not have an access to cgroup
|
||||
logrus.WithError(err).Warn("failed to kill all processes, possibly due to lack of cgroup (Hint: enable cgroup v2 delegation)")
|
||||
// Some processes may leak when cgroup is not delegated
|
||||
// https://github.com/opencontainers/runc/pull/4395#pullrequestreview-2291179652
|
||||
return c.signal(s)
|
||||
}
|
||||
return fmt.Errorf("unable to kill all processes: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return c.signal(s)
|
||||
}
|
||||
|
||||
func (c *Container) signal(s os.Signal) error {
|
||||
// To avoid a PID reuse attack, don't kill non-running container.
|
||||
if !c.hasInit() {
|
||||
return ErrNotRunning
|
||||
|
||||
Reference in New Issue
Block a user