Skip to content

test(contest): add cgroup v2 device integration tests - #3943

Open
ARMeeru wants to merge 2 commits into
youki-dev:mainfrom
ARMeeru:test/cgroup-v2-devices
Open

ARMeeru wants to merge 2 commits into
youki-dev:mainfrom
ARMeeru:test/cgroup-v2-devices

Conversation

@ARMeeru

@ARMeeru ARMeeru commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a cgroup_v2_devices contest group for cgroupfs. Like the systemd device tests, it runs runtimetest's device_cgroup check inside the container, which opens block nodes the runtime created and compares EPERM against the spec's rules, so it needs no host devices. The four cases are default deny, deny-all with an allow and a redundant deny, a deny on top of allow-all, and an allow followed by a write deny.

device_cgroup now checks writes as well as reads, so the systemd device group gets the write check too. The spec helpers both groups use move from systemd/devices.rs to utils/cgroups.rs.

mknod is not covered: both runtimes append allow b *:* m and allow c *:* m, and how a deny of it should behave is open in #3911.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

On aarch64 with kernel 7.3, cgroup v2 and systemd 262, as root, release youki and runc 1.5.3 each pass all four cgroup_v2_devices tests and all five cgroup_systemd_devices tests with no skips. This host has no 8:x disk, so the allowed opens return ENXIO.

Mutation checks on youki's device rule code, against cgroup_v2_devices:

  • Making a type a rule always switch to allow-all fails device_default_deny and device_allow_with_redundant_deny.
  • Reading the w access bit as r fails the other three tests.

Full just lint passes. cargo test --locked -p contest -p runtimetest --all-targets passes.

Related Issues

Fixes #3605

Additional Context

Update-time device preservation and its regression tests are handled in #3930. This PR adds only the creation-time coverage requested in #3605.

Add a cgroupfs contest group covering default and explicit device
denial, character-device access, and block-device reads.

The deny cases write to and read /dev/kmsg: one has only a deny-all
rule, the other grants and then revokes access. The allow cases write
to and open /dev/kmsg, and read one byte with dd from a block device
that was readable on the host, skipping empty and removable devices.
Skip only cases whose host device prerequisites are unavailable.

Fixes youki-dev#3605

Signed-off-by: Asifur Rahaman Meeru <asifur.rahaman@meeru.dev>
@ARMeeru
ARMeeru force-pushed the test/cgroup-v2-devices branch from 603ddc4 to b4e2277 Compare November 27, 2026 01:29
@ARMeeru
ARMeeru marked this pull request as ready for review November 27, 2026 01:42
@saku3
saku3 requested a balanced review from Copilot November 28, 2026 20:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the added creation-time cgroup v2 device-access tests.

No open issues 🎉

What changed in this PR

Adds creation-time device-access coverage to contest’s cgroup v2 integration tests using cgroupfs. Update-time behavior remains scoped to #3930.

Changes:

  • Adds four tests covering default denial, explicit denial, character-device access, and block-device reads.
  • Uses real device operations, with host prerequisite checks that skip unavailable devices.
  • Registers the new cgroup_v2_devices test group.
File Description
tests/​contest/​contest/​src/​tests/​cgroups/​mod.rs Exposes the new devices test module.
tests/​contest/​contest/​src/​tests/​cgroups/​devices.rs Implements and registers four device-access tests with shared setup and host prerequisite checks.

Review effort: Balanced

@saku3

saku3 commented Nov 29, 2026

Copy link
Copy Markdown
Member

Is there a reason for performing device access validation in contest instead of runtimetest?
Could we extend or share some of the existing device validation logic in runtimetest?

@ARMeeru

ARMeeru commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Is there a reason for performing device access validation in contest instead of runtimetest? Could we extend or share some of the existing device validation logic in runtimetest?

No strong reason. I followed runc's dev.bats, which mostly probes with shell commands, rather than reusing runtimetest device_cgroup from #3721. That check doesn't depend on the host the way this version does (an openable /dev/kmsg, CAP_SYSLOG on dmesg_restrict hosts, a readable host block device).

I'll rework the group to run runtimetest device_cgroup on cgroupfs with the three access cases the systemd group runs through it (default deny, deny-all with an allow and a redundant deny, a deny on top of allow-all), plus allow then deny. It only checks block device reads, so the /dev/kmsg case goes. Should I add a write check to it as well, and is it fine to move the spec helpers from systemd/devices.rs into a shared module?

@saku3

saku3 commented Nov 29, 2026

Copy link
Copy Markdown
Member

Should I add a write check to it as well, and is it fine to move the spec helpers from systemd/devices.rs into a shared module?

If both can be done without significant changes, please include them in this PR.

Ideally, the tests should cover all three device access permissions: r (read), w (write), and m (mknod).

@ARMeeru

ARMeeru commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Should I add a write check to it as well, and is it fine to move the spec helpers from systemd/devices.rs into a shared module?

If both can be done without significant changes, please include them in this PR.

Ideally, the tests should cover all three device access permissions: r (read), w (write), and m (mknod).

I'll add the write check and move the helpers.

For m, I measured mknod on cgroupfs with youki and runc 1.5.3. Both runtimes append allow b *:* m and allow c *:* m after the spec's rules, so with a deny-all spec mknod is allowed whatever the spec says, and a check could only confirm that. With allow-all plus deny b 8:0 m, runc denies mknod of 8:0 and youki allows it, because youki checks its later built-in rule first. That's the mirror of Case 2 in #3911, so an m deny test would pin a behavior #3911 hasn't decided yet. I'd leave m out of this PR and add it once #3911 settles. Is that OK?

@saku3

saku3 commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks for investigating. That approach sounds good to me.

Replace the shell probes in the cgroup_v2_devices group with
runtimetest's device_cgroup check, as the systemd device tests do, and
move the spec helpers both groups use into utils. device_cgroup now
checks writes as well as reads, so the systemd group gets the write
check too.

mknod is not covered: both runtimes append allow b *:* m and
allow c *:* m, and how a deny of it should behave is open in youki-dev#3911.

Signed-off-by: Asifur Rahaman Meeru <asifur.rahaman@meeru.dev>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add integration tests for cgroup v2 and systemd

3 participants