Skip to content

bump selinux to v1.15.1, use SetProcessKind - #13395

Merged
mxpv merged 2 commits into
containerd:mainfrom
kolyshkin:selinux-1.15.0
Aug 5, 2026
Merged

mxpv merged 2 commits into
containerd:mainfrom
kolyshkin:selinux-1.15.0

Conversation

@kolyshkin

@kolyshkin kolyshkin commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

This is a draft until oc/selinux v1.15.0 is released; mostly to test opencontainers/selinux#271.

This also includes #13392.

Update: bumped to v1.15.1

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.

Pull request overview

This PR vendors and integrates upcoming github.com/opencontainers/selinux changes (targeting v1.15.0) into containerd, updating CRI SELinux handling to use newer APIs like ChangeLabelType, ReserveLabelV2, and SetCategoryRange, and removing the internal seutil helper.

Changes:

  • Bump github.com/opencontainers/selinux to v1.15.0 and (for now) replace it to github.com/kolyshkin/selinux at a specific pseudo-version for testing.
  • Switch CRI KVM label adjustment to selinux.ChangeLabelType(...) and drop internal/cri/seutil.
  • Update label reservation flow to propagate reservation errors (ReserveLabelV2) and validate category range via SetCategoryRange.

Reviewed changes

Copilot reviewed 8 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vendor/modules.txt Updates vendored module metadata for the selinux bump and replace.
vendor/github.com/opencontainers/selinux/pkg/pwalkdir/pwalkdir.go Sync with upstream vendored changes (incl. Go 1.22 integer-range loop).
vendor/github.com/opencontainers/selinux/go-selinux/selinux.go Adds new public APIs (ChangeLabelType, SetCategoryRange, ReserveLabelV2, etc.).
vendor/github.com/opencontainers/selinux/go-selinux/selinux_stub.go Updates non-Linux stubs to match new upstream API surface.
vendor/github.com/opencontainers/selinux/go-selinux/selinux_linux.go Syncs Linux implementation changes (label reservation semantics, context fallback plumbing, etc.).
vendor/github.com/opencontainers/selinux/go-selinux/label/label_stub.go Removes legacy build tag line in vendored stub.
vendor/github.com/opencontainers/selinux/go-selinux/label/label_linux.go Adjusts InitLabels option parsing and uses ReserveLabelV2 for custom levels.
internal/cri/store/label/label.go Makes the store’s Reserver return errors and wires it to ReserveLabelV2.
internal/cri/store/label/label_test.go Updates tests for the new Reserver func(string) error signature.
internal/cri/store/container/container_test.go Updates test override for the new Reserver signature.
internal/cri/server/service_linux.go Uses selinux.SetCategoryRange instead of assigning CategoryRange directly.
internal/cri/server/podsandbox/helpers_linux.go Replaces seutil.ChangeToKVM with selinux.ChangeLabelType and gates on selinux.GetEnabled().
internal/cri/server/helpers_linux.go Same KVM label update as podsandbox helper, using ChangeLabelType.
internal/cri/seutil/seutil.go Removes the now-redundant SELinux KVM label helper.
go.sum Adds sums for the temporary replacement module.
go.mod Bumps selinux requirement to v1.15.0 and adds a temporary replace directive.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

