Skip to content

Fix: skip cgroup filesystem type check when cgroups are disabled#2062

Merged
giuseppe merged 1 commit intocontainers:mainfrom
jnovy:fix-cgroup-disabled-check
Apr 1, 2026
Merged

Fix: skip cgroup filesystem type check when cgroups are disabled#2062
giuseppe merged 1 commit intocontainers:mainfrom
jnovy:fix-cgroup-disabled-check

Conversation

@jnovy
Copy link
Copy Markdown
Contributor

@jnovy jnovy commented Mar 27, 2026

Fixes #1413

Problem

When --cgroup-manager=disabled is used (or --cgroups=disabled via podman), crun still unconditionally calls libcrun_get_cgroup_mode() early in the container startup path. This function does statfs("/sys/fs/cgroup") and returns an error if the filesystem type is neither CGROUP2_SUPER_MAGIC nor TMPFS_MAGIC.

On systems where /sys/fs/cgroup is not a standard cgroup mount — such as Android with Linux Deploy where it is mounted as sysfs — this causes container creation to fail with:

OCI runtime error: crun: invalid file system type on `/sys/fs/cgroup`

This defeats the purpose of --cgroups=disabled, which exists precisely for environments where cgroups are not properly available.

Root Cause

In libcrun_container_run_internal() (container.c), libcrun_get_cgroup_mode() is called before setup_cgroup_manager(), which is where context->force_no_cgroup is evaluated. The same pattern exists in libcrun_set_mounts() (linux.c), where the cgroup mode is queried unconditionally to determine the unified cgroup path.

Fix

Guard the libcrun_get_cgroup_mode() calls and related cgroup logic with checks for context->force_no_cgroup:

  • src/libcrun/container.c: Skip the cgroup mode detection and the cgroup v1 deprecation warning when force_no_cgroup is set.
  • src/libcrun/linux.c: Skip the cgroup mode detection and unified cgroup path reading in libcrun_set_mounts() when force_no_cgroup is set.

Testing

Added two regression tests in tests/test_cgroup_setup.py:

  • test_cgroup_disabled() — verifies that a foreground container with --cgroup-manager=disabled runs successfully without triggering cgroup filesystem validation.
  • test_cgroup_disabled_detach() — verifies the same for the create+start (detached) code path.

All existing tests continue to pass.

Reproduction

# On a system where /sys/fs/cgroup is not tmpfs or cgroup2 (e.g., Android/Linux Deploy):
sudo podman run -dt --runtime crun --cgroups=disabled --network=host docker.io/library/httpd
# Before fix: OCI runtime error: crun: invalid file system type on `/sys/fs/cgroup`
# After fix: container starts successfully

Signed-off-by: Jindrich Novy jnovy@redhat.com

When --cgroup-manager=disabled (force_no_cgroup) is set, crun should
not attempt to detect the cgroup mode by calling statfs on
/sys/fs/cgroup.  On systems where /sys/fs/cgroup is not mounted as
tmpfs or cgroup2 (e.g. Android with Linux Deploy where it is mounted
as sysfs), this causes a spurious 'invalid file system type' error
even though cgroups are explicitly disabled.

Guard the libcrun_get_cgroup_mode() calls in
libcrun_container_run_internal() and libcrun_set_mounts() with a check
for force_no_cgroup, so the cgroup filesystem type verification and
the cgroup v1 deprecation warning are both skipped when cgroups are
disabled.

Closes: containers#1413

Signed-off-by: Jindrich Novy <jnovy@redhat.com>
@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting /gemini review.

Copy link
Copy Markdown
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

is this enough to work on a system without /sys/fs/cgroup?

If so, LGTM

@giuseppe giuseppe merged commit 8ae50fa into containers:main Apr 1, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crun verify the cgroup file system type even when invoked with --cgroups=disabled

2 participants