Skip to content

lsm: treat unlabeled_t SELinux context as unlabeled for relabeling - #2368

Open
joelcapitao wants to merge 1 commit into
bootc-dev:mainfrom
joelcapitao:fix-selinux
Open

lsm: treat unlabeled_t SELinux context as unlabeled for relabeling#2368
joelcapitao wants to merge 1 commit into
bootc-dev:mainfrom
joelcapitao:fix-selinux

Conversation

@joelcapitao

Copy link
Copy Markdown
Contributor

Modify has_security_selinux() to return Unlabeled when a file has the unlabeled_t SELinux type. This ensures files created in permissive mode (where the kernel does not apply type transitions) get properly relabeled during bootc install to-filesystem.

Previously, files with unlabeled_t were considered "already labeled" and skipped during relabeling passes, causing SELinux policy mismatches on the final disk image.

Note that /sysroot/boot cannot be relabeled when it is masked by a mounted filesystem (e.g., when osbuild pre-mounts the boot partition). This is acceptable because /sysroot/boot is primarily used as a potential mount point for the boot partition, created by ostree admin init-fs. In the final booted system, /boot is mounted separately and its contents are properly labeled.

Assisted-by: OpenCode (Claude Opus 4.5)

Modify `has_security_selinux()` to return `Unlabeled` when a file has
the `unlabeled_t` SELinux type. This ensures files created in permissive
mode (where the kernel does not apply type transitions) get properly
relabeled during `bootc install to-filesystem`.

Previously, files with `unlabeled_t` were considered "already labeled"
and skipped during relabeling passes, causing SELinux policy mismatches
on the final disk image.

Note that `/sysroot/boot` cannot be relabeled when it is masked by a
mounted filesystem (e.g., when osbuild pre-mounts the boot partition).
This is acceptable because `/sysroot/boot` is primarily used as a
potential mount point for the boot partition, created by
`ostree admin init-fs`. In the final booted system, `/boot` is mounted
separately and its contents are properly labeled.

Assisted-by: OpenCode (Claude Opus 4.5)
@bootc-bot
bootc-bot Bot requested a review from jmarrero August 5, 2026 14:48
Comment thread crates/lib/src/lsm.rs
Comment on lines +267 to +268
// This can happen when files are created with SELinux in permissive mode,
// where the kernel doesn't apply type transitions and assigns unlabeled_t.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think it's true that permissive mode doesn't do type transitions

Comment thread crates/lib/src/lsm.rs
// This can happen when files are created with SELinux in permissive mode,
// where the kernel doesn't apply type transitions and assigns unlabeled_t.
let label = std::str::from_utf8(&buf[..len]).unwrap_or("");
if label.contains(":unlabeled_t:") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not happy about parsing security contexts like this, there's official APIs for this

I also don't want to hardcode unlabeled_t ideally.

Hmmmmmm...I think what's giong on here is the kernel returns this type when the xattr is missing - maybe ideally we can figure out a way to query that state. I bet the stock selinux userspace tooling has code for this.

Comment thread crates/lib/src/lsm.rs
// Check if the label is unlabeled_t - treat it as unlabeled.
// This can happen when files are created with SELinux in permissive mode,
// where the kernel doesn't apply type transitions and assigns unlabeled_t.
let label = std::str::from_utf8(&buf[..len]).unwrap_or("");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Silently discarding non-UTF8 security contexts feels odd, we can just scan bytes

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.

2 participants