l, err := seutil.ChangeToKVM(spec.Process.SelinuxLabel)
l, err := selinux.ChangeLabelType(spec.Process.SelinuxLabel, selinux.TypeKVMProcess)
if err != nil {
return fmt.Errorf("failed to get selinux kvm label: %w", err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Potato, potahto...

l, err := seutil.ChangeToKVM(spec.Process.SelinuxLabel)
l, err := selinux.ChangeLabelType(spec.Process.SelinuxLabel, selinux.TypeKVMProcess)
if err != nil {
return fmt.Errorf("failed to get selinux kvm label: %w", err)
Copilot AI review requested due to automatic review settings May 21, 2026 21:56
@kolyshkin kolyshkin changed the title [DRAFT] bump selinux to v1.15.0, use ChangeLabelType bump selinux to v1.15.0, use SetProcessKind May 21, 2026

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.

Pull request overview

Copilot reviewed 8 out of 16 changed files in this pull request and generated 4 comments.

Comment thread internal/cri/server/helpers_linux.go Resolved
Comment thread internal/cri/store/label/label.go Outdated
Comment on lines +60 to +62
if err := s.Reserver(label); err != nil {
return err
}
Comment thread internal/cri/server/helpers_linux.go Resolved
@kolyshkin
kolyshkin marked this pull request as ready for review May 21, 2026 22:02
@kolyshkin kolyshkin changed the title bump selinux to v1.15.0, use SetProcessKind bump selinux to v1.15.1, use SetProcessKind Jun 15, 2026
@kolyshkin

Copy link
Copy Markdown
Contributor Author

Not sure how can I summon the maintainers to please review this one; @thaJeztah halp 🙏🏻

Copilot AI review requested due to automatic review settings June 15, 2026 19:27

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.

Pull request overview

Copilot reviewed 8 out of 16 changed files in this pull request and generated 3 comments.

Comment thread internal/cri/server/helpers_linux.go Resolved
Comment thread internal/cri/store/label/label.go Outdated
Comment on lines +60 to +62
if err := s.Reserver(label); err != nil {
return err
}
@samuelkarp samuelkarp added this to the 2.4 milestone Jun 15, 2026
Comment thread internal/cri/store/label/label.go Outdated

if _, ok := s.levels[level]; !ok {
s.Reserver(label)
if err := s.Reserver(label); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we need to ignore selinux.ErrMCSAlreadyExists here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question. I looked at it before opening this PR, here's my (non-AI generated:)) recap.

It looks like we only call ReserveLabel for when s.levels[level] is non-existent (IOW its refcount is 0), and after the successful reservation we increase the refcount (to 1). So, if Reserve is called twice with the same label, we won't call ReserveLabel and thus won't get ErrMCSAlreadyExists.

This is actually tested by existing tests, e.g. this part in TestAddThenRemove:

          t.Log("should count to two level")
          assert.NoError(store.Reserve("junk:junk:junk:c1,c2"))
          assert.NoError(store.Reserve("junk2:junk2:junk2:c1,c2"))

The same level component ("c1,c2") is reserved twice here. If it were a bare call to selinux.ReserveLabelV2, we would definitely get ErrMCSAlreadyExists error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

actually

NetNS:0x2efe7fd56230 StopCh:0x2efe7fd40960 Stats:<nil> Endpoint:{Address: Version:0}} into store: MCS label already exists"

https://github.com/containerd/containerd/actions/runs/27570881490/job/81562347785?pr=13395#step:8:10802

@djdongjin djdongjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kolyshkin

Copy link
Copy Markdown
Contributor Author

Alas I am on vacation for the next couple of weeks, the options are:

  • wait for me;
  • figure it out;
  • ignore ErrMCSAlreadyExists for now.

I'd go with 3 because this is what was happening before.

Now, this might be a real bug ("reusing the label when we shouldn't" or "forgetting to release the label" or something else) or a dud (we just re-reserve a label and it is completely normal). Have to look deeper to find out.

helsaawy added a commit to microsoft/hcsshim that referenced this pull request Jun 26, 2026
PR #2769 upgraded `github.com/opencontainers/selinux` from `v1.13.1` to
`v1.15.0`.
However, containerd is still on `v1.13.1`, and the version mismatch is
blocking the upgrade of new hcsshim releases
(containerd/containerd#13671).
Upgrading the `selinux` dependency in containerd is currently blocked
(containerd/containerd#13395), so, for now, roll
back the version until the latter PR is merged so their hcsshim
dependency can be updated.

Signed-off-by: Hamza El-Saawy <[email protected]>
helsaawy added a commit to helsaawy/containerd that referenced this pull request Jun 29, 2026
Dependabot PR containerd#13671 is using older tag, which is blocked by `selinux`
update (containerd#13395).
Update hcsshim to version that does not bump the `selinux` package
(which was only updated via dependabot PRs).

Signed-off-by: Hamza El-Saawy <[email protected]>
@djdongjin
djdongjin self-requested a review July 5, 2026 04:55
Copilot AI review requested due to automatic review settings July 21, 2026 23:49
@kolyshkin

Copy link
Copy Markdown
Contributor Author

So I figured it out. The label is actually reserved multiple times:

  1. in selinux.ContainerLabels, called via label.InitLabels, called from these two places:
    (a)

    processLabel, mountLabel, err := label.InitLabels(labelOptions)

    (b)
    return label.InitLabels(labels)

  2. in sandboxStore.Add, for a sandbox.

  3. in containerStore.Add, for every container of a sandbox (same label as in sandbox).

Since a container can either have the same label as the pod or a distinct one, it's hard to fix this properly.

So I'm just ignoring ErrMCSAlreadyExists for now.

Rebased; PTAL @djdongjin @thaJeztah

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.

Pull request overview

Copilot reviewed 8 out of 16 changed files in this pull request and generated no new comments.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment on lines +61 to +64
// The label may already be reserved, e.g. because selinux.ContainerLabels()
// just generated (and reserved) it, or because another container in the
// same pod is reusing the sandbox's label.
if err := s.Reserver(label); err != nil && !errors.Is(err, selinux.ErrMCSAlreadyExists) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thx for the comment; useful!

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jul 23, 2026
Switch away from deprecated functionality.

Signed-off-by: Kir Kolyshkin <[email protected]>
Drop internal/cri/seutil/seutil.go in favor of direct call to newly
introduced selinux.SetProcessKind.

Signed-off-by: Kir Kolyshkin <[email protected]>
Copilot AI review requested due to automatic review settings July 28, 2026 23:24
@kolyshkin

Copy link
Copy Markdown
Contributor Author

Rebased

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.

Pull request overview

Copilot reviewed 8 out of 16 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

internal/cri/store/label/label.go:66

  • The new behavior that treats selinux.ErrMCSAlreadyExists as non-fatal isn't covered by unit tests. Adding a test where Reserver returns selinux.ErrMCSAlreadyExists would ensure this path stays intentional and prevents regressions that would make pod label reuse fail.
	if _, ok := s.levels[level]; !ok {
		// The label may already be reserved, e.g. because selinux.ContainerLabels()
		// just generated (and reserved) it, or because another container in the
		// same pod is reusing the sandbox's label.
		if err := s.Reserver(label); err != nil && !errors.Is(err, selinux.ErrMCSAlreadyExists) {
			return err
		}

@mxpv
mxpv added this pull request to the merge queue Aug 5, 2026
Merged via the queue into containerd:main with commit 4985496 Aug 5, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants