Skip to content

Commit 31ec99e

Browse files
committed
apparmor: switch to apparmor to internal capable check for policy management
With LSM stacking calling back into capable to check for MAC_ADMIN for apparmor policy results in asking the other stacked LSMs for MAC_ADMIN resulting in the other LSMs answering based on their policy management. For apparmor policy management we just need to call apparmor's capability fn directly. Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 92de220 commit 31ec99e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

security/apparmor/policy.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,22 @@ static int audit_policy(struct aa_label *label, const char *op,
631631
return error;
632632
}
633633

634+
/* don't call out to other LSMs in the stack for apparmor policy admin
635+
* permissions
636+
*/
637+
static int policy_ns_capable(struct aa_label *label,
638+
struct user_namespace *userns, int cap)
639+
{
640+
int err;
641+
642+
/* check for MAC_ADMIN cap in cred */
643+
err = cap_capable(current_cred(), userns, cap, CAP_OPT_NONE);
644+
if (!err)
645+
err = aa_capable(label, cap, CAP_OPT_NONE);
646+
647+
return err;
648+
}
649+
634650
/**
635651
* aa_policy_view_capable - check if viewing policy in at @ns is allowed
636652
* label: label that is trying to view policy in ns
@@ -662,7 +678,7 @@ bool aa_policy_view_capable(struct aa_label *label, struct aa_ns *ns)
662678
bool aa_policy_admin_capable(struct aa_label *label, struct aa_ns *ns)
663679
{
664680
struct user_namespace *user_ns = current_user_ns();
665-
bool capable = ns_capable(user_ns, CAP_MAC_ADMIN);
681+
bool capable = policy_ns_capable(label, user_ns, CAP_MAC_ADMIN);
666682

667683
AA_DEBUG("cap_mac_admin? %d\n", capable);
668684
AA_DEBUG("policy locked? %d\n", aa_g_lock_policy);

0 commit comments

Comments
 (0)