diff options
author | John Johansen <john.johansen@canonical.com> | 2013-02-18 19:10:34 -0500 |
---|---|---|
committer | John Johansen <john.johansen@canonical.com> | 2013-04-28 03:37:13 -0400 |
commit | a4987857d2c958b93b2faafe0811eea1a63ff59a (patch) | |
tree | aa140446d01ddecc209415720ef77dc9c7777ca2 | |
parent | 180a6f5965a49535a7704c07691a6d1209904971 (diff) |
apparmor: remove sid from profiles
The sid is not going to be a direct property of a profile anymore, instead
it will be directly related to the label, and the profile will pickup
a label back reference.
For null-profiles replace the use of sid with a per namespace unique
id.
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Kees Cook <kees@ubuntu.com>
-rw-r--r-- | security/apparmor/include/policy.h | 4 | ||||
-rw-r--r-- | security/apparmor/include/sid.h | 4 | ||||
-rw-r--r-- | security/apparmor/policy.c | 23 | ||||
-rw-r--r-- | security/apparmor/policy_unpack.c | 1 |
4 files changed, 11 insertions, 21 deletions
diff --git a/security/apparmor/include/policy.h b/security/apparmor/include/policy.h index 95979c431e26..b25491a3046a 100644 --- a/security/apparmor/include/policy.h +++ b/security/apparmor/include/policy.h | |||
@@ -105,6 +105,7 @@ struct aa_ns_acct { | |||
105 | * @acct: accounting for the namespace | 105 | * @acct: accounting for the namespace |
106 | * @unconfined: special unconfined profile for the namespace | 106 | * @unconfined: special unconfined profile for the namespace |
107 | * @sub_ns: list of namespaces under the current namespace. | 107 | * @sub_ns: list of namespaces under the current namespace. |
108 | * @uniq_null: uniq value used for null learning profiles | ||
108 | * | 109 | * |
109 | * An aa_namespace defines the set profiles that are searched to determine | 110 | * An aa_namespace defines the set profiles that are searched to determine |
110 | * which profile to attach to a task. Profiles can not be shared between | 111 | * which profile to attach to a task. Profiles can not be shared between |
@@ -127,6 +128,7 @@ struct aa_namespace { | |||
127 | struct aa_ns_acct acct; | 128 | struct aa_ns_acct acct; |
128 | struct aa_profile *unconfined; | 129 | struct aa_profile *unconfined; |
129 | struct list_head sub_ns; | 130 | struct list_head sub_ns; |
131 | atomic_t uniq_null; | ||
130 | }; | 132 | }; |
131 | 133 | ||
132 | /* struct aa_policydb - match engine for a policy | 134 | /* struct aa_policydb - match engine for a policy |
@@ -148,7 +150,6 @@ struct aa_policydb { | |||
148 | * @rename: optional profile name that this profile renamed | 150 | * @rename: optional profile name that this profile renamed |
149 | * @xmatch: optional extended matching for unconfined executables names | 151 | * @xmatch: optional extended matching for unconfined executables names |
150 | * @xmatch_len: xmatch prefix len, used to determine xmatch priority | 152 | * @xmatch_len: xmatch prefix len, used to determine xmatch priority |
151 | * @sid: the unique security id number of this profile | ||
152 | * @audit: the auditing mode of the profile | 153 | * @audit: the auditing mode of the profile |
153 | * @mode: the enforcement mode of the profile | 154 | * @mode: the enforcement mode of the profile |
154 | * @flags: flags controlling profile behavior | 155 | * @flags: flags controlling profile behavior |
@@ -184,7 +185,6 @@ struct aa_profile { | |||
184 | 185 | ||
185 | struct aa_dfa *xmatch; | 186 | struct aa_dfa *xmatch; |
186 | int xmatch_len; | 187 | int xmatch_len; |
187 | u32 sid; | ||
188 | enum audit_mode audit; | 188 | enum audit_mode audit; |
189 | enum profile_mode mode; | 189 | enum profile_mode mode; |
190 | u32 flags; | 190 | u32 flags; |
diff --git a/security/apparmor/include/sid.h b/security/apparmor/include/sid.h index 020db35c3010..513ca0e48965 100644 --- a/security/apparmor/include/sid.h +++ b/security/apparmor/include/sid.h | |||
@@ -16,7 +16,9 @@ | |||
16 | 16 | ||
17 | #include <linux/types.h> | 17 | #include <linux/types.h> |
18 | 18 | ||
19 | struct aa_profile; | 19 | /* sid value that will not be allocated */ |
20 | #define AA_SID_INVALID 0 | ||
21 | #define AA_SID_ALLOC AA_SID_INVALID | ||
20 | 22 | ||
21 | u32 aa_alloc_sid(void); | 23 | u32 aa_alloc_sid(void); |
22 | void aa_free_sid(u32 sid); | 24 | void aa_free_sid(u32 sid); |
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c index 813200384d97..13fc9efddd5d 100644 --- a/security/apparmor/policy.c +++ b/security/apparmor/policy.c | |||
@@ -87,7 +87,6 @@ | |||
87 | #include "include/policy.h" | 87 | #include "include/policy.h" |
88 | #include "include/policy_unpack.h" | 88 | #include "include/policy_unpack.h" |
89 | #include "include/resource.h" | 89 | #include "include/resource.h" |
90 | #include "include/sid.h" | ||
91 | 90 | ||
92 | 91 | ||
93 | /* root profile namespace */ | 92 | /* root profile namespace */ |
@@ -292,7 +291,6 @@ static struct aa_namespace *alloc_namespace(const char *prefix, | |||
292 | if (!ns->unconfined) | 291 | if (!ns->unconfined) |
293 | goto fail_unconfined; | 292 | goto fail_unconfined; |
294 | 293 | ||
295 | ns->unconfined->sid = aa_alloc_sid(); | ||
296 | ns->unconfined->flags = PFLAG_UNCONFINED | PFLAG_IX_ON_NAME_ERROR | | 294 | ns->unconfined->flags = PFLAG_UNCONFINED | PFLAG_IX_ON_NAME_ERROR | |
297 | PFLAG_IMMUTABLE; | 295 | PFLAG_IMMUTABLE; |
298 | 296 | ||
@@ -303,6 +301,8 @@ static struct aa_namespace *alloc_namespace(const char *prefix, | |||
303 | */ | 301 | */ |
304 | ns->unconfined->ns = aa_get_namespace(ns); | 302 | ns->unconfined->ns = aa_get_namespace(ns); |
305 | 303 | ||
304 | atomic_set(&ns->uniq_null, 0); | ||
305 | |||
306 | return ns; | 306 | return ns; |
307 | 307 | ||
308 | fail_unconfined: | 308 | fail_unconfined: |
@@ -497,7 +497,6 @@ static void __replace_profile(struct aa_profile *old, struct aa_profile *new) | |||
497 | /* released when @new is freed */ | 497 | /* released when @new is freed */ |
498 | new->parent = aa_get_profile(old->parent); | 498 | new->parent = aa_get_profile(old->parent); |
499 | new->ns = aa_get_namespace(old->ns); | 499 | new->ns = aa_get_namespace(old->ns); |
500 | new->sid = old->sid; | ||
501 | __list_add_profile(&policy->profiles, new); | 500 | __list_add_profile(&policy->profiles, new); |
502 | /* inherit children */ | 501 | /* inherit children */ |
503 | list_for_each_entry_safe(child, tmp, &old->base.profiles, base.list) { | 502 | list_for_each_entry_safe(child, tmp, &old->base.profiles, base.list) { |
@@ -665,7 +664,7 @@ struct aa_profile *aa_alloc_profile(const char *hname) | |||
665 | * @hat: true if the null- learning profile is a hat | 664 | * @hat: true if the null- learning profile is a hat |
666 | * | 665 | * |
667 | * Create a null- complain mode profile used in learning mode. The name of | 666 | * Create a null- complain mode profile used in learning mode. The name of |
668 | * the profile is unique and follows the format of parent//null-sid. | 667 | * the profile is unique and follows the format of parent//null-<uniq>. |
669 | * | 668 | * |
670 | * null profiles are added to the profile list but the list does not | 669 | * null profiles are added to the profile list but the list does not |
671 | * hold a count on them so that they are automatically released when | 670 | * hold a count on them so that they are automatically released when |
@@ -677,20 +676,19 @@ struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat) | |||
677 | { | 676 | { |
678 | struct aa_profile *profile = NULL; | 677 | struct aa_profile *profile = NULL; |
679 | char *name; | 678 | char *name; |
680 | u32 sid = aa_alloc_sid(); | 679 | int uniq = atomic_inc_return(&parent->ns->uniq_null); |
681 | 680 | ||
682 | /* freed below */ | 681 | /* freed below */ |
683 | name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, GFP_KERNEL); | 682 | name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, GFP_KERNEL); |
684 | if (!name) | 683 | if (!name) |
685 | goto fail; | 684 | goto fail; |
686 | sprintf(name, "%s//null-%x", parent->base.hname, sid); | 685 | sprintf(name, "%s//null-%x", parent->base.hname, uniq); |
687 | 686 | ||
688 | profile = aa_alloc_profile(name); | 687 | profile = aa_alloc_profile(name); |
689 | kfree(name); | 688 | kfree(name); |
690 | if (!profile) | 689 | if (!profile) |
691 | goto fail; | 690 | goto fail; |
692 | 691 | ||
693 | profile->sid = sid; | ||
694 | profile->mode = APPARMOR_COMPLAIN; | 692 | profile->mode = APPARMOR_COMPLAIN; |
695 | profile->flags = PFLAG_NULL; | 693 | profile->flags = PFLAG_NULL; |
696 | if (hat) | 694 | if (hat) |
@@ -708,7 +706,6 @@ struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat) | |||
708 | return profile; | 706 | return profile; |
709 | 707 | ||
710 | fail: | 708 | fail: |
711 | aa_free_sid(sid); | ||
712 | return NULL; | 709 | return NULL; |
713 | } | 710 | } |
714 | 711 | ||
@@ -749,7 +746,6 @@ static void free_profile(struct aa_profile *profile) | |||
749 | aa_free_cap_rules(&profile->caps); | 746 | aa_free_cap_rules(&profile->caps); |
750 | aa_free_rlimit_rules(&profile->rlimits); | 747 | aa_free_rlimit_rules(&profile->rlimits); |
751 | 748 | ||
752 | aa_free_sid(profile->sid); | ||
753 | aa_put_dfa(profile->xmatch); | 749 | aa_put_dfa(profile->xmatch); |
754 | aa_put_dfa(profile->policy.dfa); | 750 | aa_put_dfa(profile->policy.dfa); |
755 | 751 | ||
@@ -972,7 +968,6 @@ static void __add_new_profile(struct aa_namespace *ns, struct aa_policy *policy, | |||
972 | profile->parent = aa_get_profile((struct aa_profile *) policy); | 968 | profile->parent = aa_get_profile((struct aa_profile *) policy); |
973 | __list_add_profile(&policy->profiles, profile); | 969 | __list_add_profile(&policy->profiles, profile); |
974 | /* released on free_profile */ | 970 | /* released on free_profile */ |
975 | profile->sid = aa_alloc_sid(); | ||
976 | profile->ns = aa_get_namespace(ns); | 971 | profile->ns = aa_get_namespace(ns); |
977 | } | 972 | } |
978 | 973 | ||
@@ -1110,14 +1105,8 @@ audit: | |||
1110 | if (!error) { | 1105 | if (!error) { |
1111 | if (rename_profile) | 1106 | if (rename_profile) |
1112 | __replace_profile(rename_profile, new_profile); | 1107 | __replace_profile(rename_profile, new_profile); |
1113 | if (old_profile) { | 1108 | if (old_profile) |
1114 | /* when there are both rename and old profiles | ||
1115 | * inherit old profiles sid | ||
1116 | */ | ||
1117 | if (rename_profile) | ||
1118 | aa_free_sid(new_profile->sid); | ||
1119 | __replace_profile(old_profile, new_profile); | 1109 | __replace_profile(old_profile, new_profile); |
1120 | } | ||
1121 | if (!(old_profile || rename_profile)) | 1110 | if (!(old_profile || rename_profile)) |
1122 | __add_new_profile(ns, policy, new_profile); | 1111 | __add_new_profile(ns, policy, new_profile); |
1123 | } | 1112 | } |
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c index ca48a7d8d5b3..6dac7d77cb4d 100644 --- a/security/apparmor/policy_unpack.c +++ b/security/apparmor/policy_unpack.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include "include/match.h" | 27 | #include "include/match.h" |
28 | #include "include/policy.h" | 28 | #include "include/policy.h" |
29 | #include "include/policy_unpack.h" | 29 | #include "include/policy_unpack.h" |
30 | #include "include/sid.h" | ||
31 | 30 | ||
32 | /* | 31 | /* |
33 | * The AppArmor interface treats data as a type byte followed by the | 32 | * The AppArmor interface treats data as a type byte followed by the |