Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Selinux Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-selinux-knowledge-patch)
---
name: selinux-knowledge-patch
description: SELinux
version: null
license: MIT
metadata:
author: Nevaberry
---
# SELinux Knowledge Patch
Load this skill when working on SELinux userspace builds, relabeling,
policy compilation, container policy, distribution activation, or MLS
administration. Use the references for complete guidance and examples.
## Reference index
| Reference | Topics |
| --- | --- |
| [Userspace tools and relabeling](references/userspace-tooling.md) | Build options, Python dependencies, file contexts, relabeling, policy capabilities, CIL validation and conversion, helper execution |
| [Container policy](references/container-policy.md) | Runtime ptrace, overlay storage labels, Incus, Udica templates, confined users |
| [Distribution policy and activation](references/distribution-policy.md) | Tumbleweed installation and upgrades, SLE Micro policy and relabeling, SLES policy and boot settings |
| [RHEL MLS administration](references/rhel-mls-and-upgrade.md) | MLS compatibility, active ranges, SSH roles, user clearance, file classification, administrative separation, secure terminals |
## Breaking changes and compatibility checks
### Removed options and rejected policy syntax
`sandbox` and `seunshare` dropped `-k` and `--kill`.
Use `killall -Z` to select processes by SELinux context.
`checkpolicy` rejects the legacy `fscon` statement.
libsepol requires at least one permission in a CIL class-permission expression.
Stricter validation of MLS ranges and levels means some policies accepted by
earlier releases can fail validation.
### Relabel paths and hard links
Use paths with real directory components in `setfiles` and `seunshare`
arguments and in `restorecond` configuration: intermediate symlinks can now
prevent those tools from reaching the target.
With `SELINUX_RESTORECON_REALPATH`, `selinux_restorecon(3)` resolves
intermediate symlinks in the initial path, as `restorecon` does.
`restorecond` always enables `SELINUX_RESTORECON_SKIP_MULTILINK`, including
when watching home directories or `/tmp`, and skips files with multiple hard links.
### Changed contexts, booleans, and helper arguments
Corrected precedence of literal entries in `file_contexts.local` can change
the selected context when a local literal entry overlaps another definition.
Corrected file-context path substitution order can change contexts for paths
affected by overlapping substitutions.
Deleting SELinux boolean customizations with `semanage` also resets active
boolean values to their policy defaults.
Affected helper calls in `sandbox` and `seunshare` pass arguments directly
to the executable; shell metacharacters in those arguments are literal.
### Python build requirements
`audit2why` requires Python 3.
The libselinux and Python builds, including updated `pywrap` targets, use the
system Python 3 `build` module.
The libselinux Python module and `sepolicy` Python build disable isolation;
their build dependencies must be available in the build environment.
## Relabeling and policy-store operations
### Restore user and role, or disable associations
Use `setfiles -U` to update the SELinux user and role fields along with type.
Use `setfiles -A` to disable `SELINUX_RESTORECON_ADD_ASSOC` during relabeling.
```console
setfiles -U /etc/selinux/targeted/contexts/files/file_contexts /srv/app
setfiles -A /etc/selinux/targeted/contexts/files/file_contexts /srv/app
```
`restorecon` can report how many files it relabeled. It logs relabeling errors
on read-only filesystems and continues, allowing recursive relabeling to
proceed past read-only Btrfs subvolumes.
### Run the relabel daemon under a supervisor
Use `restorecond -F` to keep the daemon in the foreground.
The supplied `restorecond.service` uses this option.
### Select policy-store settings
The `relabel_store` option in `semanage.conf` controls policy-store relabeling.
Use `semodule -g PATH` or `semodule --config=PATH` to select an alternate
semanage configuration file for an invocation.
```console
semodule --config=/path/to/semanage.conf -l
```
## Policy compilation and validation
Use `secilcheck` to verify that an already compiled SELinux policy satisfies
`neverallow` assertions supplied in CIL.
libsepol accepts multiple `policycap` statements. The supported capabilities
below have these uses; see the userspace reference for version attribution.
| Capability | Use |
| --- | --- |
| `netif_wildcard` | Wildcard interface names in `netifcon` rules compiled by `checkpolicy` |
| `genfs_seclabel_wildcard` | Wildcard matching of `genfscon` paths |
| `functionfs_seclabel` | FunctionFS labeling |
| `memfd_class` | A dedicated SELinux object class for memfd files |
| `bpf_token_perms` | BPF token permissions |
Policies can associate a type attribute with another type attribute.
libsepol handles type attributes correctly in rules assigning types to roles.
`secilc` corrects the long spelling of its attribute expansion size option;
build scripts can use the short form `-X`.
## Userspace builds and formatting
Set `DISABLE_SHARED=y` to build SELinux userspace without shared libraries.
```console
make DISABLE_SHARED=y
```
Use libselinux's `EXTRA_LD_FLAGS` make variable to pass `--undefined-version`
to `lld` in musl/LLVM builds.
New patches must follow the tree's `.clang-format` rules.
Run `make check-format` to check formatting or `make format` to apply it.
## Container policy checks
The policy's `ptrace` allow rule for `container_runtime_domain` applies only
when `deny_ptrace` is off.
New `overlay-containers` and `overlay2-containers` directories covered by the
storage transitions receive `container_ro_file_t` at creation.
The container policy includes Incus file contexts and installs the `container_u`
SELinux user description on systems with confined SELinux users.
The container-selinux `udica-templates/` directory supplies templates for
deploying Udica-generated policies on OpenShift nodes without installing
Udica on every node.
## Distribution-specific activation
New Tumbleweed ISO installations default to SELinux enforcing starting with
snapshot `20250211`, with AppArmor offered as a manual choice. The minimalVM
image also enables SELinux by default. Existing installations retain the LSM
selected by their configuration after upgrading to that snapshot.
Leap 15.x uses its own installation defaults.
SLE Micro 6.0 includes SELinux by default in YaST installations and prebuilt
images and ships and supports the `targeted` policy.
After re-enabling SELinux on SLE Micro, create `/etc/selinux/.autorelabel`
before rebooting to relabel files changed while SELinux was disabled.
SLES 15 SP7 ships and supports the SELinux framework and tools.
Build a site-specific policy for production; use policies from openSUSE's
`security:/SELinux_legacy` repository only for testing.
With a policy installed, add `lsm=selinux,bpf selinux=1` to
`GRUB_CMDLINE_LINUX_DEFAULT` in `/etc/default/grub`, rebuild the GRUB 2
configuration, and reboot with the initial `SELINUX=permissive` setting in
`/etc/selinux/config`. See the distribution reference for the commands.
## RHEL MLS administration
Use the RHEL 10 MLS policy on hosts without the X Window System.
It omits the unconfined module, so processes running as `root` are confined too.
RHEL's MLS policy permits writes only at the current sensitivity, the lower
bound of the process's active range. A process at `s1-s2` can read through
`s1` and write at `s1`, subject to ordinary file permissions and type enforcement.
Create confined users with MLS active. The MLS reference gives the commands
for setting `staff_u` levels and ranges, regenerating home contexts, and
pinning an `opsuser` login to `s1`.
From a secure terminal, `newrole -l s1` in a shell at `s0-s2` opens a shell at
`s1-s2`, retaining the upper bound. Use `exit` to return to the original range.
The `ssh_sysadm_login` boolean controls SSH login in `sysadm_r`. After
switching to MLS, log in as `root` in `staff_r`, run `newrole -r sysadm_r`,
and then enable the boolean.
The enabled-by-default `sysadm_secadm` module gives `sysadm_r` security
administration rights. Before disabling it, give a designated `staff_u` login
a `sudoers` rule for `secadm_r`; log in directly, use `sudo -i`, and verify
`secadm_r:secadm_t` before running `semodule -d sysadm_secadm` from that shell.
See the MLS reference for the rule, secure-terminal setup, persistent file
classification, and `mlsfilewrite` behavior.