summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Johansen <john.johansen@canonical.com>2017-10-08 03:43:02 -0400
committerJohn Johansen <john.johansen@canonical.com>2018-02-09 14:30:01 -0500
commitde62de59c27881c59c7df2e535cb9e1275cd52cc (patch)
tree931811ad47bc7d33aac279fbc3a438543d9011e6
parentd065f2f56522b9240acb8c5ea35e9ee25f1b33e6 (diff)
apparmor: move task related defines and fns to task.X files
Signed-off-by: John Johansen <john.johansen@canonical.com>
-rw-r--r--security/apparmor/Makefile2
-rw-r--r--security/apparmor/domain.c4
-rw-r--r--security/apparmor/include/context.h40
-rw-r--r--security/apparmor/include/task.h90
-rw-r--r--security/apparmor/lsm.c6
-rw-r--r--security/apparmor/task.c (renamed from security/apparmor/context.c)61
6 files changed, 105 insertions, 98 deletions
diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile
index 9a6b4033d52b..380c8e08174a 100644
--- a/security/apparmor/Makefile
+++ b/security/apparmor/Makefile
@@ -3,7 +3,7 @@
3# 3#
4obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o 4obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
5 5
6apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \ 6apparmor-y := apparmorfs.o audit.o capability.o task.o ipc.o lib.o match.o \
7 path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \ 7 path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
8 resource.o secid.o file.o policy_ns.o label.o mount.o 8 resource.o secid.o file.o policy_ns.o label.o mount.o
9apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o 9apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index b180e10f2b86..56d080a6d774 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -794,7 +794,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
794 if (bprm->called_set_creds) 794 if (bprm->called_set_creds)
795 return 0; 795 return 0;
796 796
797 ctx = current_task_ctx(); 797 ctx = task_ctx(current);
798 AA_BUG(!cred_label(bprm->cred)); 798 AA_BUG(!cred_label(bprm->cred));
799 AA_BUG(!ctx); 799 AA_BUG(!ctx);
800 800
@@ -1067,7 +1067,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, int flags)
1067 1067
1068 /* released below */ 1068 /* released below */
1069 cred = get_current_cred(); 1069 cred = get_current_cred();
1070 ctx = current_task_ctx(); 1070 ctx = task_ctx(current);
1071 label = aa_get_newest_cred_label(cred); 1071 label = aa_get_newest_cred_label(cred);
1072 previous = aa_get_newest_label(ctx->previous); 1072 previous = aa_get_newest_label(ctx->previous);
1073 1073
diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h
index b2aeb1da7e77..e287b7d0d4be 100644
--- a/security/apparmor/include/context.h
+++ b/security/apparmor/include/context.h
@@ -21,33 +21,10 @@
21 21
22#include "label.h" 22#include "label.h"
23#include "policy_ns.h" 23#include "policy_ns.h"
24#include "task.h"
24 25
25#define task_ctx(X) ((X)->security)
26#define current_task_ctx() (task_ctx(current))
27#define cred_label(X) ((X)->security) 26#define cred_label(X) ((X)->security)
28 27
29/*
30 * struct aa_task_ctx - information for current task label change
31 * @onexec: profile to transition to on next exec (MAY BE NULL)
32 * @previous: profile the task may return to (MAY BE NULL)
33 * @token: magic value the task must know for returning to @previous_profile
34 */
35struct aa_task_ctx {
36 struct aa_label *onexec;
37 struct aa_label *previous;
38 u64 token;
39};
40
41struct aa_task_ctx *aa_alloc_task_ctx(gfp_t flags);
42void aa_free_task_ctx(struct aa_task_ctx *ctx);
43void aa_dup_task_ctx(struct aa_task_ctx *new, const struct aa_task_ctx *old);
44
45int aa_replace_current_label(struct aa_label *label);
46int aa_set_current_onexec(struct aa_label *label, bool stack);
47int aa_set_current_hat(struct aa_label *label, u64 token);
48int aa_restore_previous_label(u64 cookie);
49struct aa_label *aa_get_task_label(struct task_struct *task);
50
51 28
52/** 29/**
53 * aa_cred_raw_label - obtain cred's label 30 * aa_cred_raw_label - obtain cred's label
@@ -196,19 +173,4 @@ static inline struct aa_ns *aa_get_current_ns(void)
196 return ns; 173 return ns;
197} 174}
198 175
199/**
200 * aa_clear_task_ctx_trans - clear transition tracking info from the ctx
201 * @ctx: task context to clear (NOT NULL)
202 */
203static inline void aa_clear_task_ctx_trans(struct aa_task_ctx *ctx)
204{
205 AA_BUG(!ctx);
206
207 aa_put_label(ctx->previous);
208 aa_put_label(ctx->onexec);
209 ctx->previous = NULL;
210 ctx->onexec = NULL;
211 ctx->token = 0;
212}
213
214#endif /* __AA_CONTEXT_H */ 176#endif /* __AA_CONTEXT_H */
diff --git a/security/apparmor/include/task.h b/security/apparmor/include/task.h
new file mode 100644
index 000000000000..d222197db299
--- /dev/null
+++ b/security/apparmor/include/task.h
@@ -0,0 +1,90 @@
1/*
2 * AppArmor security module
3 *
4 * This file contains AppArmor task related definitions and mediation
5 *
6 * Copyright 2017 Canonical Ltd.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, version 2 of the
11 * License.
12 */
13
14#ifndef __AA_TASK_H
15#define __AA_TASK_H
16
17#define task_ctx(X) ((X)->security)
18
19/*
20 * struct aa_task_ctx - information for current task label change
21 * @onexec: profile to transition to on next exec (MAY BE NULL)
22 * @previous: profile the task may return to (MAY BE NULL)
23 * @token: magic value the task must know for returning to @previous_profile
24 */
25struct aa_task_ctx {
26 struct aa_label *onexec;
27 struct aa_label *previous;
28 u64 token;
29};
30
31int aa_replace_current_label(struct aa_label *label);
32int aa_set_current_onexec(struct aa_label *label, bool stack);
33int aa_set_current_hat(struct aa_label *label, u64 token);
34int aa_restore_previous_label(u64 cookie);
35struct aa_label *aa_get_task_label(struct task_struct *task);
36
37/**
38 * aa_alloc_task_ctx - allocate a new task_ctx
39 * @flags: gfp flags for allocation
40 *
41 * Returns: allocated buffer or NULL on failure
42 */
43static inline struct aa_task_ctx *aa_alloc_task_ctx(gfp_t flags)
44{
45 return kzalloc(sizeof(struct aa_task_ctx), flags);
46}
47
48/**
49 * aa_free_task_ctx - free a task_ctx
50 * @ctx: task_ctx to free (MAYBE NULL)
51 */
52static inline void aa_free_task_ctx(struct aa_task_ctx *ctx)
53{
54 if (ctx) {
55 aa_put_label(ctx->previous);
56 aa_put_label(ctx->onexec);
57
58 kzfree(ctx);
59 }
60}
61
62/**
63 * aa_dup_task_ctx - duplicate a task context, incrementing reference counts
64 * @new: a blank task context (NOT NULL)
65 * @old: the task context to copy (NOT NULL)
66 */
67static inline void aa_dup_task_ctx(struct aa_task_ctx *new,
68 const struct aa_task_ctx *old)
69{
70 *new = *old;
71 aa_get_label(new->previous);
72 aa_get_label(new->onexec);
73}
74
75/**
76 * aa_clear_task_ctx_trans - clear transition tracking info from the ctx
77 * @ctx: task context to clear (NOT NULL)
78 */
79static inline void aa_clear_task_ctx_trans(struct aa_task_ctx *ctx)
80{
81 AA_BUG(!ctx);
82
83 aa_put_label(ctx->previous);
84 aa_put_label(ctx->onexec);
85 ctx->previous = NULL;
86 ctx->onexec = NULL;
87 ctx->token = 0;
88}
89
90#endif /* __AA_TASK_H */
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index fda36f3e3820..7577cd982230 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -101,7 +101,7 @@ static int apparmor_task_alloc(struct task_struct *task,
101 if (!new) 101 if (!new)
102 return -ENOMEM; 102 return -ENOMEM;
103 103
104 aa_dup_task_ctx(new, current_task_ctx()); 104 aa_dup_task_ctx(new, task_ctx(current));
105 task_ctx(task) = new; 105 task_ctx(task) = new;
106 106
107 return 0; 107 return 0;
@@ -582,7 +582,7 @@ static int apparmor_getprocattr(struct task_struct *task, char *name,
582 int error = -ENOENT; 582 int error = -ENOENT;
583 /* released below */ 583 /* released below */
584 const struct cred *cred = get_task_cred(task); 584 const struct cred *cred = get_task_cred(task);
585 struct aa_task_ctx *ctx = current_task_ctx(); 585 struct aa_task_ctx *ctx = task_ctx(current);
586 struct aa_label *label = NULL; 586 struct aa_label *label = NULL;
587 587
588 if (strcmp(name, "current") == 0) 588 if (strcmp(name, "current") == 0)
@@ -705,7 +705,7 @@ static void apparmor_bprm_committing_creds(struct linux_binprm *bprm)
705static void apparmor_bprm_committed_creds(struct linux_binprm *bprm) 705static void apparmor_bprm_committed_creds(struct linux_binprm *bprm)
706{ 706{
707 /* clear out temporary/transitional state from the context */ 707 /* clear out temporary/transitional state from the context */
708 aa_clear_task_ctx_trans(current_task_ctx()); 708 aa_clear_task_ctx_trans(task_ctx(current));
709 709
710 return; 710 return;
711} 711}
diff --git a/security/apparmor/context.c b/security/apparmor/task.c
index d95a3d47cb92..36eb8707ad89 100644
--- a/security/apparmor/context.c
+++ b/security/apparmor/task.c
@@ -1,32 +1,23 @@
1/* 1/*
2 * AppArmor security module 2 * AppArmor security module
3 * 3 *
4 * This file contains AppArmor functions used to manipulate object security 4 * This file contains AppArmor task related definitions and mediation
5 * contexts.
6 * 5 *
7 * Copyright (C) 1998-2008 Novell/SUSE 6 * Copyright 2017 Canonical Ltd.
8 * Copyright 2009-2010 Canonical Ltd.
9 * 7 *
10 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2 of the 10 * published by the Free Software Foundation, version 2 of the
13 * License. 11 * License.
14 * 12 *
15 *
16 * AppArmor sets confinement on every task, via the cred_label() which
17 * is required and are not allowed to be NULL. The cred_label is
18 * reference counted.
19 *
20 * TODO 13 * TODO
21 * If a task uses change_hat it currently does not return to the old 14 * If a task uses change_hat it currently does not return to the old
22 * cred or task context but instead creates a new one. Ideally the task 15 * cred or task context but instead creates a new one. Ideally the task
23 * should return to the previous cred if it has not been modified. 16 * should return to the previous cred if it has not been modified.
24 *
25 */ 17 */
26 18
27#include "include/context.h" 19#include "include/context.h"
28#include "include/policy.h" 20#include "include/task.h"
29
30 21
31/** 22/**
32 * aa_get_task_label - Get another task's label 23 * aa_get_task_label - Get another task's label
@@ -46,43 +37,6 @@ struct aa_label *aa_get_task_label(struct task_struct *task)
46} 37}
47 38
48/** 39/**
49 * aa_alloc_task_ctx - allocate a new task_ctx
50 * @flags: gfp flags for allocation
51 *
52 * Returns: allocated buffer or NULL on failure
53 */
54struct aa_task_ctx *aa_alloc_task_ctx(gfp_t flags)
55{
56 return kzalloc(sizeof(struct aa_task_ctx), flags);
57}
58
59/**
60 * aa_free_task_ctx - free a task_ctx
61 * @ctx: task_ctx to free (MAYBE NULL)
62 */
63void aa_free_task_ctx(struct aa_task_ctx *ctx)
64{
65 if (ctx) {
66 aa_put_label(ctx->previous);
67 aa_put_label(ctx->onexec);
68
69 kzfree(ctx);
70 }
71}
72
73/**
74 * aa_dup_task_ctx - duplicate a task context, incrementing reference counts
75 * @new: a blank task context (NOT NULL)
76 * @old: the task context to copy (NOT NULL)
77 */
78void aa_dup_task_ctx(struct aa_task_ctx *new, const struct aa_task_ctx *old)
79{
80 *new = *old;
81 aa_get_label(new->previous);
82 aa_get_label(new->onexec);
83}
84
85/**
86 * aa_replace_current_label - replace the current tasks label 40 * aa_replace_current_label - replace the current tasks label
87 * @label: new label (NOT NULL) 41 * @label: new label (NOT NULL)
88 * 42 *
@@ -110,7 +64,7 @@ int aa_replace_current_label(struct aa_label *label)
110 * if switching to unconfined or a different label namespace 64 * if switching to unconfined or a different label namespace
111 * clear out context state 65 * clear out context state
112 */ 66 */
113 aa_clear_task_ctx_trans(current_task_ctx()); 67 aa_clear_task_ctx_trans(task_ctx(current));
114 68
115 /* 69 /*
116 * be careful switching cred label, when racing replacement it 70 * be careful switching cred label, when racing replacement it
@@ -126,6 +80,7 @@ int aa_replace_current_label(struct aa_label *label)
126 return 0; 80 return 0;
127} 81}
128 82
83
129/** 84/**
130 * aa_set_current_onexec - set the tasks change_profile to happen onexec 85 * aa_set_current_onexec - set the tasks change_profile to happen onexec
131 * @label: system label to set at exec (MAYBE NULL to clear value) 86 * @label: system label to set at exec (MAYBE NULL to clear value)
@@ -134,7 +89,7 @@ int aa_replace_current_label(struct aa_label *label)
134 */ 89 */
135int aa_set_current_onexec(struct aa_label *label, bool stack) 90int aa_set_current_onexec(struct aa_label *label, bool stack)
136{ 91{
137 struct aa_task_ctx *ctx = current_task_ctx(); 92 struct aa_task_ctx *ctx = task_ctx(current);
138 93
139 aa_get_label(label); 94 aa_get_label(label);
140 aa_put_label(ctx->onexec); 95 aa_put_label(ctx->onexec);
@@ -156,7 +111,7 @@ int aa_set_current_onexec(struct aa_label *label, bool stack)
156 */ 111 */
157int aa_set_current_hat(struct aa_label *label, u64 token) 112int aa_set_current_hat(struct aa_label *label, u64 token)
158{ 113{
159 struct aa_task_ctx *ctx = current_task_ctx(); 114 struct aa_task_ctx *ctx = task_ctx(current);
160 struct cred *new; 115 struct cred *new;
161 116
162 new = prepare_creds(); 117 new = prepare_creds();
@@ -196,7 +151,7 @@ int aa_set_current_hat(struct aa_label *label, u64 token)
196 */ 151 */
197int aa_restore_previous_label(u64 token) 152int aa_restore_previous_label(u64 token)
198{ 153{
199 struct aa_task_ctx *ctx = current_task_ctx(); 154 struct aa_task_ctx *ctx = task_ctx(current);
200 struct cred *new; 155 struct cred *new;
201 156
202 if (ctx->token != token) 157 if (ctx->token != token)