Skip to content

Commit ef4ff6a

Browse files
committed
Skip updates on parent Devices cgroup
Signed-off-by: Buddha Prakash <[email protected]>
1 parent bd1d3ac commit ef4ff6a

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

libcontainer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ config := &configs.Config{
7777
Parent: "system",
7878
Resources: &configs.Resources{
7979
MemorySwappiness: nil,
80-
AllowAllDevices: false,
80+
AllowAllDevices: nil,
8181
AllowedDevices: configs.DefaultAllowedDevices,
8282
},
8383
},

libcontainer/cgroups/fs/devices.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ func (s *DevicesGroup) Set(path string, cgroup *configs.Cgroup) error {
4343
}
4444
return nil
4545
}
46-
if !cgroup.Resources.AllowAllDevices {
47-
if err := writeFile(path, "devices.deny", "a"); err != nil {
48-
return err
49-
}
50-
51-
for _, dev := range cgroup.Resources.AllowedDevices {
52-
if err := writeFile(path, "devices.allow", dev.CgroupString()); err != nil {
46+
if cgroup.Resources.AllowAllDevices != nil {
47+
if *cgroup.Resources.AllowAllDevices == false {
48+
if err := writeFile(path, "devices.deny", "a"); err != nil {
5349
return err
5450
}
51+
52+
for _, dev := range cgroup.Resources.AllowedDevices {
53+
if err := writeFile(path, "devices.allow", dev.CgroupString()); err != nil {
54+
return err
55+
}
56+
}
57+
return nil
5558
}
56-
return nil
57-
}
5859

59-
if err := writeFile(path, "devices.allow", "a"); err != nil {
60-
return err
60+
if err := writeFile(path, "devices.allow", "a"); err != nil {
61+
return err
62+
}
6163
}
6264

6365
for _, dev := range cgroup.Resources.DeniedDevices {

libcontainer/cgroups/fs/devices_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func TestDevicesSetAllow(t *testing.T) {
4040
helper.writeFileContents(map[string]string{
4141
"devices.deny": "a",
4242
})
43-
44-
helper.CgroupData.config.Resources.AllowAllDevices = false
43+
allowAllDevices := false
44+
helper.CgroupData.config.Resources.AllowAllDevices = &allowAllDevices
4545
helper.CgroupData.config.Resources.AllowedDevices = allowedDevices
4646
devices := &DevicesGroup{}
4747
if err := devices.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
@@ -66,7 +66,8 @@ func TestDevicesSetDeny(t *testing.T) {
6666
"devices.allow": "a",
6767
})
6868

69-
helper.CgroupData.config.Resources.AllowAllDevices = true
69+
allowAllDevices := true
70+
helper.CgroupData.config.Resources.AllowAllDevices = &allowAllDevices
7071
helper.CgroupData.config.Resources.DeniedDevices = deniedDevices
7172
devices := &DevicesGroup{}
7273
if err := devices.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {

libcontainer/configs/cgroup_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Cgroup struct {
3636
type Resources struct {
3737
// If this is true allow access to any kind of device within the container. If false, allow access only to devices explicitly listed in the allowed_devices list.
3838
// Deprecated
39-
AllowAllDevices bool `json:"allow_all_devices,omitempty"`
39+
AllowAllDevices *bool `json:"allow_all_devices,omitempty"`
4040
// Deprecated
4141
AllowedDevices []*Device `json:"allowed_devices,omitempty"`
4242
// Deprecated

libcontainer/integration/template_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const defaultMountFlags = syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NOD
2020
// it uses a network strategy of just setting a loopback interface
2121
// and the default setup for devices
2222
func newTemplateConfig(rootfs string) *configs.Config {
23+
allowAllDevices := false
2324
return &configs.Config{
2425
Rootfs: rootfs,
2526
Capabilities: []string{
@@ -49,7 +50,7 @@ func newTemplateConfig(rootfs string) *configs.Config {
4950
Path: "integration/test",
5051
Resources: &configs.Resources{
5152
MemorySwappiness: nil,
52-
AllowAllDevices: false,
53+
AllowAllDevices: &allowAllDevices,
5354
AllowedDevices: configs.DefaultAllowedDevices,
5455
},
5556
},

0 commit comments

Comments
 (0)