aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Johansen <john.johansen@canonical.com>2017-01-19 17:08:36 -0500
committerJohn Johansen <john.johansen@canonical.com>2018-02-09 14:30:01 -0500
commit4d2f8ba3e3b76e34f84ae1de456934713e9e59af (patch)
tree27ef81949dd96ddcffeec4924962103533459a3e
parent3acfd5f54ca16c15c36ac2f218357f2707b7edb8 (diff)
apparmor: rename task_ctx to the more accurate cred_ctx
Signed-off-by: John Johansen <john.johansen@canonical.com>
-rw-r--r--security/apparmor/context.c38
-rw-r--r--security/apparmor/domain.c6
-rw-r--r--security/apparmor/include/context.h19
-rw-r--r--security/apparmor/lsm.c26
-rw-r--r--security/apparmor/policy.c2
5 files changed, 45 insertions, 46 deletions
diff --git a/security/apparmor/context.c b/security/apparmor/context.c
index c95f1ac6190b..89c03053303e 100644
--- a/security/apparmor/context.c
+++ b/security/apparmor/context.c
@@ -13,11 +13,11 @@
13 * License. 13 * License.
14 * 14 *
15 * 15 *
16 * AppArmor sets confinement on every task, via the the aa_task_ctx and 16 * AppArmor sets confinement on every task, via the the aa_cred_ctx and
17 * the aa_task_ctx.label, both of which are required and are not allowed 17 * the aa_cred_ctx.label, both of which are required and are not allowed
18 * to be NULL. The aa_task_ctx is not reference counted and is unique 18 * to be NULL. The aa_cred_ctx is not reference counted and is unique
19 * to each cred (which is reference count). The label pointed to by 19 * to each cred (which is reference count). The label pointed to by
20 * the task_ctx is reference counted. 20 * the cred_ctx is reference counted.
21 * 21 *
22 * TODO 22 * TODO
23 * If a task uses change_hat it currently does not return to the old 23 * If a task uses change_hat it currently does not return to the old
@@ -30,21 +30,21 @@
30#include "include/policy.h" 30#include "include/policy.h"
31 31
32/** 32/**
33 * aa_alloc_task_context - allocate a new task_ctx 33 * aa_alloc_cred_ctx - allocate a new cred_ctx
34 * @flags: gfp flags for allocation 34 * @flags: gfp flags for allocation
35 * 35 *
36 * Returns: allocated buffer or NULL on failure 36 * Returns: allocated buffer or NULL on failure
37 */ 37 */
38struct aa_task_ctx *aa_alloc_task_context(gfp_t flags) 38struct aa_cred_ctx *aa_alloc_cred_ctx(gfp_t flags)
39{ 39{
40 return kzalloc(sizeof(struct aa_task_ctx), flags); 40 return kzalloc(sizeof(struct aa_cred_ctx), flags);
41} 41}
42 42
43/** 43/**
44 * aa_free_task_context - free a task_ctx 44 * aa_free_cred_ctx - free a cred_ctx
45 * @ctx: task_ctx to free (MAYBE NULL) 45 * @ctx: cred_ctx to free (MAYBE NULL)
46 */ 46 */
47void aa_free_task_context(struct aa_task_ctx *ctx) 47void aa_free_cred_ctx(struct aa_cred_ctx *ctx)
48{ 48{
49 if (ctx) { 49 if (ctx) {
50 aa_put_label(ctx->label); 50 aa_put_label(ctx->label);
@@ -56,11 +56,11 @@ void aa_free_task_context(struct aa_task_ctx *ctx)
56} 56}
57 57
58/** 58/**
59 * aa_dup_task_context - duplicate a task context, incrementing reference counts 59 * aa_dup_cred_ctx - duplicate a task context, incrementing reference counts
60 * @new: a blank task context (NOT NULL) 60 * @new: a blank task context (NOT NULL)
61 * @old: the task context to copy (NOT NULL) 61 * @old: the task context to copy (NOT NULL)
62 */ 62 */
63void aa_dup_task_context(struct aa_task_ctx *new, const struct aa_task_ctx *old) 63void aa_dup_cred_ctx(struct aa_cred_ctx *new, const struct aa_cred_ctx *old)
64{ 64{
65 *new = *old; 65 *new = *old;
66 aa_get_label(new->label); 66 aa_get_label(new->label);
@@ -93,7 +93,7 @@ struct aa_label *aa_get_task_label(struct task_struct *task)
93 */ 93 */
94int aa_replace_current_label(struct aa_label *label) 94int aa_replace_current_label(struct aa_label *label)
95{ 95{
96 struct aa_task_ctx *ctx = current_ctx(); 96 struct aa_cred_ctx *ctx = current_cred_ctx();
97 struct cred *new; 97 struct cred *new;
98 AA_BUG(!label); 98 AA_BUG(!label);
99 99
@@ -112,7 +112,7 @@ int aa_replace_current_label(struct aa_label *label)
112 /* if switching to unconfined or a different label namespace 112 /* if switching to unconfined or a different label namespace
113 * clear out context state 113 * clear out context state
114 */ 114 */
115 aa_clear_task_ctx_trans(ctx); 115 aa_clear_cred_ctx_trans(ctx);
116 116
117 /* 117 /*
118 * be careful switching ctx->profile, when racing replacement it 118 * be careful switching ctx->profile, when racing replacement it
@@ -136,14 +136,14 @@ int aa_replace_current_label(struct aa_label *label)
136 */ 136 */
137int aa_set_current_onexec(struct aa_label *label, bool stack) 137int aa_set_current_onexec(struct aa_label *label, bool stack)
138{ 138{
139 struct aa_task_ctx *ctx; 139 struct aa_cred_ctx *ctx;
140 struct cred *new = prepare_creds(); 140 struct cred *new = prepare_creds();
141 if (!new) 141 if (!new)
142 return -ENOMEM; 142 return -ENOMEM;
143 143
144 ctx = cred_ctx(new); 144 ctx = cred_ctx(new);
145 aa_get_label(label); 145 aa_get_label(label);
146 aa_clear_task_ctx_trans(ctx); 146 aa_clear_cred_ctx_trans(ctx);
147 ctx->onexec = label; 147 ctx->onexec = label;
148 ctx->token = stack; 148 ctx->token = stack;
149 149
@@ -163,7 +163,7 @@ int aa_set_current_onexec(struct aa_label *label, bool stack)
163 */ 163 */
164int aa_set_current_hat(struct aa_label *label, u64 token) 164int aa_set_current_hat(struct aa_label *label, u64 token)
165{ 165{
166 struct aa_task_ctx *ctx; 166 struct aa_cred_ctx *ctx;
167 struct cred *new = prepare_creds(); 167 struct cred *new = prepare_creds();
168 if (!new) 168 if (!new)
169 return -ENOMEM; 169 return -ENOMEM;
@@ -201,7 +201,7 @@ int aa_set_current_hat(struct aa_label *label, u64 token)
201 */ 201 */
202int aa_restore_previous_label(u64 token) 202int aa_restore_previous_label(u64 token)
203{ 203{
204 struct aa_task_ctx *ctx; 204 struct aa_cred_ctx *ctx;
205 struct cred *new = prepare_creds(); 205 struct cred *new = prepare_creds();
206 if (!new) 206 if (!new)
207 return -ENOMEM; 207 return -ENOMEM;
@@ -221,7 +221,7 @@ int aa_restore_previous_label(u64 token)
221 ctx->label = aa_get_newest_label(ctx->previous); 221 ctx->label = aa_get_newest_label(ctx->previous);
222 AA_BUG(!ctx->label); 222 AA_BUG(!ctx->label);
223 /* clear exec && prev information when restoring to previous context */ 223 /* clear exec && prev information when restoring to previous context */
224 aa_clear_task_ctx_trans(ctx); 224 aa_clear_cred_ctx_trans(ctx);
225 225
226 commit_creds(new); 226 commit_creds(new);
227 return 0; 227 return 0;
diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index 6a54d2ffa840..90967de96be0 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -779,7 +779,7 @@ static struct aa_label *handle_onexec(struct aa_label *label,
779 */ 779 */
780int apparmor_bprm_set_creds(struct linux_binprm *bprm) 780int apparmor_bprm_set_creds(struct linux_binprm *bprm)
781{ 781{
782 struct aa_task_ctx *ctx; 782 struct aa_cred_ctx *ctx;
783 struct aa_label *label, *new = NULL; 783 struct aa_label *label, *new = NULL;
784 struct aa_profile *profile; 784 struct aa_profile *profile;
785 char *buffer = NULL; 785 char *buffer = NULL;
@@ -859,7 +859,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
859 859
860done: 860done:
861 /* clear out temporary/transitional state from the context */ 861 /* clear out temporary/transitional state from the context */
862 aa_clear_task_ctx_trans(ctx); 862 aa_clear_cred_ctx_trans(ctx);
863 863
864 aa_put_label(label); 864 aa_put_label(label);
865 put_buffers(buffer); 865 put_buffers(buffer);
@@ -1049,7 +1049,7 @@ build:
1049int aa_change_hat(const char *hats[], int count, u64 token, int flags) 1049int aa_change_hat(const char *hats[], int count, u64 token, int flags)
1050{ 1050{
1051 const struct cred *cred; 1051 const struct cred *cred;
1052 struct aa_task_ctx *ctx; 1052 struct aa_cred_ctx *ctx;
1053 struct aa_label *label, *previous, *new = NULL, *target = NULL; 1053 struct aa_label *label, *previous, *new = NULL, *target = NULL;
1054 struct aa_profile *profile; 1054 struct aa_profile *profile;
1055 struct aa_perms perms = {}; 1055 struct aa_perms perms = {};
diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h
index 6ae07e9aaa17..0622fcf2a695 100644
--- a/security/apparmor/include/context.h
+++ b/security/apparmor/include/context.h
@@ -23,10 +23,10 @@
23#include "policy_ns.h" 23#include "policy_ns.h"
24 24
25#define cred_ctx(X) ((X)->security) 25#define cred_ctx(X) ((X)->security)
26#define current_ctx() cred_ctx(current_cred()) 26#define current_cred_ctx() cred_ctx(current_cred())
27 27
28/** 28/**
29 * struct aa_task_ctx - primary label for confined tasks 29 * struct aa_cred_ctx - primary label for confined tasks
30 * @label: the current label (NOT NULL) 30 * @label: the current label (NOT NULL)
31 * @exec: label to transition to on next exec (MAYBE NULL) 31 * @exec: label to transition to on next exec (MAYBE NULL)
32 * @previous: label the task may return to (MAYBE NULL) 32 * @previous: label the task may return to (MAYBE NULL)
@@ -37,17 +37,16 @@
37 * 37 *
38 * TODO: make so a task can be confined by a stack of contexts 38 * TODO: make so a task can be confined by a stack of contexts
39 */ 39 */
40struct aa_task_ctx { 40struct aa_cred_ctx {
41 struct aa_label *label; 41 struct aa_label *label;
42 struct aa_label *onexec; 42 struct aa_label *onexec;
43 struct aa_label *previous; 43 struct aa_label *previous;
44 u64 token; 44 u64 token;
45}; 45};
46 46
47struct aa_task_ctx *aa_alloc_task_context(gfp_t flags); 47struct aa_cred_ctx *aa_alloc_cred_ctx(gfp_t flags);
48void aa_free_task_context(struct aa_task_ctx *ctx); 48void aa_free_cred_ctx(struct aa_cred_ctx *ctx);
49void aa_dup_task_context(struct aa_task_ctx *new, 49void aa_dup_cred_ctx(struct aa_cred_ctx *new, const struct aa_cred_ctx *old);
50 const struct aa_task_ctx *old);
51int aa_replace_current_label(struct aa_label *label); 50int aa_replace_current_label(struct aa_label *label);
52int aa_set_current_onexec(struct aa_label *label, bool stack); 51int aa_set_current_onexec(struct aa_label *label, bool stack);
53int aa_set_current_hat(struct aa_label *label, u64 token); 52int aa_set_current_hat(struct aa_label *label, u64 token);
@@ -65,7 +64,7 @@ struct aa_label *aa_get_task_label(struct task_struct *task);
65 */ 64 */
66static inline struct aa_label *aa_cred_raw_label(const struct cred *cred) 65static inline struct aa_label *aa_cred_raw_label(const struct cred *cred)
67{ 66{
68 struct aa_task_ctx *ctx = cred_ctx(cred); 67 struct aa_cred_ctx *ctx = cred_ctx(cred);
69 68
70 AA_BUG(!ctx || !ctx->label); 69 AA_BUG(!ctx || !ctx->label);
71 return ctx->label; 70 return ctx->label;
@@ -214,10 +213,10 @@ static inline struct aa_ns *aa_get_current_ns(void)
214} 213}
215 214
216/** 215/**
217 * aa_clear_task_ctx_trans - clear transition tracking info from the ctx 216 * aa_clear_cred_ctx_trans - clear transition tracking info from the ctx
218 * @ctx: task context to clear (NOT NULL) 217 * @ctx: task context to clear (NOT NULL)
219 */ 218 */
220static inline void aa_clear_task_ctx_trans(struct aa_task_ctx *ctx) 219static inline void aa_clear_cred_ctx_trans(struct aa_cred_ctx *ctx)
221{ 220{
222 aa_put_label(ctx->previous); 221 aa_put_label(ctx->previous);
223 aa_put_label(ctx->onexec); 222 aa_put_label(ctx->onexec);
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 9a65eeaf7dfa..0624eb2081f3 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -51,11 +51,11 @@ DEFINE_PER_CPU(struct aa_buffers, aa_buffers);
51 */ 51 */
52 52
53/* 53/*
54 * free the associated aa_task_ctx and put its labels 54 * free the associated aa_cred_ctx and put its labels
55 */ 55 */
56static void apparmor_cred_free(struct cred *cred) 56static void apparmor_cred_free(struct cred *cred)
57{ 57{
58 aa_free_task_context(cred_ctx(cred)); 58 aa_free_cred_ctx(cred_ctx(cred));
59 cred_ctx(cred) = NULL; 59 cred_ctx(cred) = NULL;
60} 60}
61 61
@@ -65,7 +65,7 @@ static void apparmor_cred_free(struct cred *cred)
65static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp) 65static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
66{ 66{
67 /* freed by apparmor_cred_free */ 67 /* freed by apparmor_cred_free */
68 struct aa_task_ctx *ctx = aa_alloc_task_context(gfp); 68 struct aa_cred_ctx *ctx = aa_alloc_cred_ctx(gfp);
69 69
70 if (!ctx) 70 if (!ctx)
71 return -ENOMEM; 71 return -ENOMEM;
@@ -75,18 +75,18 @@ static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
75} 75}
76 76
77/* 77/*
78 * prepare new aa_task_ctx for modification by prepare_cred block 78 * prepare new aa_cred_ctx for modification by prepare_cred block
79 */ 79 */
80static int apparmor_cred_prepare(struct cred *new, const struct cred *old, 80static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
81 gfp_t gfp) 81 gfp_t gfp)
82{ 82{
83 /* freed by apparmor_cred_free */ 83 /* freed by apparmor_cred_free */
84 struct aa_task_ctx *ctx = aa_alloc_task_context(gfp); 84 struct aa_cred_ctx *ctx = aa_alloc_cred_ctx(gfp);
85 85
86 if (!ctx) 86 if (!ctx)
87 return -ENOMEM; 87 return -ENOMEM;
88 88
89 aa_dup_task_context(ctx, cred_ctx(old)); 89 aa_dup_cred_ctx(ctx, cred_ctx(old));
90 cred_ctx(new) = ctx; 90 cred_ctx(new) = ctx;
91 return 0; 91 return 0;
92} 92}
@@ -96,10 +96,10 @@ static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
96 */ 96 */
97static void apparmor_cred_transfer(struct cred *new, const struct cred *old) 97static void apparmor_cred_transfer(struct cred *new, const struct cred *old)
98{ 98{
99 const struct aa_task_ctx *old_ctx = cred_ctx(old); 99 const struct aa_cred_ctx *old_ctx = cred_ctx(old);
100 struct aa_task_ctx *new_ctx = cred_ctx(new); 100 struct aa_cred_ctx *new_ctx = cred_ctx(new);
101 101
102 aa_dup_task_context(new_ctx, old_ctx); 102 aa_dup_cred_ctx(new_ctx, old_ctx);
103} 103}
104 104
105static int apparmor_ptrace_access_check(struct task_struct *child, 105static int apparmor_ptrace_access_check(struct task_struct *child,
@@ -577,7 +577,7 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
577 int error = -ENOENT; 577 int error = -ENOENT;
578 /* released below */ 578 /* released below */
579 const struct cred *cred = get_task_cred(task); 579 const struct cred *cred = get_task_cred(task);
580 struct aa_task_ctx *ctx = cred_ctx(cred); 580 struct aa_cred_ctx *ctx = cred_ctx(cred);
581 struct aa_label *label = NULL; 581 struct aa_label *label = NULL;
582 582
583 if (strcmp(name, "current") == 0) 583 if (strcmp(name, "current") == 0)
@@ -678,7 +678,7 @@ fail:
678static void apparmor_bprm_committing_creds(struct linux_binprm *bprm) 678static void apparmor_bprm_committing_creds(struct linux_binprm *bprm)
679{ 679{
680 struct aa_label *label = aa_current_raw_label(); 680 struct aa_label *label = aa_current_raw_label();
681 struct aa_task_ctx *new_ctx = cred_ctx(bprm->cred); 681 struct aa_cred_ctx *new_ctx = cred_ctx(bprm->cred);
682 682
683 /* bail out if unconfined or not changing profile */ 683 /* bail out if unconfined or not changing profile */
684 if ((new_ctx->label->proxy == label->proxy) || 684 if ((new_ctx->label->proxy == label->proxy) ||
@@ -1024,9 +1024,9 @@ static int param_set_mode(const char *val, const struct kernel_param *kp)
1024static int __init set_init_ctx(void) 1024static int __init set_init_ctx(void)
1025{ 1025{
1026 struct cred *cred = (struct cred *)current->real_cred; 1026 struct cred *cred = (struct cred *)current->real_cred;
1027 struct aa_task_ctx *ctx; 1027 struct aa_cred_ctx *ctx;
1028 1028
1029 ctx = aa_alloc_task_context(GFP_KERNEL); 1029 ctx = aa_alloc_cred_ctx(GFP_KERNEL);
1030 if (!ctx) 1030 if (!ctx)
1031 return -ENOMEM; 1031 return -ENOMEM;
1032 1032
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index b0b58848c248..c505d517fa3c 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -845,7 +845,7 @@ static struct aa_profile *update_to_newest_parent(struct aa_profile *new)
845 * @udata: serialized data stream (NOT NULL) 845 * @udata: serialized data stream (NOT NULL)
846 * 846 *
847 * unpack and replace a profile on the profile list and uses of that profile 847 * unpack and replace a profile on the profile list and uses of that profile
848 * by any aa_task_ctx. If the profile does not exist on the profile list 848 * by any aa_cred_ctx. If the profile does not exist on the profile list
849 * it is added. 849 * it is added.
850 * 850 *
851 * Returns: size of data consumed else error code on failure. 851 * Returns: size of data consumed else error code on failure.