AppArmor checks CAP_MAC_ADMIN for policy management and CAP_MAC_OVERRIDE
for unconfined stacking with cap_capable() instead of capable(), so that
other stacked LSMs do not have to authorize them.  This also lets a
process in a Landlock domain that denies CAP_MAC_ADMIN manage AppArmor
policy, and one that denies CAP_MAC_OVERRIDE avoid the stacking
restriction on unconfined profile changes.

Commit 31ec99e13346 ("apparmor: switch to apparmor to internal capable
check for policy management") made this choice for CAP_MAC_ADMIN.

Switch these checks to security_capable_lsm(), which keeps this choice
for LSMs that only implement the capable hook.  policy_ns_capable()
still makes its own aa_capable() check.  Update the comments that
described these checks.

Cc: Georgia Garcia <[email protected]>
Cc: Günther Noack <[email protected]>
Cc: John Johansen <[email protected]>
Cc: Paul Moore <[email protected]>
Fixes: 97c8386f1d74 ("landlock: Enforce capability restrictions")
Signed-off-by: Mickaël Salaün <[email protected]>
---
 security/apparmor/domain.c | 9 +++++----
 security/apparmor/policy.c | 7 ++++---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index af9e8431e3ea..d2c111783457 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -884,11 +884,12 @@ static bool is_profile_priv_restricted_to_stack(const 
struct cred *subj_cred,
 {
        if (profile_unconfined(profile) && profile == profile->ns->unconfined &&
            aa_unprivileged_unconfined_restricted &&
-           /* cap_capable returns false (0) if true, hence true here means
-            * doesn't have capability and the stack will be restricted
+           /* security_capable_lsm() returns 0 if CAP_MAC_OVERRIDE is granted,
+            * otherwise the stack will be restricted
             */
-           cap_capable(current_cred(), &init_user_ns, CAP_MAC_OVERRIDE,
-                       CAP_OPT_NOAUDIT))
+           security_capable_lsm(current_cred(), &init_user_ns,
+                                CAP_MAC_OVERRIDE, CAP_OPT_NOAUDIT,
+                                LSM_ID_APPARMOR))
                return true;
        return false;
 }
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 63f7821b4dff..ba162d921805 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -876,8 +876,8 @@ static int audit_policy(struct aa_label *subj_label, const 
char *op,
        return error;
 }
 
-/* don't call out to other LSMs in the stack for apparmor policy admin
- * permissions
+/* don't ask other LSMs' capable hooks about apparmor policy admin
+ * permissions, only LSMs restricting capability use through capable_lsm
  */
 static int policy_ns_capable(const struct cred *subj_cred,
                             struct aa_label *label,
@@ -886,7 +886,8 @@ static int policy_ns_capable(const struct cred *subj_cred,
        int err;
 
        /* check for MAC_ADMIN cap in cred */
-       err = cap_capable(subj_cred, userns, cap, CAP_OPT_NONE);
+       err = security_capable_lsm(subj_cred, userns, cap, CAP_OPT_NONE,
+                                  LSM_ID_APPARMOR);
        if (!err)
                err = aa_capable(subj_cred, label, cap, CAP_OPT_NONE);
 
-- 
2.56.0


Reply via email to