Skip to content

SELinux: the check of the capabilities - #828

Merged
tamnd merged 2 commits into
mainfrom
sel-4j
Nov 23, 2026
Merged

tamnd merged 2 commits into
mainfrom
sel-4j

Conversation

@tamnd

@tamnd tamnd commented Nov 23, 2026

Copy link
Copy Markdown
Owner

This PR is part #13 of #540 (SELinux), the ninth part of the permission checks. The capabilities now have the check of SELinux, as selinux_capable and cred_has_capability of hooks.c of Linux. This part does not depend on #752. mprotect waits for #752.

Changes

  • fs/rk-vfs, the capable hook:
    • The hook now gets the user namespace of the request, as security_capable of Linux. security::capable and security::capable_lsm pass it to the modules.
    • Cred::ns_capable gives the namespace of the request to the modules, also when the process owns the namespace. Cred::has_cap gives the namespace of the process.
    • The capability module and AppArmor take the new argument and do not use it. The check of CAP_SYS_ADMIN of AppArmor for userns_create gives the namespace of the process.
  • sec/rk-lsm-selinux:
    • task.rs:
      • capable, as selinux_capable: the classes capability and capability2 for the first user namespace, else cap_userns and cap2_userns.
      • cred_has_capability now takes the CAP_OPT_* bits. With CAP_OPT_NOAUDIT there is no record. The record has capability=N, as Linux.
      • has_cap_mac_admin, as Linux: the check of the capability module and of SELinux for CAP_MAC_ADMIN in the first user namespace. A read of the label (getxattr of security.selinux) does the check without a record. A write of an unknown context to an xattr or to fscreate does the check with a record.
    • lib.rs: the hook capable.
    • tests/rk_test.conf: the classes capability2, cap_userns and cap2_userns. Each domain gets its capabilities in the first user namespace without sys_time, sys_tty_config and wake_alarm, and no capability in the other user namespaces. The binaries rk_test.24.bin, rk_test.33.bin and rk_test.35.bin are made again with checkpolicy 3.9.
  • tests/user/init.c: test_selinux checks in enforcing mode that a set of the clock gives EPERM, that a sethostname works, and that a new UTS namespace in a new user namespace gives EPERM. The log has the exact records of the denials of sys_time (class capability) and sys_admin (class cap_userns).
  • The CHANGELOG has an entry for this PR.

Not in this PR:

  • The System V IPC checks and the socket checks. They come in later parts.

Tests

The load average on server2 was 3.54, 7.15, 8.57 at the start of the build, and 22.06, 18.52, 13.18 at the start of the second unit test run.

  • rustfmt --check of the changed files: pass.
  • cargo test -p rk-lsm-selinux on server2: 56 passed. The new test checks the classes of the two kinds of user namespaces, the rules, the capabilities that are not valid, CAP_OPT_NOAUDIT, the permissive mode and the path through Cred::capable and Cred::ns_capable.
  • cargo test -p rk-lsm-apparmor -p rk-vfs on server2: 165 passed (38 and 127 in the two crates). The test of the capability module in rk-vfs gives the new argument.
  • cargo build of the x86_64 and the arm64 kernels: pass.
  • The selinux boot test: cargo xtask boot-test selinux and RK_AARCH64_TESTS=selinux cargo xtask boot-test aarch64 made the images on server2. The QEMU commands of xtask then ran them:
    • x86_64 on server1, with no NIC: pass, 145 of 145 checks, QEMU status 33. The load average was 0.31, 0.15, 0.12.
    • arm64 on server2: pass, 145 of 145 checks. The load average was 7.64, 7.28, 7.83.
    • The images were made before a change of the format of sec/rk-lsm-apparmor/src/ns.rs and before two fixes of the unit tests. These changes do not change the kernel code.
    • The log has only the two expected capability denials, so the other checks of the test get their capabilities from the new rules.
  • cargo xtask boot-test apparmor and cargo xtask boot-test init did not run. The change of AppArmor and of the capability module is only the new argument of the hook.
  • The stack frames on x86_64: task::cred_has_capability 0xc8 bytes, task::capable 0x38, task::has_cap_mac_admin 0x28, security::capable_lsm 0x58.

The full gate did not run.

The capable hook gets the user namespace of the request, as on Linux.
SELinux checks a capability in the class capability or capability2, or
in cap_userns or cap2_userns for another user namespace, as
selinux_capable and cred_has_capability. The record has capability=N.
The test policy has the new classes and the rules of the capabilities.
@tamnd tamnd added kind/feature New behavior or a new part. area/security LSMs, seccomp, Landlock, capabilities and mitigations. area/testing The test tools, the fuzzers and the compat harness. labels Nov 23, 2026
@tamnd
tamnd merged commit 737cefb into main Nov 23, 2026
6 of 7 checks passed
@tamnd
tamnd deleted the sel-4j branch November 23, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security LSMs, seccomp, Landlock, capabilities and mitigations. area/testing The test tools, the fuzzers and the compat harness. kind/feature New behavior or a new part.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant