From 4e0f7a203d608470eeae9dfd21277a8a94bb7c29 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 13 Feb 2025 16:16:50 -0800 Subject: [PATCH] libct/cg/dev: remove specconv dependency This was needed for a test case only, but we can easily copy the data needed. The alternatives are: - keep things as is (and have cgroups depend on runc/libcontainer/specconv); - remove this test case; - move AllowedDevices to cgroups/devices/config. Signed-off-by: Kir Kolyshkin --- .../cgroups/devices/devicefilter_test.go | 87 +++++++++++++++++-- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/libcontainer/cgroups/devices/devicefilter_test.go b/libcontainer/cgroups/devices/devicefilter_test.go index 197039a7c..912e8d8cd 100644 --- a/libcontainer/cgroups/devices/devicefilter_test.go +++ b/libcontainer/cgroups/devices/devicefilter_test.go @@ -5,7 +5,6 @@ import ( "testing" devices "github.com/opencontainers/runc/libcontainer/cgroups/devices/config" - "github.com/opencontainers/runc/libcontainer/specconv" ) func hash(s, comm string) string { @@ -53,6 +52,88 @@ block-0: } func TestDeviceFilter_BuiltInAllowList(t *testing.T) { + // This is a copy of all rules from + // github.com/opencontainers/runc/libcontainer/specconv.AllowedDevices. + devices := []*devices.Rule{ + { + Type: devices.CharDevice, + Major: devices.Wildcard, + Minor: devices.Wildcard, + Permissions: "m", + Allow: true, + }, + { + Type: devices.BlockDevice, + Major: devices.Wildcard, + Minor: devices.Wildcard, + Permissions: "m", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 1, + Minor: 3, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 1, + Minor: 8, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 1, + Minor: 7, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 5, + Minor: 0, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 1, + Minor: 5, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 1, + Minor: 9, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 136, + Minor: devices.Wildcard, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 5, + Minor: 2, + Permissions: "rwm", + Allow: true, + }, + { + Type: devices.CharDevice, + Major: 10, + Minor: 200, + Permissions: "rwm", + Allow: true, + }, + } + expected := ` // load parameters into registers 0: LdXMemW dst: r2 src: r1 off: 0 imm: 0 @@ -136,10 +217,6 @@ block-11: 62: MovImm32 dst: r0 imm: 0 63: Exit ` - var devices []*devices.Rule - for _, device := range specconv.AllowedDevices { - devices = append(devices, &device.Rule) - } testDeviceFilter(t, devices, expected) }