This source file includes following definitions.
- cred_label
- set_cred_label
- aa_cred_raw_label
- aa_get_newest_cred_label
- __aa_task_raw_label
- aa_current_raw_label
- aa_get_current_label
- end_current_label_crit_section
- __begin_current_label_crit_section
- begin_current_label_crit_section
- aa_get_current_ns
1
2
3
4
5
6
7
8
9
10
11 #ifndef __AA_CONTEXT_H
12 #define __AA_CONTEXT_H
13
14 #include <linux/cred.h>
15 #include <linux/slab.h>
16 #include <linux/sched.h>
17
18 #include "label.h"
19 #include "policy_ns.h"
20 #include "task.h"
21
22 static inline struct aa_label *cred_label(const struct cred *cred)
23 {
24 struct aa_label **blob = cred->security + apparmor_blob_sizes.lbs_cred;
25
26 AA_BUG(!blob);
27 return *blob;
28 }
29
30 static inline void set_cred_label(const struct cred *cred,
31 struct aa_label *label)
32 {
33 struct aa_label **blob = cred->security + apparmor_blob_sizes.lbs_cred;
34
35 AA_BUG(!blob);
36 *blob = label;
37 }
38
39
40
41
42
43
44
45
46
47 static inline struct aa_label *aa_cred_raw_label(const struct cred *cred)
48 {
49 struct aa_label *label = cred_label(cred);
50
51 AA_BUG(!label);
52 return label;
53 }
54
55
56
57
58
59
60
61 static inline struct aa_label *aa_get_newest_cred_label(const struct cred *cred)
62 {
63 return aa_get_newest_label(aa_cred_raw_label(cred));
64 }
65
66
67
68
69
70
71
72
73
74 static inline struct aa_label *__aa_task_raw_label(struct task_struct *task)
75 {
76 return aa_cred_raw_label(__task_cred(task));
77 }
78
79
80
81
82
83
84
85
86
87 static inline struct aa_label *aa_current_raw_label(void)
88 {
89 return aa_cred_raw_label(current_cred());
90 }
91
92
93
94
95
96
97
98
99
100
101 static inline struct aa_label *aa_get_current_label(void)
102 {
103 struct aa_label *l = aa_current_raw_label();
104
105 if (label_is_stale(l))
106 return aa_get_newest_label(l);
107 return aa_get_label(l);
108 }
109
110 #define __end_current_label_crit_section(X) end_current_label_crit_section(X)
111
112
113
114
115
116
117
118
119
120 static inline void end_current_label_crit_section(struct aa_label *label)
121 {
122 if (label != aa_current_raw_label())
123 aa_put_label(label);
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138 static inline struct aa_label *__begin_current_label_crit_section(void)
139 {
140 struct aa_label *label = aa_current_raw_label();
141
142 if (label_is_stale(label))
143 label = aa_get_newest_label(label);
144
145 return label;
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159
160 static inline struct aa_label *begin_current_label_crit_section(void)
161 {
162 struct aa_label *label = aa_current_raw_label();
163
164 might_sleep();
165
166 if (label_is_stale(label)) {
167 label = aa_get_newest_label(label);
168 if (aa_replace_current_label(label) == 0)
169
170 aa_put_label(label);
171 }
172
173 return label;
174 }
175
176 static inline struct aa_ns *aa_get_current_ns(void)
177 {
178 struct aa_label *label;
179 struct aa_ns *ns;
180
181 label = __begin_current_label_crit_section();
182 ns = aa_get_ns(labels_ns(label));
183 __end_current_label_crit_section(label);
184
185 return ns;
186 }
187
188 #endif