diff options
author | John Johansen <john.johansen@canonical.com> | 2013-02-27 06:43:40 -0500 |
---|---|---|
committer | John Johansen <john.johansen@canonical.com> | 2013-04-28 03:39:35 -0400 |
commit | 214beacaa7b669473bc963af719fa359a8312ea4 (patch) | |
tree | e847f9c082c579f711a53f35442710af753aaf7f /security/apparmor | |
parent | 53fe8b9961716033571d9799005bfdbbafa5162c (diff) |
apparmor: localize getting the security context to a few macros
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Diffstat (limited to 'security/apparmor')
-rw-r--r-- | security/apparmor/context.c | 10 | ||||
-rw-r--r-- | security/apparmor/domain.c | 6 | ||||
-rw-r--r-- | security/apparmor/include/context.h | 7 | ||||
-rw-r--r-- | security/apparmor/lsm.c | 22 |
4 files changed, 24 insertions, 21 deletions
diff --git a/security/apparmor/context.c b/security/apparmor/context.c index 3f911afa2bb9..d5af1d15f26d 100644 --- a/security/apparmor/context.c +++ b/security/apparmor/context.c | |||
@@ -93,7 +93,7 @@ struct aa_profile *aa_get_task_profile(struct task_struct *task) | |||
93 | */ | 93 | */ |
94 | int aa_replace_current_profile(struct aa_profile *profile) | 94 | int aa_replace_current_profile(struct aa_profile *profile) |
95 | { | 95 | { |
96 | struct aa_task_cxt *cxt = current_cred()->security; | 96 | struct aa_task_cxt *cxt = current_cxt(); |
97 | struct cred *new; | 97 | struct cred *new; |
98 | BUG_ON(!profile); | 98 | BUG_ON(!profile); |
99 | 99 | ||
@@ -104,7 +104,7 @@ int aa_replace_current_profile(struct aa_profile *profile) | |||
104 | if (!new) | 104 | if (!new) |
105 | return -ENOMEM; | 105 | return -ENOMEM; |
106 | 106 | ||
107 | cxt = new->security; | 107 | cxt = cred_cxt(new); |
108 | if (unconfined(profile) || (cxt->profile->ns != profile->ns)) | 108 | if (unconfined(profile) || (cxt->profile->ns != profile->ns)) |
109 | /* if switching to unconfined or a different profile namespace | 109 | /* if switching to unconfined or a different profile namespace |
110 | * clear out context state | 110 | * clear out context state |
@@ -136,7 +136,7 @@ int aa_set_current_onexec(struct aa_profile *profile) | |||
136 | if (!new) | 136 | if (!new) |
137 | return -ENOMEM; | 137 | return -ENOMEM; |
138 | 138 | ||
139 | cxt = new->security; | 139 | cxt = cred_cxt(new); |
140 | aa_get_profile(profile); | 140 | aa_get_profile(profile); |
141 | aa_put_profile(cxt->onexec); | 141 | aa_put_profile(cxt->onexec); |
142 | cxt->onexec = profile; | 142 | cxt->onexec = profile; |
@@ -163,7 +163,7 @@ int aa_set_current_hat(struct aa_profile *profile, u64 token) | |||
163 | return -ENOMEM; | 163 | return -ENOMEM; |
164 | BUG_ON(!profile); | 164 | BUG_ON(!profile); |
165 | 165 | ||
166 | cxt = new->security; | 166 | cxt = cred_cxt(new); |
167 | if (!cxt->previous) { | 167 | if (!cxt->previous) { |
168 | /* transfer refcount */ | 168 | /* transfer refcount */ |
169 | cxt->previous = cxt->profile; | 169 | cxt->previous = cxt->profile; |
@@ -200,7 +200,7 @@ int aa_restore_previous_profile(u64 token) | |||
200 | if (!new) | 200 | if (!new) |
201 | return -ENOMEM; | 201 | return -ENOMEM; |
202 | 202 | ||
203 | cxt = new->security; | 203 | cxt = cred_cxt(new); |
204 | if (cxt->token != token) { | 204 | if (cxt->token != token) { |
205 | abort_creds(new); | 205 | abort_creds(new); |
206 | return -EACCES; | 206 | return -EACCES; |
diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c index 07fcb09b990f..01b7bd669a88 100644 --- a/security/apparmor/domain.c +++ b/security/apparmor/domain.c | |||
@@ -356,7 +356,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm) | |||
356 | if (bprm->cred_prepared) | 356 | if (bprm->cred_prepared) |
357 | return 0; | 357 | return 0; |
358 | 358 | ||
359 | cxt = bprm->cred->security; | 359 | cxt = cred_cxt(bprm->cred); |
360 | BUG_ON(!cxt); | 360 | BUG_ON(!cxt); |
361 | 361 | ||
362 | profile = aa_get_profile(aa_newest_version(cxt->profile)); | 362 | profile = aa_get_profile(aa_newest_version(cxt->profile)); |
@@ -551,7 +551,7 @@ int apparmor_bprm_secureexec(struct linux_binprm *bprm) | |||
551 | void apparmor_bprm_committing_creds(struct linux_binprm *bprm) | 551 | void apparmor_bprm_committing_creds(struct linux_binprm *bprm) |
552 | { | 552 | { |
553 | struct aa_profile *profile = __aa_current_profile(); | 553 | struct aa_profile *profile = __aa_current_profile(); |
554 | struct aa_task_cxt *new_cxt = bprm->cred->security; | 554 | struct aa_task_cxt *new_cxt = cred_cxt(bprm->cred); |
555 | 555 | ||
556 | /* bail out if unconfined or not changing profile */ | 556 | /* bail out if unconfined or not changing profile */ |
557 | if ((new_cxt->profile == profile) || | 557 | if ((new_cxt->profile == profile) || |
@@ -628,7 +628,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, bool permtest) | |||
628 | 628 | ||
629 | /* released below */ | 629 | /* released below */ |
630 | cred = get_current_cred(); | 630 | cred = get_current_cred(); |
631 | cxt = cred->security; | 631 | cxt = cred_cxt(cred); |
632 | profile = aa_cred_profile(cred); | 632 | profile = aa_cred_profile(cred); |
633 | previous_profile = cxt->previous; | 633 | previous_profile = cxt->previous; |
634 | 634 | ||
diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h index 4cecad313227..d44ba5802e3d 100644 --- a/security/apparmor/include/context.h +++ b/security/apparmor/include/context.h | |||
@@ -21,6 +21,9 @@ | |||
21 | 21 | ||
22 | #include "policy.h" | 22 | #include "policy.h" |
23 | 23 | ||
24 | #define cred_cxt(X) (X)->security | ||
25 | #define current_cxt() cred_cxt(current_cred()) | ||
26 | |||
24 | /* struct aa_file_cxt - the AppArmor context the file was opened in | 27 | /* struct aa_file_cxt - the AppArmor context the file was opened in |
25 | * @perms: the permission the file was opened with | 28 | * @perms: the permission the file was opened with |
26 | * | 29 | * |
@@ -93,7 +96,7 @@ struct aa_profile *aa_get_task_profile(struct task_struct *task); | |||
93 | */ | 96 | */ |
94 | static inline struct aa_profile *aa_cred_profile(const struct cred *cred) | 97 | static inline struct aa_profile *aa_cred_profile(const struct cred *cred) |
95 | { | 98 | { |
96 | struct aa_task_cxt *cxt = cred->security; | 99 | struct aa_task_cxt *cxt = cred_cxt(cred); |
97 | BUG_ON(!cxt || !cxt->profile); | 100 | BUG_ON(!cxt || !cxt->profile); |
98 | return aa_newest_version(cxt->profile); | 101 | return aa_newest_version(cxt->profile); |
99 | } | 102 | } |
@@ -145,7 +148,7 @@ static inline struct aa_profile *__aa_current_profile(void) | |||
145 | */ | 148 | */ |
146 | static inline struct aa_profile *aa_current_profile(void) | 149 | static inline struct aa_profile *aa_current_profile(void) |
147 | { | 150 | { |
148 | const struct aa_task_cxt *cxt = current_cred()->security; | 151 | const struct aa_task_cxt *cxt = current_cxt(); |
149 | struct aa_profile *profile; | 152 | struct aa_profile *profile; |
150 | BUG_ON(!cxt || !cxt->profile); | 153 | BUG_ON(!cxt || !cxt->profile); |
151 | 154 | ||
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 10843aa5a368..2027fdf2060b 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c | |||
@@ -48,8 +48,8 @@ int apparmor_initialized __initdata; | |||
48 | */ | 48 | */ |
49 | static void apparmor_cred_free(struct cred *cred) | 49 | static void apparmor_cred_free(struct cred *cred) |
50 | { | 50 | { |
51 | aa_free_task_context(cred->security); | 51 | aa_free_task_context(cred_cxt(cred)); |
52 | cred->security = NULL; | 52 | cred_cxt(cred) = NULL; |
53 | } | 53 | } |
54 | 54 | ||
55 | /* | 55 | /* |
@@ -62,7 +62,7 @@ static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp) | |||
62 | if (!cxt) | 62 | if (!cxt) |
63 | return -ENOMEM; | 63 | return -ENOMEM; |
64 | 64 | ||
65 | cred->security = cxt; | 65 | cred_cxt(cred) = cxt; |
66 | return 0; | 66 | return 0; |
67 | } | 67 | } |
68 | 68 | ||
@@ -77,8 +77,8 @@ static int apparmor_cred_prepare(struct cred *new, const struct cred *old, | |||
77 | if (!cxt) | 77 | if (!cxt) |
78 | return -ENOMEM; | 78 | return -ENOMEM; |
79 | 79 | ||
80 | aa_dup_task_context(cxt, old->security); | 80 | aa_dup_task_context(cxt, cred_cxt(old)); |
81 | new->security = cxt; | 81 | cred_cxt(new) = cxt; |
82 | return 0; | 82 | return 0; |
83 | } | 83 | } |
84 | 84 | ||
@@ -87,8 +87,8 @@ static int apparmor_cred_prepare(struct cred *new, const struct cred *old, | |||
87 | */ | 87 | */ |
88 | static void apparmor_cred_transfer(struct cred *new, const struct cred *old) | 88 | static void apparmor_cred_transfer(struct cred *new, const struct cred *old) |
89 | { | 89 | { |
90 | const struct aa_task_cxt *old_cxt = old->security; | 90 | const struct aa_task_cxt *old_cxt = cred_cxt(old); |
91 | struct aa_task_cxt *new_cxt = new->security; | 91 | struct aa_task_cxt *new_cxt = cred_cxt(new); |
92 | 92 | ||
93 | aa_dup_task_context(new_cxt, old_cxt); | 93 | aa_dup_task_context(new_cxt, old_cxt); |
94 | } | 94 | } |
@@ -507,7 +507,7 @@ static int apparmor_getprocattr(struct task_struct *task, char *name, | |||
507 | int error = -ENOENT; | 507 | int error = -ENOENT; |
508 | /* released below */ | 508 | /* released below */ |
509 | const struct cred *cred = get_task_cred(task); | 509 | const struct cred *cred = get_task_cred(task); |
510 | struct aa_task_cxt *cxt = cred->security; | 510 | struct aa_task_cxt *cxt = cred_cxt(cred); |
511 | 511 | ||
512 | if (strcmp(name, "current") == 0) | 512 | if (strcmp(name, "current") == 0) |
513 | error = aa_getprocattr(aa_newest_version(cxt->profile), | 513 | error = aa_getprocattr(aa_newest_version(cxt->profile), |
@@ -880,7 +880,7 @@ static int __init set_init_cxt(void) | |||
880 | return -ENOMEM; | 880 | return -ENOMEM; |
881 | 881 | ||
882 | cxt->profile = aa_get_profile(root_ns->unconfined); | 882 | cxt->profile = aa_get_profile(root_ns->unconfined); |
883 | cred->security = cxt; | 883 | cred_cxt(cred) = cxt; |
884 | 884 | ||
885 | return 0; | 885 | return 0; |
886 | } | 886 | } |
@@ -910,8 +910,8 @@ static int __init apparmor_init(void) | |||
910 | error = register_security(&apparmor_ops); | 910 | error = register_security(&apparmor_ops); |
911 | if (error) { | 911 | if (error) { |
912 | struct cred *cred = (struct cred *)current->real_cred; | 912 | struct cred *cred = (struct cred *)current->real_cred; |
913 | aa_free_task_context(cred->security); | 913 | aa_free_task_context(cred_cxt(cred)); |
914 | cred->security = NULL; | 914 | cred_cxt(cred) = NULL; |
915 | AA_ERROR("Unable to register AppArmor\n"); | 915 | AA_ERROR("Unable to register AppArmor\n"); |
916 | goto register_security_out; | 916 | goto register_security_out; |
917 | } | 917 | } |