Hi, This is series 3 of 3:
1. fix Landlock mediation of commoncap's capability checks; 2. fix PR_SET_SECUREBITS mediation and add focused Landlock tests; * 3. fix Landlock mediation of capabilities guarding LSM policies. This series applies on top of series 2: https://patch.msgid.link/[email protected] AppArmor, Smack and SELinux deliberately check the capabilities that guard their own policy with cap_capable() instead of capable(), so that other LSMs do not have to authorize them: - commit db59000ab760 ("selinux: only invoke capabilities and selinux for CAP_MAC_ADMIN checks"); - commit f28e783ff668 ("Smack: Use cap_capable in privilege check"); - commit 31ec99e13346 ("apparmor: switch to apparmor to internal capable check for policy management"). However, LANDLOCK_PERMISSION_CAPABILITY_USE, merged for v7.4, restricts capability use in general through the capable hook, so a domain that denies CAP_MAC_ADMIN can still load AppArmor policy, change a file's Smack label, or set SELinux contexts unknown to the loaded policy. Patch 1 adds security_capable_lsm(), which these LSMs call instead of cap_capable(). It checks the capability with commoncap, then calls a new capable_lsm hook with the LSM_ID_* of the LSM whose policy the capability guards. LSMs that only implement the capable hook still do not see these checks. Patch 2 implements the hook in Landlock, patches 3 to 5 switch AppArmor, Smack and SELinux to the new helper, and patch 6 adds tests. Calling the other LSMs' capable hooks instead, possibly with a new CAP_OPT_* flag, would change what the capable hook sees for its current users, including BPF LSM programs, and would require every MAC LSM to ignore these checks. The new hook keeps the choice of the commits above by default and follows the hook guidelines. The trade-off is that an LSM restricting capability use in general needs to implement both hooks, as the kerneldoc says. As the capable hook, the new hook can be called in atomic context and with another task's credentials (Smack's SIGIO check and ptrace rule). Smack passes CAP_OPT_NONE, so Landlock logs every denial of these capabilities, including for the override checks that some Smack hooks make before their label rules. The new tests are skipped unless Smack or AppArmor is active. With lsm=landlock,smack and lsm=landlock,apparmor, they fail without these patches and pass with them. SELinux only checks CAP_MAC_ADMIN this way with a loaded policy, so it is only build- and boot-tested. Paul, an Acked-by for the LSM and SELinux patches, and for taking this series through the Landlock tree, would be welcome. Stephen, a review of the LSM and SELinux patches would be welcome. John, a review of the AppArmor patch would be welcome. Casey, a review of the Smack patch would be welcome. KP and Matt, a review of the new BPF LSM attach point would be welcome. Changes since v1: https://patch.msgid.link/[email protected] - Fix the AppArmor test for users without the root UID or GID (reported by Sashiko). Regards, Mickaël Salaün (6): lsm: Add a capable_lsm hook for capabilities guarding an LSM's policy landlock: Restrict capabilities guarding other LSMs' policies apparmor: Use security_capable_lsm() for policy capabilities smack: Use security_capable_lsm() for privilege checks selinux: Use security_capable_lsm() for CAP_MAC_ADMIN checks selftests/landlock: Test capabilities guarding other LSMs' policies include/linux/lsm_hook_defs.h | 2 + include/linux/security.h | 9 + security/apparmor/domain.c | 9 +- security/apparmor/policy.c | 7 +- security/landlock/cap.c | 23 ++ security/security.c | 47 ++++ security/selinux/hooks.c | 3 +- security/smack/smack_access.c | 3 +- tools/testing/selftests/landlock/cap_test.c | 240 +++++++++++++++++++- tools/testing/selftests/landlock/common.h | 2 + 10 files changed, 331 insertions(+), 14 deletions(-) base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb prerequisite-patch-id: 365071039dd2be439f67707944d12edbe1422d60 prerequisite-patch-id: 021705fb5147cdc8edcac9dbe53c06b854cf976a prerequisite-patch-id: 1dfd782b28feeac47423e702764778031b850d6c prerequisite-patch-id: 0bf745b08b99168d266461ef5b0b943a2b71eceb prerequisite-patch-id: ad96449ac2b66342bdc171582d400276372ce386 prerequisite-patch-id: 39d6ce2bdfc170b545eb2d275ab781e15c9e887a prerequisite-patch-id: 8b180590cb598fc5be4aa403be233b80e0de8dcd prerequisite-patch-id: e56fbdef4bd6316e80e50ec8e8493ffb707dc76d -- 2.56.0
