Repository navigation
[1.5] libct: don't reset selinux labels on init error path - #5442
Merged
Merged
Conversation
Both linuxStandardInit.Init and linuxSetnsInit.Init deferred a
selinux.SetKeyLabel("") / selinux.SetExecLabel("") call to reset the
labels on return. These deferred calls are useless: on success the
function ends with execve(2) and never returns, and on failure runc init
exits right after, so there is nothing left to reset.
Worse, they are actively harmful. They run after utils.UnsafeCloseFrom,
which closes every file descriptor that must not leak into the
container, including the procfs handle cached internally by libpathrs.
Writing the label then re-opens /proc, and libpathrs aborts the whole
process:
thread '<unnamed>' (1) panicked at src/procfs.rs:349:22:
cached procfs handle should be valid: [...] Bad file descriptor
SIGABRT: abort
So a plain execve failure (a bad ELF, or an exec denied by policy) was
reported as a Rust panic plus a Go stack dump instead of the actual
error.
Drop the deferred calls, and add a test case.
Fixes opencontainers#5438
(cherry picked from commit 1056e68)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
lifubang
approved these changes
Sep 4, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #5439 to release-1.5. Original description follows.
Fixes #5438.
Both
linuxStandardInit.InitandlinuxSetnsInit.Initdeferred aselinux.SetKeyLabel("")/selinux.SetExecLabel("")call to reset the labelson return. These deferred calls are useless: on success the function ends with
execve(2)and never returns, and on failurerunc initexits right after, sothere is nothing left to reset.
Worse, they are actively harmful. They run after
utils.UnsafeCloseFrom, whichcloses every file descriptor that must not leak into the container, including
the procfs handle cached internally by libpathrs. Writing the label then
re-opens /proc, and libpathrs aborts the whole process:
So a plain
execvefailure (a bad ELF, or an exec denied by policy) wasreported as a Rust panic plus a Go stack dump instead of the actual error.
Reproducer from the issue, before:
after:
We do have tests for a failing
execve(runc run [execve error]inrun.bats, and its counterpart in exec.bats), but they do not set
process.selinuxLabel, so no deferred label reset is registered. Theselinux.bats tests do set a label, but all of them run a working binary,
so
Initnever returns. The new test covers the intersection.The test case before the fix is being tested in #5440.