This source file includes following definitions.
- aa_get_task_label
- aa_replace_current_label
- aa_set_current_onexec
- aa_set_current_hat
- aa_restore_previous_label
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include "include/cred.h"
16 #include "include/task.h"
17
18
19
20
21
22
23
24 struct aa_label *aa_get_task_label(struct task_struct *task)
25 {
26 struct aa_label *p;
27
28 rcu_read_lock();
29 p = aa_get_newest_label(__aa_task_raw_label(task));
30 rcu_read_unlock();
31
32 return p;
33 }
34
35
36
37
38
39
40
41 int aa_replace_current_label(struct aa_label *label)
42 {
43 struct aa_label *old = aa_current_raw_label();
44 struct aa_task_ctx *ctx = task_ctx(current);
45 struct cred *new;
46
47 AA_BUG(!label);
48
49 if (old == label)
50 return 0;
51
52 if (current_cred() != current_real_cred())
53 return -EBUSY;
54
55 new = prepare_creds();
56 if (!new)
57 return -ENOMEM;
58
59 if (ctx->nnp && label_is_stale(ctx->nnp)) {
60 struct aa_label *tmp = ctx->nnp;
61
62 ctx->nnp = aa_get_newest_label(tmp);
63 aa_put_label(tmp);
64 }
65 if (unconfined(label) || (labels_ns(old) != labels_ns(label)))
66
67
68
69
70 aa_clear_task_ctx_trans(task_ctx(current));
71
72
73
74
75
76
77
78 aa_get_label(label);
79 aa_put_label(cred_label(new));
80 set_cred_label(new, label);
81
82 commit_creds(new);
83 return 0;
84 }
85
86
87
88
89
90
91
92
93 int aa_set_current_onexec(struct aa_label *label, bool stack)
94 {
95 struct aa_task_ctx *ctx = task_ctx(current);
96
97 aa_get_label(label);
98 aa_put_label(ctx->onexec);
99 ctx->onexec = label;
100 ctx->token = stack;
101
102 return 0;
103 }
104
105
106
107
108
109
110
111
112
113
114
115 int aa_set_current_hat(struct aa_label *label, u64 token)
116 {
117 struct aa_task_ctx *ctx = task_ctx(current);
118 struct cred *new;
119
120 new = prepare_creds();
121 if (!new)
122 return -ENOMEM;
123 AA_BUG(!label);
124
125 if (!ctx->previous) {
126
127 ctx->previous = cred_label(new);
128 ctx->token = token;
129 } else if (ctx->token == token) {
130 aa_put_label(cred_label(new));
131 } else {
132
133 abort_creds(new);
134 return -EACCES;
135 }
136
137 set_cred_label(new, aa_get_newest_label(label));
138
139 aa_put_label(ctx->onexec);
140 ctx->onexec = NULL;
141
142 commit_creds(new);
143 return 0;
144 }
145
146
147
148
149
150
151
152
153
154
155 int aa_restore_previous_label(u64 token)
156 {
157 struct aa_task_ctx *ctx = task_ctx(current);
158 struct cred *new;
159
160 if (ctx->token != token)
161 return -EACCES;
162
163 if (!ctx->previous)
164 return 0;
165
166 new = prepare_creds();
167 if (!new)
168 return -ENOMEM;
169
170 aa_put_label(cred_label(new));
171 set_cred_label(new, aa_get_newest_label(ctx->previous));
172 AA_BUG(!cred_label(new));
173
174 aa_clear_task_ctx_trans(ctx);
175
176 commit_creds(new);
177
178 return 0;
179 }