Skip to content

Commit 6635338

Browse files
authored
Merge pull request #4615 from kolyshkin/1.2-4612
[1.2] libct/cg/sd: set the DeviceAllow property before DevicePolicy
2 parents de92f4b + 9742b6c commit 6635338

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

libcontainer/cgroups/devices/systemd.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ func systemdProperties(r *configs.Resources, sdVer int) ([]systemdDbus.Property,
2323
}
2424

2525
properties := []systemdDbus.Property{
26+
// When we later add DeviceAllow=/dev/foo properties, we are
27+
// appending devices to the allow list for the unit. However,
28+
// if this is an existing unit, it already has DeviceAllow=
29+
// entries, and we need to clear them all before applying the
30+
// new set. (We also do this for new units, mainly for safety
31+
// to ensure we only enable the devices we expect.)
32+
//
33+
// To clear any existing DeviceAllow= rules, we have to add an
34+
// empty DeviceAllow= property.
35+
newProp("DeviceAllow", []deviceAllowEntry{}),
2636
// Always run in the strictest white-list mode.
2737
newProp("DevicePolicy", "strict"),
28-
// Empty the DeviceAllow array before filling it.
29-
newProp("DeviceAllow", []deviceAllowEntry{}),
3038
}
3139

3240
// Figure out the set of rules.
@@ -239,7 +247,7 @@ func allowAllDevices() []systemdDbus.Property {
239247
// Setting mode to auto and removing all DeviceAllow rules
240248
// results in allowing access to all devices.
241249
return []systemdDbus.Property{
242-
newProp("DevicePolicy", "auto"),
243250
newProp("DeviceAllow", []deviceAllowEntry{}),
251+
newProp("DevicePolicy", "auto"),
244252
}
245253
}

tests/integration/dev.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,15 @@ function teardown() {
141141
runc exec -t test_exec sh -c "ls -l /proc/self/fd/0; echo 123"
142142
[ "$status" -eq 0 ]
143143
}
144+
145+
# https://github.com/opencontainers/runc/issues/4568
146+
@test "runc run [devices vs systemd NeedDaemonReload]" {
147+
# The systemd bug is there since v230, see
148+
# https://github.com/systemd/systemd/pull/3170/commits/ab932a622d57fd327ef95992c343fd4425324088
149+
# and https://github.com/systemd/systemd/issues/35710.
150+
requires systemd_v230
151+
152+
set_cgroups_path
153+
runc run -d --console-socket "$CONSOLE_SOCKET" test_need_reload
154+
check_systemd_value "NeedDaemonReload" "no"
155+
}

0 commit comments

Comments
 (0)