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

selinux: don't use lsetxattr on /proc/self/fd/%d and bump selinux to v1.10.1 #3889

Closed
wants to merge 2 commits into from

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Apr 1, 2022

  • Syscall lsetxattr always fails with ENOTSUP when it tries to relabel
    /proc/self/fd/%d but in this case we are acutally interested in the
    actual file pointed by the /proc/self/fd/%d not in the symlink
    ( since that was the behavior before ) so use Chcon instead of Relabel
    since Relabel was configured here Relabel: relabel links instead of their targets opencontainers/selinux#173
    to use lsetxattr instead of setxattr.

  • Bump selinux to v1.10.1 to verify if it works

Fixes and replaces: #3875
See: containers/common#994

[NO NEW TESTS NEEDED]: This does not adds new functionality but all existing tests must pass with selinux v.1.10.1 as of now they all break when selinux is bumped to v.1.10.1

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 1, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Apr 1, 2022
lsetxattr always fails with ENOTSUP when it tries to relabel
/proc/self/fd/%d but in this case we are acutally intrested on the
actual file pointed by the `/proc/self/fd/%d` not in the `symlink` so use `Chcon` instead of
`Relabel` since `Relabel` was configured here opencontainers/selinux#173
to use `lsetxattr` instead of `setxattr`.

[NO NEW TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
[NO NEW TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
@flouthoc flouthoc changed the title selinux: don't use lsetxattr on /proc/self/fd/%d selinux: don't use lsetxattr on /proc/self/fd/%d and bump selinux to v1.10.1 Apr 1, 2022
@flouthoc
Copy link
Collaborator Author

flouthoc commented Apr 1, 2022

@rhatdan @giuseppe @nalind @TomSweeneyRedHat PTAL. This should fix selinux issue both in buildah and podman ( containers/podman#13687 )

@@ -33,7 +32,7 @@ func runLabelStdioPipes(stdioPipe [][]int, processLabel, mountLabel string) erro
}
for i := range stdioPipe {
pipeFdName := fmt.Sprintf("/proc/self/fd/%d", stdioPipe[i][0])
if err := label.Relabel(pipeFdName, pipeContext, false); err != nil {
if err := selinux.Chcon(pipeFdName, pipeContext, false); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

label.Relabel ends up calling selinux.Chcon, but it checks if selinux is enabled.

Why do we need this change?

Copy link
Collaborator Author

@flouthoc flouthoc Apr 1, 2022

Choose a reason for hiding this comment

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

@giuseppe Relabel calls Chcon but ends up hard-coding recurse flag to true https://github.com/opencontainers/selinux/blob/main/go-selinux/label/label_linux.go#L169, which is now configured to use lsetxattr( always instead of setxattr ( the change was done here opencontainers/selinux#173 ) and for somereason lsetxattr always gives operation not supported for both rootless and root cases when labeling /proc/self/fd/%d . I think that's because lsetxattr tries to label this special symlink /proc/self/fd/%d but instead it should try to label the actual file like setxattr( used to do before.

Failure is easy to reproduce if you see containers/podman#13687 and #3875

Copy link
Member

Choose a reason for hiding this comment

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

thanks.

What happens now if we try to relabel a real symlink (not the magic /proc/self/fd one)? Do we end up relabelling the file it points to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rhatdan
Copy link
Member

rhatdan commented Apr 1, 2022

Let's concentrate on #3875

I now duplicate the previous behavior, reading the symlink if it exists and added an IsNotExists check, and it seems to fix the problem.

@rhatdan rhatdan closed this Apr 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants