Skip to content

Commit 88e6d48

Browse files
committed
libcontainer: cgroups: loudly fail with Set
It is vital to loudly fail when a user attempts to set a cgroup limit (rather than using the system default). Otherwise the user will assume they have security they do not actually have. This mirrors the original Apply() (that would set cgroup configs) semantics. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 8a740d5 commit 88e6d48

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

libcontainer/cgroups/fs/apply_raw.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,24 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
180180
}
181181

182182
func (m *Manager) Set(container *configs.Config) error {
183-
for name, path := range m.Paths {
183+
for _, sys := range subsystems {
184184
// We can't set this here, because after being applied, memcg doesn't
185185
// allow a non-empty cgroup from having its limits changed.
186-
if name == "memory" {
186+
if sys.Name() == "memory" {
187187
continue
188188
}
189-
sys, err := subsystems.Get(name)
190-
if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
191-
continue
189+
190+
// Generate fake cgroup data.
191+
d, err := getCgroupData(container.Cgroups, -1)
192+
if err != nil {
193+
return err
192194
}
195+
// Get the path, but don't error out if the cgroup wasn't found.
196+
path, err := d.path(sys.Name())
197+
if err != nil && !cgroups.IsNotFound(err) {
198+
return err
199+
}
200+
193201
if err := sys.Set(path, container.Cgroups); err != nil {
194202
return err
195203
}

libcontainer/cgroups/systemd/apply_systemd.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,16 +438,19 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
438438
}
439439

440440
func (m *Manager) Set(container *configs.Config) error {
441-
for name, path := range m.Paths {
441+
for _, sys := range subsystems {
442442
// We can't set this here, because after being applied, memcg doesn't
443443
// allow a non-empty cgroup from having its limits changed.
444-
if name == "memory" {
444+
if sys.Name() == "memory" {
445445
continue
446446
}
447-
sys, err := subsystems.Get(name)
448-
if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
449-
continue
447+
448+
// Get the subsystem path, but don't error out for not found cgroups.
449+
path, err := getSubsystemPath(container.Cgroups, sys.Name())
450+
if err != nil && !cgroups.IsNotFound(err) {
451+
return err
450452
}
453+
451454
if err := sys.Set(path, container.Cgroups); err != nil {
452455
return err
453456
}

0 commit comments

Comments
 (0)