aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Johansen <john.johansen@canonical.com>2017-01-16 03:42:54 -0500
committerJohn Johansen <john.johansen@canonical.com>2017-01-16 04:18:41 -0500
commitfc1c9fd10a53a17abb3348adb2ec5d29813a0397 (patch)
treeb430294cb54354272638cd4c333c753f8a6c88e5
parent078c73c63fb2878689da334f112507639c72c14f (diff)
apparmor: add ns name to the audit data for policy loads
Signed-off-by: John Johansen <john.johansen@canonical.com>
-rw-r--r--security/apparmor/include/audit.h1
-rw-r--r--security/apparmor/policy.c34
2 files changed, 25 insertions, 10 deletions
diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h
index ba3dfd17f23f..dbfb4a6d72b6 100644
--- a/security/apparmor/include/audit.h
+++ b/security/apparmor/include/audit.h
@@ -113,6 +113,7 @@ struct apparmor_audit_data {
113 void *target; 113 void *target;
114 struct { 114 struct {
115 long pos; 115 long pos;
116 const char *ns;
116 void *target; 117 void *target;
117 } iface; 118 } iface;
118 struct { 119 struct {
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 27d93aa58016..3c5c0b28eac5 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -582,11 +582,23 @@ static int replacement_allowed(struct aa_profile *profile, int noreplace,
582 return 0; 582 return 0;
583} 583}
584 584
585/* audit callback for net specific fields */
586static void audit_cb(struct audit_buffer *ab, void *va)
587{
588 struct common_audit_data *sa = va;
589
590 if (sa->aad->iface.ns) {
591 audit_log_format(ab, " ns=");
592 audit_log_untrustedstring(ab, sa->aad->iface.ns);
593 }
594}
595
585/** 596/**
586 * aa_audit_policy - Do auditing of policy changes 597 * aa_audit_policy - Do auditing of policy changes
587 * @profile: profile to check if it can manage policy 598 * @profile: profile to check if it can manage policy
588 * @op: policy operation being performed 599 * @op: policy operation being performed
589 * @gfp: memory allocation flags 600 * @gfp: memory allocation flags
601 * @nsname: name of the ns being manipulated (MAY BE NULL)
590 * @name: name of profile being manipulated (NOT NULL) 602 * @name: name of profile being manipulated (NOT NULL)
591 * @info: any extra information to be audited (MAYBE NULL) 603 * @info: any extra information to be audited (MAYBE NULL)
592 * @error: error code 604 * @error: error code
@@ -594,19 +606,21 @@ static int replacement_allowed(struct aa_profile *profile, int noreplace,
594 * Returns: the error to be returned after audit is done 606 * Returns: the error to be returned after audit is done
595 */ 607 */
596static int audit_policy(struct aa_profile *profile, int op, gfp_t gfp, 608static int audit_policy(struct aa_profile *profile, int op, gfp_t gfp,
597 const char *name, const char *info, int error) 609 const char *nsname, const char *name,
610 const char *info, int error)
598{ 611{
599 struct common_audit_data sa; 612 struct common_audit_data sa;
600 struct apparmor_audit_data aad = {0,}; 613 struct apparmor_audit_data aad = {0,};
601 sa.type = LSM_AUDIT_DATA_NONE; 614 sa.type = LSM_AUDIT_DATA_NONE;
602 sa.aad = &aad; 615 sa.aad = &aad;
603 aad.op = op; 616 aad.op = op;
617 aad.iface.ns = nsname;
604 aad.name = name; 618 aad.name = name;
605 aad.info = info; 619 aad.info = info;
606 aad.error = error; 620 aad.error = error;
607 621
608 return aa_audit(AUDIT_APPARMOR_STATUS, profile, gfp, 622 return aa_audit(AUDIT_APPARMOR_STATUS, profile, gfp,
609 &sa, NULL); 623 &sa, audit_cb);
610} 624}
611 625
612/** 626/**
@@ -659,11 +673,11 @@ int aa_may_manage_policy(struct aa_profile *profile, struct aa_ns *ns, int op)
659{ 673{
660 /* check if loading policy is locked out */ 674 /* check if loading policy is locked out */
661 if (aa_g_lock_policy) 675 if (aa_g_lock_policy)
662 return audit_policy(profile, op, GFP_KERNEL, NULL, 676 return audit_policy(profile, op, GFP_KERNEL, NULL, NULL,
663 "policy_locked", -EACCES); 677 "policy_locked", -EACCES);
664 678
665 if (!policy_admin_capable(ns)) 679 if (!policy_admin_capable(ns))
666 return audit_policy(profile, op, GFP_KERNEL, NULL, 680 return audit_policy(profile, op, GFP_KERNEL, NULL, NULL,
667 "not policy admin", -EACCES); 681 "not policy admin", -EACCES);
668 682
669 /* TODO: add fine grained mediation of policy loads */ 683 /* TODO: add fine grained mediation of policy loads */
@@ -818,7 +832,7 @@ ssize_t aa_replace_profiles(struct aa_ns *view, void *udata, size_t size,
818 ns = aa_prepare_ns(view, ns_name); 832 ns = aa_prepare_ns(view, ns_name);
819 if (!ns) { 833 if (!ns) {
820 error = audit_policy(__aa_current_profile(), op, GFP_KERNEL, 834 error = audit_policy(__aa_current_profile(), op, GFP_KERNEL,
821 ns_name, 835 NULL, ns_name,
822 "failed to prepare namespace", -ENOMEM); 836 "failed to prepare namespace", -ENOMEM);
823 goto free; 837 goto free;
824 } 838 }
@@ -895,7 +909,7 @@ ssize_t aa_replace_profiles(struct aa_ns *view, void *udata, size_t size,
895 list_del_init(&ent->list); 909 list_del_init(&ent->list);
896 op = (!ent->old && !ent->rename) ? OP_PROF_LOAD : OP_PROF_REPL; 910 op = (!ent->old && !ent->rename) ? OP_PROF_LOAD : OP_PROF_REPL;
897 911
898 audit_policy(__aa_current_profile(), op, GFP_ATOMIC, 912 audit_policy(__aa_current_profile(), op, GFP_ATOMIC, NULL,
899 ent->new->base.hname, NULL, error); 913 ent->new->base.hname, NULL, error);
900 914
901 if (ent->old) { 915 if (ent->old) {
@@ -950,7 +964,7 @@ fail_lock:
950 964
951 /* audit cause of failure */ 965 /* audit cause of failure */
952 op = (!ent->old) ? OP_PROF_LOAD : OP_PROF_REPL; 966 op = (!ent->old) ? OP_PROF_LOAD : OP_PROF_REPL;
953 audit_policy(__aa_current_profile(), op, GFP_KERNEL, 967 audit_policy(__aa_current_profile(), op, GFP_KERNEL, NULL,
954 ent->new->base.hname, info, error); 968 ent->new->base.hname, info, error);
955 /* audit status that rest of profiles in the atomic set failed too */ 969 /* audit status that rest of profiles in the atomic set failed too */
956 info = "valid profile in failed atomic policy load"; 970 info = "valid profile in failed atomic policy load";
@@ -961,7 +975,7 @@ fail_lock:
961 continue; 975 continue;
962 } 976 }
963 op = (!ent->old) ? OP_PROF_LOAD : OP_PROF_REPL; 977 op = (!ent->old) ? OP_PROF_LOAD : OP_PROF_REPL;
964 audit_policy(__aa_current_profile(), op, GFP_KERNEL, 978 audit_policy(__aa_current_profile(), op, GFP_KERNEL, NULL,
965 tmp->new->base.hname, info, error); 979 tmp->new->base.hname, info, error);
966 } 980 }
967free: 981free:
@@ -1036,7 +1050,7 @@ ssize_t aa_remove_profiles(struct aa_ns *view, char *fqname, size_t size)
1036 1050
1037 /* don't fail removal if audit fails */ 1051 /* don't fail removal if audit fails */
1038 (void) audit_policy(__aa_current_profile(), OP_PROF_RM, GFP_KERNEL, 1052 (void) audit_policy(__aa_current_profile(), OP_PROF_RM, GFP_KERNEL,
1039 name, info, error); 1053 NULL, name, info, error);
1040 aa_put_ns(ns); 1054 aa_put_ns(ns);
1041 aa_put_profile(profile); 1055 aa_put_profile(profile);
1042 return size; 1056 return size;
@@ -1047,6 +1061,6 @@ fail_ns_lock:
1047 1061
1048fail: 1062fail:
1049 (void) audit_policy(__aa_current_profile(), OP_PROF_RM, GFP_KERNEL, 1063 (void) audit_policy(__aa_current_profile(), OP_PROF_RM, GFP_KERNEL,
1050 name, info, error); 1064 NULL, name, info, error);
1051 return error; 1065 return error;
1052} 1066}