Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2] runc delete: fix for rootless cgroup + ro cgroupfs #4531

Merged
merged 4 commits into from
Nov 15, 2024

Conversation

lifubang
Copy link
Member

@lifubang lifubang commented Nov 13, 2024

Backport:


This is an alternative to #4520.


An issue with runc 1.2.0 was reported to buildkit and then here (#4518),
in which runc delete returns with an error, with the log saying:

unable to destroy container: unable to remove container's cgroup: open /sys/fs/cgroup/snschvixiy3s74w74fjantrdg: no such file or directory

Apparently, what happens is runc is running with no cgroup access
(because /sys/fs/cgroup is mounted read-only). In this case error to
create a cgroup path (in runc create/run) is ignored, but cgroup removal
(in runc delete) is not.

This is caused by commit d3d7f7d, which changes the cgroup removal
logic in RemovePath, and contains a bug. In the current code, if the
initial rmdir has failed (in this case with EROFS), but the subsequent
os.ReadDir returns ENOENT, that error it is ultimately returned
(instead of being ignored -- since the path does not exist, there is
nothing to remove).

This PR fixes the issue in 3 commits:

  1. A minimal but sufficient fix for the issue, targeted for quick review and backport to v1.2.2.
  2. An improvement to RemovePath logic (originally suggested by @thaJeztah here
  3. An improvement to RemovePath comments, better explaining what's going on.

Only the first commit is changing the logic and fixing the issue -- the rest is mostly
cosmetic and "nice to have".

Fixes: #4518.

TODO: add a test case.

An issue with runc 1.2.0 was reported to buildkit, in which
runc delete returns with an error, with the log saying:

> unable to destroy container: unable to remove container's cgroup: open /sys/fs/cgroup/snschvixiy3s74w74fjantrdg: no such file or directory

Apparently, what happens is runc is running with no cgroup access
(because /sys/fs/cgroup is mounted read-only). In this case error to
create a cgroup path (in runc create/run) is ignored, but cgroup removal
(in runc delete) is not.

This is caused by commit d3d7f7d, which changes the cgroup removal
logic in RemovePath. In the current code, if the initial rmdir has
failed (in this case with EROFS), but the subsequent os.ReadDir returns
ENOENT, it is returned (instead of being ignored -- as the path does not
exist and so there is nothing to remove).

Here is the minimal fix for the issue.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit db59489)
Signed-off-by: lfbzhm <lifubang@acmcoder.com>
If the sub-cgroup RemovePath has failed for any reason, return the
error right away. This way, we don't have to check for err != nil
before retrying rmdir.

This is a cosmetic change and should not change any functionality.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 12e06a7)
Signed-off-by: lfbzhm <lifubang@acmcoder.com>
Let's explain in greater details what's happening here and why.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit ba3d026)
Signed-off-by: lfbzhm <lifubang@acmcoder.com>
@lifubang lifubang added regression backport/1.2-pr A backport PR to release-1.2 labels Nov 13, 2024
@lifubang lifubang added this to the 1.2.2 milestone Nov 13, 2024
@kolyshkin
Copy link
Contributor

Can we please add a backport of #4526 here (once it's merged)? I saw #4527 but logically it belongs here.

@kolyshkin kolyshkin mentioned this pull request Nov 13, 2024
@lifubang
Copy link
Member Author

Can we please add a backport of #4526 here (once it's merged)? I saw #4527 but logically it belongs here.

Added, #4527 is used to verify the test is correct or not.

Signed-off-by: lfbzhm <lifubang@acmcoder.com>
(cherry picked from commit 119111a)
Signed-off-by: lfbzhm <lifubang@acmcoder.com>
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

One nit: PR description does not mention #4526 backport.

Otherwise LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit 1b42ebc into opencontainers:release-1.2 Nov 15, 2024
40 checks passed
@lifubang lifubang deleted the backport-4523 branch November 15, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.2-pr A backport PR to release-1.2 regression
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants