Repository navigation
Conversation
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.
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_capableandcred_has_capabilityof hooks.c of Linux. This part does not depend on #752.mprotectwaits for #752.Changes
fs/rk-vfs, thecapablehook:security_capableof Linux.security::capableandsecurity::capable_lsmpass it to the modules.Cred::ns_capablegives the namespace of the request to the modules, also when the process owns the namespace.Cred::has_capgives the namespace of the process.CAP_SYS_ADMINof AppArmor foruserns_creategives the namespace of the process.sec/rk-lsm-selinux:task.rs:capable, asselinux_capable: the classescapabilityandcapability2for the first user namespace, elsecap_usernsandcap2_userns.cred_has_capabilitynow takes theCAP_OPT_*bits. WithCAP_OPT_NOAUDITthere is no record. The record hascapability=N, as Linux.has_cap_mac_admin, as Linux: the check of the capability module and of SELinux forCAP_MAC_ADMINin the first user namespace. A read of the label (getxattrofsecurity.selinux) does the check without a record. A write of an unknown context to an xattr or tofscreatedoes the check with a record.lib.rs: the hookcapable.tests/rk_test.conf: the classescapability2,cap_usernsandcap2_userns. Each domain gets its capabilities in the first user namespace withoutsys_time,sys_tty_configandwake_alarm, and no capability in the other user namespaces. The binariesrk_test.24.bin,rk_test.33.binandrk_test.35.binare made again with checkpolicy 3.9.tests/user/init.c:test_selinuxchecks in enforcing mode that a set of the clock givesEPERM, that asethostnameworks, and that a new UTS namespace in a new user namespace givesEPERM. The log has the exact records of the denials ofsys_time(classcapability) andsys_admin(classcap_userns).Not in this PR:
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 --checkof the changed files: pass.cargo test -p rk-lsm-selinuxon 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 throughCred::capableandCred::ns_capable.cargo test -p rk-lsm-apparmor -p rk-vfson server2: 165 passed (38 and 127 in the two crates). The test of the capability module inrk-vfsgives the new argument.cargo buildof the x86_64 and the arm64 kernels: pass.cargo xtask boot-test selinuxandRK_AARCH64_TESTS=selinux cargo xtask boot-test aarch64made the images on server2. The QEMU commands of xtask then ran them:sec/rk-lsm-apparmor/src/ns.rsand before two fixes of the unit tests. These changes do not change the kernel code.cargo xtask boot-test apparmorandcargo xtask boot-test initdid not run. The change of AppArmor and of the capability module is only the new argument of the hook.task::cred_has_capability0xc8 bytes,task::capable0x38,task::has_cap_mac_admin0x28,security::capable_lsm0x58.The full gate did not run.