Repository navigation
Conversation
The update path sets ControllerOpt.skip_devices, so the v1, v2 and systemd managers skip the devices controller, as runc's SkipDevices does. Setting unit properties makes systemd attach the device filter it derives from DeviceAllow, and for rules that keep a deny that filter denies every device. So when a skipped update sets unit properties, the systemd manager detaches the device programs that appeared during the call. Fixes youki-dev#3919 Signed-off-by: Asifur Rahaman Meeru <asifur.rahaman@meeru.dev>
There was a problem hiding this comment.
🟡 Changes recommended
The cleanup can detach administrator-tightened or concurrently attached device filters, broadening device access to an older policy.
2 open issues
What changed in this PR
Addresses #3919 by preserving container device rules during youki update, rather than rebuilding them from unrelated resource changes.
Changes:
- Adds
ControllerOpt::skip_devices, enabled only for updates across cgroup v1, v2, and systemd. - Skips systemd device properties and adds cleanup of device filters attached during property updates, with rootless error handling.
- Adds unit and integration coverage for preserving device access while updating process limits.
| File | Description |
|---|---|
tests/contest/contest/src/tests/update/mod.rs |
Registers both device-rule regression tests. |
tests/contest/contest/src/tests/update/devices.rs |
Checks device access before and after updates on both drivers. |
crates/youki/src/commands/update.rs |
Enables device skipping for updates. |
crates/youki/src/commands/mod.rs |
Passes rootless status to the cgroup manager. |
crates/libcontainer/src/process/container_intermediate_process.rs |
Keeps device handling enabled during creation. |
crates/libcgroups/src/v2/unified.rs |
Updates test options for the new field. |
crates/libcgroups/src/v2/manager.rs |
Updates freezer and test options. |
crates/libcgroups/src/v2/devices/controller.rs |
Adds device skipping, filter snapshot and cleanup helpers, and tests. |
crates/libcgroups/src/v1/memory.rs |
Updates test options for the new field. |
crates/libcgroups/src/v1/manager.rs |
Updates freezer options for the new field. |
crates/libcgroups/src/v1/freezer.rs |
Updates test options for the new field. |
crates/libcgroups/src/v1/devices.rs |
Deselects the devices controller during updates and tests selection. |
crates/libcgroups/src/systemd/pids.rs |
Updates test options for the new field. |
crates/libcgroups/src/systemd/manager.rs |
Coordinates skipped device handling and post-property filter cleanup. |
crates/libcgroups/src/systemd/devices.rs |
Omits device properties when skipping and adds coverage. |
crates/libcgroups/src/common.rs |
Defines and documents skip_devices. |
crates/libcgroups/examples/systemd_io.rs |
Updates the example to retain normal device handling. |
Review effort: Balanced
| if !before.contains(&prog.id) { | ||
| bpf_prog::detach2(prog.fd, fd.as_raw_fd())?; |
There was a problem hiding this comment.
This is a known limit of the detach, listed in the description next to a concurrent attach. Avoiding it needs systemd to never own a device filter (DevicePolicy=auto at create when the rules keep a deny), and I've asked the maintainers there which way they want to go. I'll leave this thread open until a decision is made.
| )?; | ||
|
|
||
| let mut detached = Vec::new(); | ||
| for prog in bpf_prog::query(fd.as_raw_fd())? { |
There was a problem hiding this comment.
Fixed in a2f50283. The snapshot now uses query_ids, which lists the attached ids without opening the programs, so a program that can't be opened still counts as attached. A new program that can't be opened now fails the update. ENOENT, a program that is already gone, is skipped. The error path has a unit test.
bpf_prog::query skips a program whose fd it cannot open. The skipped update's snapshot of the attached device programs now uses the ids alone, so such a program still counts as attached before the property call, and a new program that cannot be opened is an error instead of a silent success. Signed-off-by: Asifur Rahaman Meeru <asifur.rahaman@meeru.dev>
|
The |
…ices # Conflicts: # tests/contest/contest/src/tests/update/mod.rs


Description
On cgroup v2 and under systemd,
youki updaterebuilt the device rules from the update's resources, which hold no devices for a flag update, so the container lost every rule that is not a default. With /dev/loop-control allowed at create,youki update --pids-limit 50leaves it denied. The update now skips the devices controller, as runc's update does withSkipDevices(its comment mentions plugins such as the NVIDIA one that apply device configuration on top).ControllerOptgets askip_devicesflag that only the update path sets. The v2 manager leaves the devices controller alone when it is set, and v1 does not select it, so a v1 update no longer needs the devices hierarchy either. The systemd manager sends no DevicePolicy/DeviceAllow and, when the update sets unit properties, lists the attached device programs before the call and detaches the ones that appeared during it. youki's own program from create stays and keeps enforcing the container's rules.The detach is needed because setting unit properties makes systemd attach the filter it derives from the unit's DeviceAllow again. I measured that with TasksMax alone. When the rules keep a deny after folding, youki creates the unit with DevicePolicy=strict and an empty DeviceAllow, so that filter denies every device. With deny-all, allow
c 10:237 rw, denyc 10:237 w, a plain skip left the container unable to open /dev/null after the update. runc folds those rules into an exact allow list, so its systemd filter matches them.Devices in an
update --resourcesJSON are ignored too, as in runc.The new pub field on
ControllerOptbreaks struct literals outside this repo, hence the breaking change box. I left the label to you.Type of Change
Testing
cargo test -p libcgroups --libandcargo test -p youkipass, fmt and clippy clean. The unit tests cover the flag in v1 (controller selection), v2 and systemd, and the detach helper, and fail when the flag is ignored or always set.Two contest tests in the update group, for the cgroupfs and systemd drivers: deny everything, allow reading c 10:237, deny writing it, then
update --pids-limit 50. Before and after the update they check that /dev/null opens, the read works and the write fails with "Operation not permitted", and after it that pids.max is 50. As root they fail on main, pass with this change and with runc 1.5.3, and the systemd one fails on /dev/null with the detach removed. Hosts without the loop driver skip them.Manually, as root on Fedora (systemd 262, kernel 7.3, runc 1.5.3): the same probes for the rule list above on both drivers, and for allow-only, allow-all and allow-all plus a deny under systemd, with
bpftool cgroup showon the scope before and after the update.Related Issues
Fixes #3919
Additional Context
As discussed in the issue, device updates can come later. containers/crun#2482 does that under systemd with a pinned eBPF program that reads a per-cgroup map, and opencontainers/runc#3401 tracks it for runc. Only the update path sets the flag, so that work can drop the skip there.
With allow-all plus a deny on systemd, runc 1.5.3 itself ends up denying every device after
runc update --pids-limit 50: bpftool shows a newsd_devicesprogram next to runc's.The detach has limits. A device program that something else attaches to the container's cgroup during the property call is detached along with systemd's. If systemd already enforces a narrower policy on the scope, for example after
systemctl set-property <scope> DeviceAllow=..., it replaces its filter during the call and the detach removes the replacement. Between systemd's attach and the detach, device opens in a deny-rule container fail for a moment.A question for the maintainers: the alternative I considered is to create the unit with DevicePolicy=auto and no DeviceAllow when the rules keep a deny, so systemd attaches no filter and youki's program is the only one. That removes the detach and every limit above, but changes what systemd is told at create, and containers created before this change would still lose their devices on update without the detach. I'm happy to switch if you prefer that.