1 |
/* |
/* |
2 |
* security/ccsecurity/domain.c |
* security/ccsecurity/domain.c |
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.0-pre 2009/08/24 |
* Version: 1.7.2+ 2010/05/27 |
7 |
* |
* |
8 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
22 |
#endif |
#endif |
23 |
#include "internal.h" |
#include "internal.h" |
24 |
|
|
|
/* For compatibility with older kernels. */ |
|
|
#ifndef for_each_process |
|
|
#define for_each_process for_each_task |
|
|
#endif |
|
|
|
|
25 |
/* Variables definitions.*/ |
/* Variables definitions.*/ |
26 |
|
|
27 |
|
/* The global domain. */ |
28 |
|
struct ccs_domain_info ccs_global_domain; |
29 |
|
|
30 |
/* The initial domain. */ |
/* The initial domain. */ |
31 |
struct ccs_domain_info ccs_kernel_domain; |
struct ccs_domain_info ccs_kernel_domain; |
32 |
|
|
33 |
/* The list for "struct ccs_domain_info". */ |
/* The list for "struct ccs_domain_info". */ |
34 |
LIST_HEAD(ccs_domain_list); |
LIST_HEAD(ccs_domain_list); |
35 |
|
|
36 |
|
struct list_head ccs_policy_list[CCS_MAX_POLICY]; |
37 |
|
struct list_head ccs_group_list[CCS_MAX_GROUP]; |
38 |
|
struct list_head ccs_shared_list[CCS_MAX_LIST]; |
39 |
|
|
40 |
/** |
/** |
41 |
* ccs_audit_execute_handler_log - Audit execute_handler log. |
* ccs_audit_execute_handler_log - Audit execute_handler log. |
42 |
* |
* |
43 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
|
* @is_default: True if it is "execute_handler" log. |
|
44 |
* |
* |
45 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
46 |
*/ |
*/ |
47 |
static int ccs_audit_execute_handler_log(struct ccs_execve_entry *ee, |
static int ccs_audit_execute_handler_log(struct ccs_execve *ee) |
|
const bool is_default) |
|
48 |
{ |
{ |
49 |
struct ccs_request_info *r = &ee->r; |
struct ccs_request_info *r = &ee->r; |
50 |
const char *handler = ee->handler->name; |
const char *handler = ee->handler->name; |
51 |
|
r->type = CCS_MAC_FILE_EXECUTE; |
52 |
r->mode = ccs_get_mode(r->profile, CCS_MAC_FILE_EXECUTE); |
r->mode = ccs_get_mode(r->profile, CCS_MAC_FILE_EXECUTE); |
53 |
return ccs_write_audit_log(true, r, "%s %s\n", |
r->granted = true; |
54 |
is_default ? CCS_KEYWORD_EXECUTE_HANDLER : |
return ccs_write_log(r, "%s %s\n", ee->handler_type == |
55 |
CCS_KEYWORD_DENIED_EXECUTE_HANDLER, handler); |
CCS_TYPE_DENIED_EXECUTE_HANDLER ? |
56 |
|
CCS_KEYWORD_DENIED_EXECUTE_HANDLER : |
57 |
|
CCS_KEYWORD_EXECUTE_HANDLER, handler); |
58 |
} |
} |
59 |
|
|
60 |
/** |
/** |
61 |
* ccs_audit_domain_creation_log - Audit domain creation log. |
* ccs_audit_domain_creation_log - Audit domain creation log. |
62 |
* |
* |
|
* @domain: Pointer to "struct ccs_domain_info". |
|
|
* |
|
63 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
64 |
*/ |
*/ |
65 |
static int ccs_audit_domain_creation_log(struct ccs_domain_info *domain) |
static int ccs_audit_domain_creation_log(void) |
66 |
{ |
{ |
|
int error; |
|
67 |
struct ccs_request_info r; |
struct ccs_request_info r; |
68 |
ccs_init_request_info(&r, domain, CCS_MAC_FILE_EXECUTE); |
ccs_init_request_info(&r, CCS_MAC_FILE_EXECUTE); |
69 |
error = ccs_write_audit_log(false, &r, "use_profile %u\n", r.profile); |
r.granted = false; |
70 |
|
return ccs_write_log(&r, "use_profile %u\n", r.profile); |
71 |
|
} |
72 |
|
|
73 |
|
int ccs_update_policy(struct ccs_acl_head *new_entry, const int size, |
74 |
|
bool is_delete, const int idx, bool (*check_duplicate) |
75 |
|
(const struct ccs_acl_head *, |
76 |
|
const struct ccs_acl_head *)) |
77 |
|
{ |
78 |
|
int error = is_delete ? -ENOENT : -ENOMEM; |
79 |
|
struct ccs_acl_head *entry; |
80 |
|
if (mutex_lock_interruptible(&ccs_policy_lock)) |
81 |
|
return -ENOMEM; |
82 |
|
list_for_each_entry_rcu(entry, &ccs_policy_list[idx], list) { |
83 |
|
if (!check_duplicate(entry, new_entry)) |
84 |
|
continue; |
85 |
|
entry->is_deleted = is_delete; |
86 |
|
error = 0; |
87 |
|
break; |
88 |
|
} |
89 |
|
if (error && !is_delete) { |
90 |
|
entry = ccs_commit_ok(new_entry, size); |
91 |
|
if (entry) { |
92 |
|
list_add_tail_rcu(&entry->list, &ccs_policy_list[idx]); |
93 |
|
error = 0; |
94 |
|
} |
95 |
|
} |
96 |
|
mutex_unlock(&ccs_policy_lock); |
97 |
|
return error; |
98 |
|
} |
99 |
|
|
100 |
|
int ccs_update_group(struct ccs_acl_head *new_entry, const int size, |
101 |
|
bool is_delete, struct ccs_group *group, |
102 |
|
bool (*check_duplicate) (const struct ccs_acl_head *, |
103 |
|
const struct ccs_acl_head *)) |
104 |
|
{ |
105 |
|
int error = is_delete ? -ENOENT : -ENOMEM; |
106 |
|
struct ccs_acl_head *entry; |
107 |
|
if (mutex_lock_interruptible(&ccs_policy_lock)) |
108 |
|
return -ENOMEM; |
109 |
|
list_for_each_entry_rcu(entry, &group->member_list, list) { |
110 |
|
if (!check_duplicate(entry, new_entry)) |
111 |
|
continue; |
112 |
|
entry->is_deleted = is_delete; |
113 |
|
error = 0; |
114 |
|
break; |
115 |
|
} |
116 |
|
if (!is_delete && error) { |
117 |
|
entry = ccs_commit_ok(new_entry, size); |
118 |
|
if (entry) { |
119 |
|
list_add_tail_rcu(&entry->list, &group->member_list); |
120 |
|
error = 0; |
121 |
|
} |
122 |
|
} |
123 |
|
mutex_unlock(&ccs_policy_lock); |
124 |
|
return error; |
125 |
|
} |
126 |
|
|
127 |
|
static void ccs_delete_type(struct ccs_domain_info *domain, u8 type) |
128 |
|
{ |
129 |
|
struct ccs_acl_info *ptr; |
130 |
|
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
131 |
|
if (ptr->type == type) |
132 |
|
ptr->is_deleted = true; |
133 |
|
} |
134 |
|
} |
135 |
|
|
136 |
|
int ccs_update_domain(struct ccs_acl_info *new_entry, const int size, |
137 |
|
bool is_delete, struct ccs_domain_info *domain, |
138 |
|
bool (*check_duplicate) (const struct ccs_acl_info *, |
139 |
|
const struct ccs_acl_info *), |
140 |
|
bool (*merge_duplicate) (struct ccs_acl_info *, |
141 |
|
struct ccs_acl_info *, |
142 |
|
const bool)) |
143 |
|
{ |
144 |
|
int error = is_delete ? -ENOENT : -ENOMEM; |
145 |
|
struct ccs_acl_info *entry; |
146 |
|
/* |
147 |
|
* Only one "execute_handler" and "denied_execute_handler" can exist |
148 |
|
* in a domain. |
149 |
|
*/ |
150 |
|
const u8 type = new_entry->type; |
151 |
|
const bool exclusive = !is_delete && |
152 |
|
(type == CCS_TYPE_EXECUTE_HANDLER || |
153 |
|
type == CCS_TYPE_DENIED_EXECUTE_HANDLER); |
154 |
|
if (mutex_lock_interruptible(&ccs_policy_lock)) |
155 |
|
return error; |
156 |
|
list_for_each_entry_rcu(entry, &domain->acl_info_list, list) { |
157 |
|
if (!check_duplicate(entry, new_entry)) |
158 |
|
continue; |
159 |
|
if (exclusive) |
160 |
|
ccs_delete_type(domain, type); |
161 |
|
if (merge_duplicate) |
162 |
|
entry->is_deleted = merge_duplicate(entry, new_entry, |
163 |
|
is_delete); |
164 |
|
else |
165 |
|
entry->is_deleted = is_delete; |
166 |
|
error = 0; |
167 |
|
break; |
168 |
|
} |
169 |
|
if (error && !is_delete) { |
170 |
|
entry = ccs_commit_ok(new_entry, size); |
171 |
|
if (entry) { |
172 |
|
if (exclusive) |
173 |
|
ccs_delete_type(domain, type); |
174 |
|
ccs_add_domain_acl(domain, entry); |
175 |
|
error = 0; |
176 |
|
} |
177 |
|
} |
178 |
|
mutex_unlock(&ccs_policy_lock); |
179 |
return error; |
return error; |
180 |
} |
} |
181 |
|
|
182 |
/* The list for "struct ccs_domain_initializer_entry". */ |
void ccs_check_acl(struct ccs_request_info *r, |
183 |
LIST_HEAD(ccs_domain_initializer_list); |
bool (*check_entry) (const struct ccs_request_info *, |
184 |
|
const struct ccs_acl_info *)) |
185 |
|
{ |
186 |
|
const struct ccs_domain_info *domain = ccs_current_domain(); |
187 |
|
struct ccs_acl_info *ptr; |
188 |
|
retry: |
189 |
|
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
190 |
|
if (ptr->is_deleted || ptr->type != r->param_type) |
191 |
|
continue; |
192 |
|
if (check_entry(r, ptr) && ccs_condition(r, ptr->cond)) { |
193 |
|
r->cond = ptr->cond; |
194 |
|
r->granted = true; |
195 |
|
return; |
196 |
|
} |
197 |
|
} |
198 |
|
if (domain != &ccs_global_domain && !domain->ignore_global && |
199 |
|
(r->param_type != CCS_TYPE_PATH_ACL || |
200 |
|
r->param.path.operation != CCS_TYPE_READ || |
201 |
|
!domain->ignore_global_allow_read) && |
202 |
|
(r->param_type != CCS_TYPE_ENV_ACL || |
203 |
|
!domain->ignore_global_allow_env)) { |
204 |
|
domain = &ccs_global_domain; |
205 |
|
goto retry; |
206 |
|
} |
207 |
|
r->granted = false; |
208 |
|
} |
209 |
|
|
210 |
|
static bool ccs_same_domain_initializer_entry(const struct ccs_acl_head *a, |
211 |
|
const struct ccs_acl_head *b) |
212 |
|
{ |
213 |
|
const struct ccs_domain_initializer *p1 = container_of(a, typeof(*p1), |
214 |
|
head); |
215 |
|
const struct ccs_domain_initializer *p2 = container_of(b, typeof(*p2), |
216 |
|
head); |
217 |
|
return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name |
218 |
|
&& p1->domainname == p2->domainname |
219 |
|
&& p1->program == p2->program; |
220 |
|
} |
221 |
|
|
222 |
/** |
/** |
223 |
* ccs_update_domain_initializer_entry - Update "struct ccs_domain_initializer_entry" list. |
* ccs_update_domain_initializer_entry - Update "struct ccs_domain_initializer" list. |
224 |
* |
* |
225 |
* @domainname: The name of domain. May be NULL. |
* @domainname: The name of domain. May be NULL. |
226 |
* @program: The name of program. |
* @program: The name of program. |
234 |
const bool is_not, |
const bool is_not, |
235 |
const bool is_delete) |
const bool is_delete) |
236 |
{ |
{ |
237 |
struct ccs_domain_initializer_entry *entry = NULL; |
struct ccs_domain_initializer e = { .is_not = is_not }; |
|
struct ccs_domain_initializer_entry *ptr; |
|
|
struct ccs_domain_initializer_entry e = { .is_not = is_not }; |
|
238 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
239 |
if (!ccs_is_correct_path(program, 1, -1, -1)) |
if (!ccs_correct_path(program, 1, -1, -1)) |
240 |
return -EINVAL; /* No patterns allowed. */ |
return -EINVAL; /* No patterns allowed. */ |
241 |
if (domainname) { |
if (domainname) { |
242 |
if (!ccs_is_domain_def(domainname) && |
if (!ccs_domain_def(domainname) && |
243 |
ccs_is_correct_path(domainname, 1, -1, -1)) |
ccs_correct_path(domainname, 1, -1, -1)) |
244 |
e.is_last_name = true; |
e.is_last_name = true; |
245 |
else if (!ccs_is_correct_domain(domainname)) |
else if (!ccs_correct_domain(domainname)) |
246 |
return -EINVAL; |
return -EINVAL; |
247 |
e.domainname = ccs_get_name(domainname); |
e.domainname = ccs_get_name(domainname); |
248 |
if (!e.domainname) |
if (!e.domainname) |
251 |
e.program = ccs_get_name(program); |
e.program = ccs_get_name(program); |
252 |
if (!e.program) |
if (!e.program) |
253 |
goto out; |
goto out; |
254 |
if (!is_delete) |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
255 |
entry = kmalloc(sizeof(e), GFP_KERNEL); |
CCS_ID_DOMAIN_INITIALIZER, |
256 |
mutex_lock(&ccs_policy_lock); |
ccs_same_domain_initializer_entry); |
|
list_for_each_entry_rcu(ptr, &ccs_domain_initializer_list, list) { |
|
|
if (ccs_memcmp(ptr, &e, offsetof(typeof(e), is_not), |
|
|
sizeof(e))) |
|
|
continue; |
|
|
ptr->is_deleted = is_delete; |
|
|
error = 0; |
|
|
break; |
|
|
} |
|
|
if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) { |
|
|
list_add_tail_rcu(&entry->list, &ccs_domain_initializer_list); |
|
|
entry = NULL; |
|
|
error = 0; |
|
|
} |
|
|
mutex_unlock(&ccs_policy_lock); |
|
257 |
out: |
out: |
258 |
ccs_put_name(e.domainname); |
ccs_put_name(e.domainname); |
259 |
ccs_put_name(e.program); |
ccs_put_name(e.program); |
|
kfree(entry); |
|
260 |
return error; |
return error; |
261 |
} |
} |
262 |
|
|
263 |
/** |
/** |
264 |
* ccs_read_domain_initializer_policy - Read "struct ccs_domain_initializer_entry" list. |
* ccs_write_domain_initializer - Write "struct ccs_domain_initializer" list. |
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
* |
|
|
* Caller holds ccs_read_lock(). |
|
|
*/ |
|
|
bool ccs_read_domain_initializer_policy(struct ccs_io_buffer *head) |
|
|
{ |
|
|
struct list_head *pos; |
|
|
bool done = true; |
|
|
list_for_each_cookie(pos, head->read_var2, |
|
|
&ccs_domain_initializer_list) { |
|
|
const char *no; |
|
|
const char *from = ""; |
|
|
const char *domain = ""; |
|
|
struct ccs_domain_initializer_entry *ptr; |
|
|
ptr = list_entry(pos, struct ccs_domain_initializer_entry, |
|
|
list); |
|
|
if (ptr->is_deleted) |
|
|
continue; |
|
|
no = ptr->is_not ? "no_" : ""; |
|
|
if (ptr->domainname) { |
|
|
from = " from "; |
|
|
domain = ptr->domainname->name; |
|
|
} |
|
|
done = ccs_io_printf(head, "%s" CCS_KEYWORD_INITIALIZE_DOMAIN |
|
|
"%s%s%s\n", no, ptr->program->name, from, |
|
|
domain); |
|
|
if (!done) |
|
|
break; |
|
|
} |
|
|
return done; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_write_domain_initializer_policy - Write "struct ccs_domain_initializer_entry" list. |
|
265 |
* |
* |
266 |
* @data: String to parse. |
* @data: String to parse. |
|
* @is_not: True if it is "no_initialize_domain" entry. |
|
267 |
* @is_delete: True if it is a delete request. |
* @is_delete: True if it is a delete request. |
268 |
* |
* |
269 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
270 |
*/ |
*/ |
271 |
int ccs_write_domain_initializer_policy(char *data, const bool is_not, |
int ccs_write_domain_initializer(char *data, const bool is_delete, const u8 flags) |
|
const bool is_delete) |
|
272 |
{ |
{ |
273 |
char *cp = strstr(data, " from "); |
char *domainname = strstr(data, " from "); |
274 |
if (cp) { |
if (domainname) { |
275 |
*cp = '\0'; |
*domainname = '\0'; |
276 |
return ccs_update_domain_initializer_entry(cp + 6, data, |
domainname += 6; |
|
is_not, is_delete); |
|
277 |
} |
} |
278 |
return ccs_update_domain_initializer_entry(NULL, data, is_not, |
return ccs_update_domain_initializer_entry(domainname, data, flags, |
279 |
is_delete); |
is_delete); |
280 |
} |
} |
281 |
|
|
282 |
/** |
/** |
283 |
* ccs_is_domain_initializer - Check whether the given program causes domainname reinitialization. |
* ccs_domain_initializer - Check whether the given program causes domainname reinitialization. |
284 |
* |
* |
285 |
* @domainname: The name of domain. |
* @domainname: The name of domain. |
286 |
* @program: The name of program. |
* @program: The name of program. |
291 |
* |
* |
292 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
293 |
*/ |
*/ |
294 |
static bool ccs_is_domain_initializer(const struct ccs_path_info *domainname, |
static bool ccs_domain_initializer(const struct ccs_path_info *domainname, |
295 |
const struct ccs_path_info *program, |
const struct ccs_path_info *program, |
296 |
const struct ccs_path_info *last_name) |
const struct ccs_path_info *last_name) |
297 |
{ |
{ |
298 |
struct ccs_domain_initializer_entry *ptr; |
struct ccs_domain_initializer *ptr; |
299 |
bool flag = false; |
bool flag = false; |
300 |
list_for_each_entry_rcu(ptr, &ccs_domain_initializer_list, list) { |
list_for_each_entry_rcu(ptr, &ccs_policy_list |
301 |
if (ptr->is_deleted) |
[CCS_ID_DOMAIN_INITIALIZER], head.list) { |
302 |
|
if (ptr->head.is_deleted) |
303 |
continue; |
continue; |
304 |
if (ptr->domainname) { |
if (ptr->domainname) { |
305 |
if (!ptr->is_last_name) { |
if (!ptr->is_last_name) { |
321 |
return flag; |
return flag; |
322 |
} |
} |
323 |
|
|
324 |
/* The list for "struct ccs_domain_keeper_entry". */ |
static bool ccs_same_domain_keeper_entry(const struct ccs_acl_head *a, |
325 |
LIST_HEAD(ccs_domain_keeper_list); |
const struct ccs_acl_head *b) |
326 |
|
{ |
327 |
|
const struct ccs_domain_keeper *p1 = container_of(a, typeof(*p1), |
328 |
|
head); |
329 |
|
const struct ccs_domain_keeper *p2 = container_of(b, typeof(*p2), |
330 |
|
head); |
331 |
|
return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name |
332 |
|
&& p1->domainname == p2->domainname |
333 |
|
&& p1->program == p2->program; |
334 |
|
} |
335 |
|
|
336 |
/** |
/** |
337 |
* ccs_update_domain_keeper_entry - Update "struct ccs_domain_keeper_entry" list. |
* ccs_update_domain_keeper_entry - Update "struct ccs_domain_keeper" list. |
338 |
* |
* |
339 |
* @domainname: The name of domain. |
* @domainname: The name of domain. |
340 |
* @program: The name of program. May be NULL. |
* @program: The name of program. May be NULL. |
348 |
const bool is_not, |
const bool is_not, |
349 |
const bool is_delete) |
const bool is_delete) |
350 |
{ |
{ |
351 |
struct ccs_domain_keeper_entry *entry = NULL; |
struct ccs_domain_keeper e = { .is_not = is_not }; |
|
struct ccs_domain_keeper_entry *ptr; |
|
|
struct ccs_domain_keeper_entry e = { .is_not = is_not }; |
|
352 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
353 |
if (!ccs_is_domain_def(domainname) && |
if (!ccs_domain_def(domainname) && |
354 |
ccs_is_correct_path(domainname, 1, -1, -1)) |
ccs_correct_path(domainname, 1, -1, -1)) |
355 |
e.is_last_name = true; |
e.is_last_name = true; |
356 |
else if (!ccs_is_correct_domain(domainname)) |
else if (!ccs_correct_domain(domainname)) |
357 |
return -EINVAL; |
return -EINVAL; |
358 |
if (program) { |
if (program) { |
359 |
if (!ccs_is_correct_path(program, 1, -1, -1)) |
if (!ccs_correct_path(program, 1, -1, -1)) |
360 |
return -EINVAL; |
return -EINVAL; |
361 |
e.program = ccs_get_name(program); |
e.program = ccs_get_name(program); |
362 |
if (!e.program) |
if (!e.program) |
365 |
e.domainname = ccs_get_name(domainname); |
e.domainname = ccs_get_name(domainname); |
366 |
if (!e.domainname) |
if (!e.domainname) |
367 |
goto out; |
goto out; |
368 |
if (!is_delete) |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
369 |
entry = kmalloc(sizeof(e), GFP_KERNEL); |
CCS_ID_DOMAIN_KEEPER, |
370 |
mutex_lock(&ccs_policy_lock); |
ccs_same_domain_keeper_entry); |
|
list_for_each_entry_rcu(ptr, &ccs_domain_keeper_list, list) { |
|
|
if (ccs_memcmp(ptr, &e, offsetof(typeof(e), is_not), |
|
|
sizeof(e))) |
|
|
continue; |
|
|
ptr->is_deleted = is_delete; |
|
|
error = 0; |
|
|
break; |
|
|
} |
|
|
if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) { |
|
|
list_add_tail_rcu(&entry->list, &ccs_domain_keeper_list); |
|
|
entry = NULL; |
|
|
error = 0; |
|
|
} |
|
|
mutex_unlock(&ccs_policy_lock); |
|
371 |
out: |
out: |
372 |
ccs_put_name(e.domainname); |
ccs_put_name(e.domainname); |
373 |
ccs_put_name(e.program); |
ccs_put_name(e.program); |
|
kfree(entry); |
|
374 |
return error; |
return error; |
375 |
} |
} |
376 |
|
|
377 |
/** |
/** |
378 |
* ccs_write_domain_keeper_policy - Write "struct ccs_domain_keeper_entry" list. |
* ccs_write_domain_keeper - Write "struct ccs_domain_keeper" list. |
379 |
* |
* |
380 |
* @data: String to parse. |
* @data: String to parse. |
|
* @is_not: True if it is "no_keep_domain" entry. |
|
381 |
* @is_delete: True if it is a delete request. |
* @is_delete: True if it is a delete request. |
382 |
* |
* |
383 |
|
* Returns 0 on success, negative value otherwise. |
384 |
*/ |
*/ |
385 |
int ccs_write_domain_keeper_policy(char *data, const bool is_not, |
int ccs_write_domain_keeper(char *data, const bool is_delete, const u8 flags) |
|
const bool is_delete) |
|
|
{ |
|
|
char *cp = strstr(data, " from "); |
|
|
if (cp) { |
|
|
*cp = '\0'; |
|
|
return ccs_update_domain_keeper_entry(cp + 6, data, |
|
|
is_not, is_delete); |
|
|
} |
|
|
return ccs_update_domain_keeper_entry(data, NULL, is_not, is_delete); |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_read_domain_keeper_policy - Read "struct ccs_domain_keeper_entry" list. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
* |
|
|
* Caller holds ccs_read_lock(). |
|
|
*/ |
|
|
bool ccs_read_domain_keeper_policy(struct ccs_io_buffer *head) |
|
386 |
{ |
{ |
387 |
struct list_head *pos; |
char *domainname = strstr(data, " from "); |
388 |
bool done = true; |
if (domainname) { |
389 |
list_for_each_cookie(pos, head->read_var2, |
*domainname = '\0'; |
390 |
&ccs_domain_keeper_list) { |
domainname += 6; |
391 |
struct ccs_domain_keeper_entry *ptr; |
} else { |
392 |
const char *no; |
domainname = data; |
393 |
const char *from = ""; |
data = NULL; |
|
const char *program = ""; |
|
|
ptr = list_entry(pos, struct ccs_domain_keeper_entry, list); |
|
|
if (ptr->is_deleted) |
|
|
continue; |
|
|
no = ptr->is_not ? "no_" : ""; |
|
|
if (ptr->program) { |
|
|
from = " from "; |
|
|
program = ptr->program->name; |
|
|
} |
|
|
done = ccs_io_printf(head, "%s" CCS_KEYWORD_KEEP_DOMAIN |
|
|
"%s%s%s\n", no, program, from, |
|
|
ptr->domainname->name); |
|
|
if (!done) |
|
|
break; |
|
394 |
} |
} |
395 |
return done; |
return ccs_update_domain_keeper_entry(domainname, data, flags, |
396 |
|
is_delete); |
397 |
} |
} |
398 |
|
|
399 |
/** |
/** |
400 |
* ccs_is_domain_keeper - Check whether the given program causes domain transition suppression. |
* ccs_domain_keeper - Check whether the given program causes domain transition suppression. |
401 |
* |
* |
402 |
* @domainname: The name of domain. |
* @domainname: The name of domain. |
403 |
* @program: The name of program. |
* @program: The name of program. |
408 |
* |
* |
409 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
410 |
*/ |
*/ |
411 |
static bool ccs_is_domain_keeper(const struct ccs_path_info *domainname, |
static bool ccs_domain_keeper(const struct ccs_path_info *domainname, |
412 |
const struct ccs_path_info *program, |
const struct ccs_path_info *program, |
413 |
const struct ccs_path_info *last_name) |
const struct ccs_path_info *last_name) |
414 |
{ |
{ |
415 |
struct ccs_domain_keeper_entry *ptr; |
struct ccs_domain_keeper *ptr; |
416 |
bool flag = false; |
bool flag = false; |
417 |
list_for_each_entry_rcu(ptr, &ccs_domain_keeper_list, list) { |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_DOMAIN_KEEPER], |
418 |
if (ptr->is_deleted) |
head.list) { |
419 |
|
if (ptr->head.is_deleted) |
420 |
continue; |
continue; |
421 |
if (!ptr->is_last_name) { |
if (!ptr->is_last_name) { |
422 |
if (ptr->domainname != domainname) |
if (ptr->domainname != domainname) |
436 |
return flag; |
return flag; |
437 |
} |
} |
438 |
|
|
439 |
/* The list for "struct ccs_aggregator_entry". */ |
static bool ccs_same_aggregator_entry(const struct ccs_acl_head *a, |
440 |
LIST_HEAD(ccs_aggregator_list); |
const struct ccs_acl_head *b) |
441 |
|
{ |
442 |
|
const struct ccs_aggregator *p1 = container_of(a, typeof(*p1), head); |
443 |
|
const struct ccs_aggregator *p2 = container_of(b, typeof(*p2), head); |
444 |
|
return p1->original_name == p2->original_name && |
445 |
|
p1->aggregated_name == p2->aggregated_name; |
446 |
|
} |
447 |
|
|
448 |
/** |
/** |
449 |
* ccs_update_aggregator_entry - Update "struct ccs_aggregator_entry" list. |
* ccs_update_aggregator_entry - Update "struct ccs_aggregator" list. |
450 |
* |
* |
451 |
* @original_name: The original program's name. |
* @original_name: The original program's name. |
452 |
* @aggregated_name: The aggregated program's name. |
* @aggregated_name: The aggregated program's name. |
458 |
const char *aggregated_name, |
const char *aggregated_name, |
459 |
const bool is_delete) |
const bool is_delete) |
460 |
{ |
{ |
461 |
struct ccs_aggregator_entry *entry = NULL; |
struct ccs_aggregator e = { }; |
|
struct ccs_aggregator_entry *ptr; |
|
|
struct ccs_aggregator_entry e = { }; |
|
462 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
463 |
if (!ccs_is_correct_path(original_name, 1, 0, -1) || |
if (!ccs_correct_path(original_name, 1, 0, -1) || |
464 |
!ccs_is_correct_path(aggregated_name, 1, -1, -1)) |
!ccs_correct_path(aggregated_name, 1, -1, -1)) |
465 |
return -EINVAL; |
return -EINVAL; |
466 |
e.original_name = ccs_get_name(original_name); |
e.original_name = ccs_get_name(original_name); |
467 |
e.aggregated_name = ccs_get_name(aggregated_name); |
e.aggregated_name = ccs_get_name(aggregated_name); |
468 |
if (!e.original_name || !e.aggregated_name) |
if (!e.original_name || !e.aggregated_name) |
469 |
goto out; |
goto out; |
470 |
if (!is_delete) |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
471 |
entry = kmalloc(sizeof(e), GFP_KERNEL); |
CCS_ID_AGGREGATOR, |
472 |
mutex_lock(&ccs_policy_lock); |
ccs_same_aggregator_entry); |
|
list_for_each_entry_rcu(ptr, &ccs_aggregator_list, list) { |
|
|
if (ccs_memcmp(ptr, &e, offsetof(typeof(e), original_name), |
|
|
sizeof(e))) |
|
|
continue; |
|
|
ptr->is_deleted = is_delete; |
|
|
error = 0; |
|
|
break; |
|
|
} |
|
|
if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) { |
|
|
list_add_tail_rcu(&entry->list, &ccs_aggregator_list); |
|
|
entry = NULL; |
|
|
error = 0; |
|
|
} |
|
|
mutex_unlock(&ccs_policy_lock); |
|
473 |
out: |
out: |
474 |
ccs_put_name(e.original_name); |
ccs_put_name(e.original_name); |
475 |
ccs_put_name(e.aggregated_name); |
ccs_put_name(e.aggregated_name); |
|
kfree(entry); |
|
476 |
return error; |
return error; |
477 |
} |
} |
478 |
|
|
479 |
/** |
/** |
480 |
* ccs_read_aggregator_policy - Read "struct ccs_aggregator_entry" list. |
* ccs_write_aggregator - Write "struct ccs_aggregator" list. |
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
* |
|
|
* Caller holds ccs_read_lock(). |
|
|
*/ |
|
|
bool ccs_read_aggregator_policy(struct ccs_io_buffer *head) |
|
|
{ |
|
|
struct list_head *pos; |
|
|
bool done = true; |
|
|
list_for_each_cookie(pos, head->read_var2, &ccs_aggregator_list) { |
|
|
struct ccs_aggregator_entry *ptr; |
|
|
ptr = list_entry(pos, struct ccs_aggregator_entry, list); |
|
|
if (ptr->is_deleted) |
|
|
continue; |
|
|
done = ccs_io_printf(head, CCS_KEYWORD_AGGREGATOR "%s %s\n", |
|
|
ptr->original_name->name, |
|
|
ptr->aggregated_name->name); |
|
|
if (!done) |
|
|
break; |
|
|
} |
|
|
return done; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_write_aggregator_policy - Write "struct ccs_aggregator_entry" list. |
|
481 |
* |
* |
482 |
* @data: String to parse. |
* @data: String to parse. |
483 |
* @is_delete: True if it is a delete request. |
* @is_delete: True if it is a delete request. |
484 |
* |
* |
485 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
486 |
*/ |
*/ |
487 |
int ccs_write_aggregator_policy(char *data, const bool is_delete) |
int ccs_write_aggregator(char *data, const bool is_delete, const u8 flags) |
488 |
{ |
{ |
489 |
char *w[2]; |
char *w[2]; |
490 |
if (!ccs_tokenize(data, w, sizeof(w)) || !w[1][0]) |
if (!ccs_tokenize(data, w, sizeof(w)) || !w[1][0]) |
507 |
struct ccs_path_info name; |
struct ccs_path_info name; |
508 |
name.name = domainname; |
name.name = domainname; |
509 |
ccs_fill_path_info(&name); |
ccs_fill_path_info(&name); |
510 |
mutex_lock(&ccs_policy_lock); |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
511 |
|
return 0; |
512 |
/* Is there an active domain? */ |
/* Is there an active domain? */ |
513 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
514 |
/* Never delete ccs_kernel_domain */ |
/* Never delete ccs_kernel_domain */ |
525 |
} |
} |
526 |
|
|
527 |
/** |
/** |
528 |
* ccs_find_or_assign_new_domain - Create a domain. |
* ccs_assign_domain - Create a domain. |
529 |
* |
* |
530 |
* @domainname: The name of domain. |
* @domainname: The name of domain. |
531 |
* @profile: Profile number to assign if the domain was newly created. |
* @profile: Profile number to assign if the domain was newly created. |
532 |
* |
* |
533 |
* Returns pointer to "struct ccs_domain_info" on success, NULL otherwise. |
* Returns pointer to "struct ccs_domain_info" on success, NULL otherwise. |
534 |
*/ |
*/ |
535 |
struct ccs_domain_info *ccs_find_or_assign_new_domain(const char *domainname, |
struct ccs_domain_info *ccs_assign_domain(const char *domainname, |
536 |
const u8 profile) |
const u8 profile) |
537 |
{ |
{ |
538 |
struct ccs_domain_info *entry; |
struct ccs_domain_info e = { }; |
539 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *entry = NULL; |
|
const struct ccs_path_info *saved_domainname; |
|
540 |
bool found = false; |
bool found = false; |
541 |
|
|
542 |
if (!ccs_is_correct_domain(domainname)) |
if (!ccs_correct_domain(domainname)) |
543 |
return NULL; |
return NULL; |
544 |
saved_domainname = ccs_get_name(domainname); |
e.profile = profile; |
545 |
if (!saved_domainname) |
e.domainname = ccs_get_name(domainname); |
546 |
|
if (!e.domainname) |
547 |
return NULL; |
return NULL; |
548 |
entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
549 |
mutex_lock(&ccs_policy_lock); |
goto out; |
550 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
list_for_each_entry_rcu(entry, &ccs_domain_list, list) { |
551 |
if (domain->is_deleted || |
if (entry->is_deleted || |
552 |
ccs_pathcmp(saved_domainname, domain->domainname)) |
ccs_pathcmp(e.domainname, entry->domainname)) |
553 |
continue; |
continue; |
554 |
found = true; |
found = true; |
555 |
break; |
break; |
556 |
} |
} |
557 |
if (!found && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!found) { |
558 |
INIT_LIST_HEAD(&entry->acl_info_list); |
entry = ccs_commit_ok(&e, sizeof(e)); |
559 |
entry->domainname = saved_domainname; |
if (entry) { |
560 |
saved_domainname = NULL; |
INIT_LIST_HEAD(&entry->acl_info_list); |
561 |
entry->profile = profile; |
list_add_tail_rcu(&entry->list, &ccs_domain_list); |
562 |
list_add_tail_rcu(&entry->list, &ccs_domain_list); |
found = true; |
563 |
domain = entry; |
} |
|
entry = NULL; |
|
|
found = true; |
|
564 |
} |
} |
565 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
566 |
ccs_put_name(saved_domainname); |
out: |
567 |
kfree(entry); |
ccs_put_name(e.domainname); |
568 |
return found ? domain : NULL; |
return found ? entry : NULL; |
569 |
} |
} |
570 |
|
|
571 |
/** |
/** |
572 |
* ccs_find_next_domain - Find a domain. |
* ccs_find_next_domain - Find a domain. |
573 |
* |
* |
574 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
575 |
* |
* |
576 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
577 |
* |
* |
578 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
579 |
*/ |
*/ |
580 |
static int ccs_find_next_domain(struct ccs_execve_entry *ee) |
static int ccs_find_next_domain(struct ccs_execve *ee) |
581 |
{ |
{ |
582 |
struct ccs_request_info *r = &ee->r; |
struct ccs_request_info *r = &ee->r; |
583 |
const struct ccs_path_info *handler = ee->handler; |
const struct ccs_path_info *handler = ee->handler; |
584 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
585 |
const char *old_domain_name = r->domain->domainname->name; |
struct ccs_domain_info * const old_domain = ccs_current_domain(); |
586 |
|
const char *old_domain_name = old_domain->domainname->name; |
587 |
struct linux_binprm *bprm = ee->bprm; |
struct linux_binprm *bprm = ee->bprm; |
588 |
const u32 ccs_flags = current->ccs_flags; |
struct task_struct *task = current; |
589 |
|
const u32 ccs_flags = task->ccs_flags; |
590 |
struct ccs_path_info rn = { }; /* real name */ |
struct ccs_path_info rn = { }; /* real name */ |
591 |
struct ccs_path_info ln; /* last name */ |
struct ccs_path_info ln; /* last name */ |
592 |
int retval; |
int retval; |
593 |
bool need_kfree = false; |
bool need_kfree = false; |
594 |
|
bool domain_created = false; |
595 |
ln.name = ccs_last_word(old_domain_name); |
ln.name = ccs_last_word(old_domain_name); |
596 |
ccs_fill_path_info(&ln); |
ccs_fill_path_info(&ln); |
597 |
retry: |
retry: |
620 |
goto out; |
goto out; |
621 |
} |
} |
622 |
} else { |
} else { |
623 |
struct ccs_aggregator_entry *ptr; |
struct ccs_aggregator *ptr; |
624 |
/* Check 'aggregator' directive. */ |
/* Check 'aggregator' directive. */ |
625 |
list_for_each_entry_rcu(ptr, &ccs_aggregator_list, list) { |
list_for_each_entry_rcu(ptr, |
626 |
if (ptr->is_deleted || |
&ccs_policy_list[CCS_ID_AGGREGATOR], |
627 |
|
head.list) { |
628 |
|
if (ptr->head.is_deleted || |
629 |
!ccs_path_matches_pattern(&rn, ptr->original_name)) |
!ccs_path_matches_pattern(&rn, ptr->original_name)) |
630 |
continue; |
continue; |
631 |
kfree(rn.name); |
kfree(rn.name); |
636 |
} |
} |
637 |
|
|
638 |
/* Check execute permission. */ |
/* Check execute permission. */ |
639 |
retval = ccs_exec_perm(r, &rn); |
retval = ccs_path_permission(r, CCS_TYPE_EXECUTE, &rn); |
640 |
if (retval == 1) |
if (retval == CCS_RETRY_REQUEST) |
641 |
goto retry; |
goto retry; |
642 |
if (retval < 0) |
if (retval < 0) |
643 |
goto out; |
goto out; |
644 |
} |
} |
645 |
|
|
646 |
/* Calculate domain to transit to. */ |
/* Calculate domain to transit to. */ |
647 |
if (ccs_is_domain_initializer(r->domain->domainname, &rn, &ln)) { |
if (ccs_domain_initializer(old_domain->domainname, &rn, &ln)) { |
648 |
/* Transit to the child of ccs_kernel_domain domain. */ |
/* Transit to the child of ccs_kernel_domain domain. */ |
649 |
snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, ROOT_NAME " " "%s", |
snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, ROOT_NAME " " "%s", |
650 |
rn.name); |
rn.name); |
651 |
} else if (r->domain == &ccs_kernel_domain && !ccs_policy_loaded) { |
} else if (old_domain == &ccs_kernel_domain && !ccs_policy_loaded) { |
652 |
/* |
/* |
653 |
* Needn't to transit from kernel domain before starting |
* Needn't to transit from kernel domain before starting |
654 |
* /sbin/init. But transit from kernel domain if executing |
* /sbin/init. But transit from kernel domain if executing |
655 |
* initializers because they might start before /sbin/init. |
* initializers because they might start before /sbin/init. |
656 |
*/ |
*/ |
657 |
domain = r->domain; |
domain = old_domain; |
658 |
} else if (ccs_is_domain_keeper(r->domain->domainname, &rn, &ln)) { |
} else if (ccs_domain_keeper(old_domain->domainname, &rn, &ln)) { |
659 |
/* Keep current domain. */ |
/* Keep current domain. */ |
660 |
domain = r->domain; |
domain = old_domain; |
661 |
} else { |
} else { |
662 |
/* Normal domain transition. */ |
/* Normal domain transition. */ |
663 |
snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "%s %s", |
snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "%s %s", |
668 |
domain = ccs_find_domain(ee->tmp); |
domain = ccs_find_domain(ee->tmp); |
669 |
if (domain) |
if (domain) |
670 |
goto done; |
goto done; |
671 |
if (r->mode == CCS_MAC_MODE_ENFORCING) { |
if (r->mode == CCS_CONFIG_ENFORCING) { |
672 |
int error = ccs_supervisor(r, "# wants to create domain\n" |
int error = ccs_supervisor(r, "# wants to create domain\n" |
673 |
"%s\n", ee->tmp); |
"%s\n", ee->tmp); |
674 |
if (error == 1) |
if (error == CCS_RETRY_REQUEST) |
675 |
goto retry; |
goto retry; |
676 |
if (error < 0) |
if (error < 0) |
677 |
goto done; |
goto done; |
678 |
} |
} |
679 |
domain = ccs_find_or_assign_new_domain(ee->tmp, r->profile); |
domain = ccs_assign_domain(ee->tmp, r->profile); |
680 |
if (domain) |
if (domain) |
681 |
ccs_audit_domain_creation_log(r->domain); |
domain_created = true; |
682 |
done: |
done: |
683 |
if (!domain) { |
if (!domain) { |
684 |
printk(KERN_WARNING "ERROR: Domain '%s' not defined.\n", |
retval = (r->mode == CCS_CONFIG_ENFORCING) ? -EPERM : 0; |
685 |
ee->tmp); |
if (!old_domain->domain_transition_failed) { |
686 |
if (r->mode == CCS_MAC_MODE_ENFORCING) |
old_domain->domain_transition_failed = true; |
687 |
retval = -EPERM; |
r->granted = false; |
688 |
else { |
ccs_write_log(r, CCS_KEYWORD_TRANSITION_FAILED "\n"); |
689 |
retval = 0; |
printk(KERN_WARNING |
690 |
r->domain->domain_transition_failed = true; |
"ERROR: Domain '%s' not defined.\n", ee->tmp); |
691 |
} |
} |
692 |
} else { |
} else { |
693 |
retval = 0; |
retval = 0; |
694 |
} |
} |
695 |
out: |
if (!retval && handler) |
696 |
|
ccs_audit_execute_handler_log(ee); |
697 |
|
/* |
698 |
|
* Tell GC that I started execve(). |
699 |
|
* Also, tell open_exec() to check read permission. |
700 |
|
*/ |
701 |
|
task->ccs_flags |= CCS_TASK_IS_IN_EXECVE; |
702 |
|
/* |
703 |
|
* Make task->ccs_flags visible to GC before changing |
704 |
|
* task->ccs_domain_info . |
705 |
|
*/ |
706 |
|
smp_mb(); |
707 |
|
/* |
708 |
|
* Proceed to the next domain in order to allow reaching via PID. |
709 |
|
* It will be reverted if execve() failed. Reverting is not good. |
710 |
|
* But it is better than being unable to reach via PID in interactive |
711 |
|
* enforcing mode. |
712 |
|
*/ |
713 |
if (domain) |
if (domain) |
714 |
r->domain = domain; |
task->ccs_domain_info = domain; |
715 |
|
if (domain_created) |
716 |
|
ccs_audit_domain_creation_log(); |
717 |
|
out: |
718 |
if (need_kfree) |
if (need_kfree) |
719 |
kfree(rn.name); |
kfree(rn.name); |
720 |
return retval; |
return retval; |
723 |
/** |
/** |
724 |
* ccs_environ - Check permission for environment variable names. |
* ccs_environ - Check permission for environment variable names. |
725 |
* |
* |
726 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
727 |
* |
* |
728 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
729 |
*/ |
*/ |
730 |
static int ccs_environ(struct ccs_execve_entry *ee) |
static int ccs_environ(struct ccs_execve *ee) |
731 |
{ |
{ |
732 |
struct ccs_request_info *r = &ee->r; |
struct ccs_request_info *r = &ee->r; |
733 |
struct linux_binprm *bprm = ee->bprm; |
struct linux_binprm *bprm = ee->bprm; |
734 |
char *arg_ptr = ee->tmp; |
/* env_page->data is allocated by ccs_dump_page(). */ |
735 |
|
struct ccs_page_dump env_page = { }; |
736 |
|
char *arg_ptr; /* Size is CCS_EXEC_TMPSIZE bytes */ |
737 |
int arg_len = 0; |
int arg_len = 0; |
738 |
unsigned long pos = bprm->p; |
unsigned long pos = bprm->p; |
739 |
int offset = pos % PAGE_SIZE; |
int offset = pos % PAGE_SIZE; |
741 |
int envp_count = bprm->envc; |
int envp_count = bprm->envc; |
742 |
/* printk(KERN_DEBUG "start %d %d\n", argv_count, envp_count); */ |
/* printk(KERN_DEBUG "start %d %d\n", argv_count, envp_count); */ |
743 |
int error = -ENOMEM; |
int error = -ENOMEM; |
744 |
|
ee->r.type = CCS_MAC_ENVIRON; |
745 |
|
ee->r.mode = ccs_get_mode(ccs_current_domain()->profile, |
746 |
|
CCS_MAC_ENVIRON); |
747 |
if (!r->mode || !envp_count) |
if (!r->mode || !envp_count) |
748 |
return 0; |
return 0; |
749 |
|
arg_ptr = kzalloc(CCS_EXEC_TMPSIZE, CCS_GFP_FLAGS); |
750 |
|
if (!arg_ptr) |
751 |
|
goto out; |
752 |
while (error == -ENOMEM) { |
while (error == -ENOMEM) { |
753 |
if (!ccs_dump_page(bprm, pos, &ee->dump)) |
if (!ccs_dump_page(bprm, pos, &env_page)) |
754 |
goto out; |
goto out; |
755 |
pos += PAGE_SIZE - offset; |
pos += PAGE_SIZE - offset; |
756 |
/* Read. */ |
/* Read. */ |
757 |
while (argv_count && offset < PAGE_SIZE) { |
while (argv_count && offset < PAGE_SIZE) { |
758 |
const char *kaddr = ee->dump.data; |
if (!env_page.data[offset++]) |
|
if (!kaddr[offset++]) |
|
759 |
argv_count--; |
argv_count--; |
760 |
} |
} |
761 |
if (argv_count) { |
if (argv_count) { |
763 |
continue; |
continue; |
764 |
} |
} |
765 |
while (offset < PAGE_SIZE) { |
while (offset < PAGE_SIZE) { |
766 |
const char *kaddr = ee->dump.data; |
const unsigned char c = env_page.data[offset++]; |
|
const unsigned char c = kaddr[offset++]; |
|
767 |
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
768 |
if (c == '=') { |
if (c == '=') { |
769 |
arg_ptr[arg_len++] = '\0'; |
arg_ptr[arg_len++] = '\0'; |
799 |
out: |
out: |
800 |
if (r->mode != 3) |
if (r->mode != 3) |
801 |
error = 0; |
error = 0; |
802 |
|
kfree(env_page.data); |
803 |
|
kfree(arg_ptr); |
804 |
return error; |
return error; |
805 |
} |
} |
806 |
|
|
851 |
* |
* |
852 |
* Returns number of directories to strip. |
* Returns number of directories to strip. |
853 |
*/ |
*/ |
854 |
static inline int ccs_root_depth(struct dentry *dentry, struct vfsmount *vfsmnt) |
static int ccs_root_depth(struct dentry *dentry, struct vfsmount *vfsmnt) |
855 |
{ |
{ |
856 |
int depth = 0; |
int depth = 0; |
857 |
ccs_realpath_lock(); |
ccs_realpath_lock(); |
905 |
return depth; |
return depth; |
906 |
} |
} |
907 |
|
|
|
static LIST_HEAD(ccs_execve_list); |
|
|
static DEFINE_SPINLOCK(ccs_execve_list_lock); |
|
|
|
|
|
/** |
|
|
* ccs_allocate_execve_entry - Allocate memory for execve(). |
|
|
* |
|
|
* Returns pointer to "struct ccs_execve_entry" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_execve_entry *ccs_allocate_execve_entry(void) |
|
|
{ |
|
|
struct ccs_execve_entry *ee = kzalloc(sizeof(*ee), GFP_KERNEL); |
|
|
if (!ee) |
|
|
return NULL; |
|
|
ee->tmp = kzalloc(CCS_EXEC_TMPSIZE, GFP_KERNEL); |
|
|
if (!ee->tmp) { |
|
|
kfree(ee); |
|
|
return NULL; |
|
|
} |
|
|
ee->reader_idx = ccs_read_lock(); |
|
|
/* ee->dump->data is allocated by ccs_dump_page(). */ |
|
|
ee->task = current; |
|
|
spin_lock(&ccs_execve_list_lock); |
|
|
list_add(&ee->list, &ccs_execve_list); |
|
|
spin_unlock(&ccs_execve_list_lock); |
|
|
return ee; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_find_execve_entry - Find ccs_execve_entry of current process. |
|
|
* |
|
|
* Returns pointer to "struct ccs_execve_entry" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_execve_entry *ccs_find_execve_entry(void) |
|
|
{ |
|
|
struct task_struct *task = current; |
|
|
struct ccs_execve_entry *ee = NULL; |
|
|
struct ccs_execve_entry *p; |
|
|
spin_lock(&ccs_execve_list_lock); |
|
|
list_for_each_entry(p, &ccs_execve_list, list) { |
|
|
if (p->task != task) |
|
|
continue; |
|
|
ee = p; |
|
|
break; |
|
|
} |
|
|
spin_unlock(&ccs_execve_list_lock); |
|
|
return ee; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_free_execve_entry - Free memory for execve(). |
|
|
* |
|
|
* @ee: Pointer to "struct ccs_execve_entry". |
|
|
*/ |
|
|
static void ccs_free_execve_entry(struct ccs_execve_entry *ee) |
|
|
{ |
|
|
if (!ee) |
|
|
return; |
|
|
spin_lock(&ccs_execve_list_lock); |
|
|
list_del(&ee->list); |
|
|
spin_unlock(&ccs_execve_list_lock); |
|
|
kfree(ee->handler_path); |
|
|
kfree(ee->tmp); |
|
|
kfree(ee->dump.data); |
|
|
ccs_read_unlock(ee->reader_idx); |
|
|
kfree(ee); |
|
|
} |
|
|
|
|
908 |
/** |
/** |
909 |
* ccs_try_alt_exec - Try to start execute handler. |
* ccs_try_alt_exec - Try to start execute handler. |
910 |
* |
* |
911 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
912 |
* |
* |
913 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
914 |
*/ |
*/ |
915 |
static int ccs_try_alt_exec(struct ccs_execve_entry *ee) |
static int ccs_try_alt_exec(struct ccs_execve *ee) |
916 |
{ |
{ |
917 |
/* |
/* |
918 |
* Contents of modified bprm. |
* Contents of modified bprm. |
958 |
struct task_struct *task = current; |
struct task_struct *task = current; |
959 |
|
|
960 |
/* Close the requested program's dentry. */ |
/* Close the requested program's dentry. */ |
961 |
|
ee->obj.path1.dentry = NULL; |
962 |
|
ee->obj.path1.mnt = NULL; |
963 |
|
ee->obj.validate_done = false; |
964 |
allow_write_access(bprm->file); |
allow_write_access(bprm->file); |
965 |
fput(bprm->file); |
fput(bprm->file); |
966 |
bprm->file = NULL; |
bprm->file = NULL; |
1008 |
"pid=%d uid=%d gid=%d euid=%d egid=%d suid=%d " |
"pid=%d uid=%d gid=%d euid=%d egid=%d suid=%d " |
1009 |
"sgid=%d fsuid=%d fsgid=%d state[0]=%u " |
"sgid=%d fsuid=%d fsgid=%d state[0]=%u " |
1010 |
"state[1]=%u state[2]=%u", |
"state[1]=%u state[2]=%u", |
1011 |
(pid_t) sys_getpid(), current_uid(), current_gid(), |
(pid_t) ccsecurity_exports.sys_getpid(), |
1012 |
current_euid(), current_egid(), current_suid(), |
current_uid(), current_gid(), current_euid(), |
1013 |
current_sgid(), current_fsuid(), current_fsgid(), |
current_egid(), current_suid(), current_sgid(), |
1014 |
|
current_fsuid(), current_fsgid(), |
1015 |
(u8) (ccs_flags >> 24), (u8) (ccs_flags >> 16), |
(u8) (ccs_flags >> 24), (u8) (ccs_flags >> 16), |
1016 |
(u8) (ccs_flags >> 8)); |
(u8) (ccs_flags >> 8)); |
1017 |
retval = copy_strings_kernel(1, &cp, bprm); |
retval = copy_strings_kernel(1, &cp, bprm); |
1051 |
{ |
{ |
1052 |
int depth = ccs_get_root_depth(); |
int depth = ccs_get_root_depth(); |
1053 |
int len = ee->handler->total_len + 1; |
int len = ee->handler->total_len + 1; |
1054 |
char *cp = kmalloc(len, GFP_KERNEL); |
char *cp = kmalloc(len, CCS_GFP_FLAGS); |
1055 |
if (!cp) { |
if (!cp) { |
1056 |
retval = ENOMEM; |
retval = -ENOMEM; |
1057 |
goto out; |
goto out; |
1058 |
} |
} |
1059 |
ee->handler_path = cp; |
ee->handler_path = cp; |
1082 |
#endif |
#endif |
1083 |
#endif |
#endif |
1084 |
|
|
1085 |
/* OK, now restart the process with execute handler program's dentry. */ |
/* |
1086 |
|
* OK, now restart the process with execute handler program's dentry. |
1087 |
|
*/ |
1088 |
filp = open_exec(ee->handler_path); |
filp = open_exec(ee->handler_path); |
1089 |
if (IS_ERR(filp)) { |
if (IS_ERR(filp)) { |
1090 |
retval = PTR_ERR(filp); |
retval = PTR_ERR(filp); |
1091 |
goto out; |
goto out; |
1092 |
} |
} |
1093 |
|
ee->obj.path1.dentry = filp->f_dentry; |
1094 |
|
ee->obj.path1.mnt = filp->f_vfsmnt; |
1095 |
bprm->file = filp; |
bprm->file = filp; |
1096 |
bprm->filename = ee->handler_path; |
bprm->filename = ee->handler_path; |
1097 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) |
1110 |
/** |
/** |
1111 |
* ccs_find_execute_handler - Find an execute handler. |
* ccs_find_execute_handler - Find an execute handler. |
1112 |
* |
* |
1113 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
1114 |
* @type: Type of execute handler. |
* @type: Type of execute handler. |
1115 |
* |
* |
1116 |
* Returns true if found, false otherwise. |
* Returns true if found, false otherwise. |
1117 |
* |
* |
1118 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1119 |
*/ |
*/ |
1120 |
static bool ccs_find_execute_handler(struct ccs_execve_entry *ee, |
static bool ccs_find_execute_handler(struct ccs_execve *ee, const u8 type) |
|
const u8 type) |
|
1121 |
{ |
{ |
1122 |
struct task_struct *task = current; |
struct task_struct *task = current; |
1123 |
const struct ccs_domain_info *domain = ccs_current_domain(); |
const struct ccs_domain_info * const domain = ccs_current_domain(); |
1124 |
struct ccs_acl_info *ptr; |
struct ccs_acl_info *ptr; |
1125 |
bool found = false; |
bool found = false; |
1126 |
/* |
/* |
1129 |
*/ |
*/ |
1130 |
if (task->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) |
if (task->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) |
1131 |
return false; |
return false; |
1132 |
list_for_each_entry(ptr, &domain->acl_info_list, list) { |
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
1133 |
struct ccs_execute_handler_record *acl; |
struct ccs_execute_handler *acl; |
1134 |
if (ptr->type != type) |
if (ptr->type != type) |
1135 |
continue; |
continue; |
1136 |
acl = container_of(ptr, struct ccs_execute_handler_record, |
acl = container_of(ptr, struct ccs_execute_handler, head); |
|
head); |
|
1137 |
ee->handler = acl->handler; |
ee->handler = acl->handler; |
1138 |
|
ee->handler_type = type; |
1139 |
found = true; |
found = true; |
1140 |
break; |
break; |
1141 |
} |
} |
1155 |
struct ccs_page_dump *dump) |
struct ccs_page_dump *dump) |
1156 |
{ |
{ |
1157 |
struct page *page; |
struct page *page; |
1158 |
/* dump->data is released by ccs_free_execve_entry(). */ |
/* dump->data is released by ccs_finish_execve(). */ |
1159 |
if (!dump->data) { |
if (!dump->data) { |
1160 |
dump->data = kzalloc(PAGE_SIZE, GFP_KERNEL); |
dump->data = kzalloc(PAGE_SIZE, CCS_GFP_FLAGS); |
1161 |
if (!dump->data) |
if (!dump->data) |
1162 |
return false; |
return false; |
1163 |
} |
} |
1165 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU) |
1166 |
if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0) |
if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0) |
1167 |
return false; |
return false; |
1168 |
#elif defined(RHEL_MAJOR) && RHEL_MAJOR == 5 && defined(RHEL_MINOR) && RHEL_MINOR == 3 && defined(CONFIG_MMU) |
#elif defined(RHEL_MAJOR) && RHEL_MAJOR == 5 && defined(RHEL_MINOR) && RHEL_MINOR >= 3 && defined(CONFIG_MMU) |
1169 |
|
if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0) |
1170 |
|
return false; |
1171 |
|
#elif defined(AX_MAJOR) && AX_MAJOR == 3 && defined(AX_MINOR) && AX_MINOR >= 2 && defined(CONFIG_MMU) |
1172 |
if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0) |
if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0) |
1173 |
return false; |
return false; |
1174 |
#else |
#else |
1183 |
*/ |
*/ |
1184 |
char *kaddr = kmap_atomic(page, KM_USER0); |
char *kaddr = kmap_atomic(page, KM_USER0); |
1185 |
dump->page = page; |
dump->page = page; |
1186 |
memcpy(dump->data + offset, kaddr + offset, PAGE_SIZE - offset); |
memcpy(dump->data + offset, kaddr + offset, |
1187 |
|
PAGE_SIZE - offset); |
1188 |
kunmap_atomic(kaddr, KM_USER0); |
kunmap_atomic(kaddr, KM_USER0); |
1189 |
} |
} |
1190 |
/* Same with put_arg_page(page) in fs/exec.c */ |
/* Same with put_arg_page(page) in fs/exec.c */ |
1191 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU) |
1192 |
put_page(page); |
put_page(page); |
1193 |
#elif defined(RHEL_MAJOR) && RHEL_MAJOR == 5 && defined(RHEL_MINOR) && RHEL_MINOR == 3 && defined(CONFIG_MMU) |
#elif defined(RHEL_MAJOR) && RHEL_MAJOR == 5 && defined(RHEL_MINOR) && RHEL_MINOR >= 3 && defined(CONFIG_MMU) |
1194 |
|
put_page(page); |
1195 |
|
#elif defined(AX_MAJOR) && AX_MAJOR == 3 && defined(AX_MINOR) && AX_MINOR >= 2 && defined(CONFIG_MMU) |
1196 |
put_page(page); |
put_page(page); |
1197 |
#endif |
#endif |
1198 |
return true; |
return true; |
1199 |
} |
} |
1200 |
|
|
1201 |
/** |
/** |
|
* ccs_fetch_next_domain - Fetch next_domain from the list. |
|
|
* |
|
|
* Returns pointer to "struct ccs_domain_info" which will be used if execve() |
|
|
* succeeds. This function does not return NULL. |
|
|
*/ |
|
|
struct ccs_domain_info *ccs_fetch_next_domain(void) |
|
|
{ |
|
|
struct ccs_execve_entry *ee = ccs_find_execve_entry(); |
|
|
struct ccs_domain_info *next_domain = NULL; |
|
|
if (ee) |
|
|
next_domain = ee->r.domain; |
|
|
if (!next_domain) |
|
|
next_domain = ccs_current_domain(); |
|
|
return next_domain; |
|
|
} |
|
|
|
|
|
/** |
|
1202 |
* ccs_start_execve - Prepare for execve() operation. |
* ccs_start_execve - Prepare for execve() operation. |
1203 |
* |
* |
1204 |
* @bprm: Pointer to "struct linux_binprm". |
* @bprm: Pointer to "struct linux_binprm". |
1205 |
|
* @eep: Pointer to "struct ccs_execve *". |
1206 |
* |
* |
1207 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1208 |
*/ |
*/ |
1209 |
int ccs_start_execve(struct linux_binprm *bprm) |
static int ccs_start_execve(struct linux_binprm *bprm, |
1210 |
|
struct ccs_execve **eep) |
1211 |
{ |
{ |
1212 |
int retval; |
int retval; |
1213 |
struct task_struct *task = current; |
struct task_struct *task = current; |
1214 |
struct ccs_execve_entry *ee = ccs_allocate_execve_entry(); |
struct ccs_execve *ee; |
1215 |
if (!ccs_policy_loaded) |
*eep = NULL; |
1216 |
ccs_load_policy(bprm->filename); |
ee = kzalloc(sizeof(*ee), CCS_GFP_FLAGS); |
1217 |
if (!ee) |
if (!ee) |
1218 |
return -ENOMEM; |
return -ENOMEM; |
1219 |
ccs_init_request_info(&ee->r, NULL, CCS_MAC_FILE_EXECUTE); |
ee->tmp = kzalloc(CCS_EXEC_TMPSIZE, CCS_GFP_FLAGS); |
1220 |
|
if (!ee->tmp) { |
1221 |
|
kfree(ee); |
1222 |
|
return -ENOMEM; |
1223 |
|
} |
1224 |
|
ee->reader_idx = ccs_read_lock(); |
1225 |
|
/* ee->dump->data is allocated by ccs_dump_page(). */ |
1226 |
|
ee->previous_domain = task->ccs_domain_info; |
1227 |
|
/* Clear manager flag. */ |
1228 |
|
task->ccs_flags &= ~CCS_TASK_IS_MANAGER; |
1229 |
|
*eep = ee; |
1230 |
|
ccs_init_request_info(&ee->r, CCS_MAC_FILE_EXECUTE); |
1231 |
ee->r.ee = ee; |
ee->r.ee = ee; |
1232 |
ee->bprm = bprm; |
ee->bprm = bprm; |
1233 |
ee->r.obj = &ee->obj; |
ee->r.obj = &ee->obj; |
1234 |
ee->obj.path1.dentry = bprm->file->f_dentry; |
ee->obj.path1.dentry = bprm->file->f_dentry; |
1235 |
ee->obj.path1.mnt = bprm->file->f_vfsmnt; |
ee->obj.path1.mnt = bprm->file->f_vfsmnt; |
1236 |
/* Clear manager flag. */ |
/* |
1237 |
task->ccs_flags &= ~CCS_TASK_IS_POLICY_MANAGER; |
* No need to call ccs_environ() for execute handler because envp[] is |
1238 |
if (ccs_find_execute_handler(ee, CCS_TYPE_EXECUTE_HANDLER)) { |
* moved to argv[]. |
1239 |
retval = ccs_try_alt_exec(ee); |
*/ |
1240 |
if (!retval) |
if (ccs_find_execute_handler(ee, CCS_TYPE_EXECUTE_HANDLER)) |
1241 |
ccs_audit_execute_handler_log(ee, true); |
return ccs_try_alt_exec(ee); |
|
goto ok; |
|
|
} |
|
1242 |
retval = ccs_find_next_domain(ee); |
retval = ccs_find_next_domain(ee); |
1243 |
if (retval != -EPERM) |
if (retval == -EPERM) { |
1244 |
goto ok; |
if (ccs_find_execute_handler(ee, |
1245 |
if (ccs_find_execute_handler(ee, CCS_TYPE_DENIED_EXECUTE_HANDLER)) { |
CCS_TYPE_DENIED_EXECUTE_HANDLER)) |
1246 |
retval = ccs_try_alt_exec(ee); |
return ccs_try_alt_exec(ee); |
|
if (!retval) |
|
|
ccs_audit_execute_handler_log(ee, false); |
|
1247 |
} |
} |
1248 |
ok: |
if (!retval) |
1249 |
if (retval < 0) |
retval = ccs_environ(ee); |
|
goto out; |
|
|
ee->r.mode = ccs_get_mode(ee->r.profile, CCS_MAC_ENVIRON); |
|
|
retval = ccs_environ(ee); |
|
|
if (retval < 0) |
|
|
goto out; |
|
|
task->ccs_flags |= CCS_CHECK_READ_FOR_OPEN_EXEC; |
|
|
retval = 0; |
|
|
out: |
|
|
if (retval) |
|
|
ccs_finish_execve(retval); |
|
1250 |
return retval; |
return retval; |
1251 |
} |
} |
1252 |
|
|
1254 |
* ccs_finish_execve - Clean up execve() operation. |
* ccs_finish_execve - Clean up execve() operation. |
1255 |
* |
* |
1256 |
* @retval: Return code of an execve() operation. |
* @retval: Return code of an execve() operation. |
1257 |
|
* @ee: Pointer to "struct ccs_execve". |
1258 |
* |
* |
1259 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1260 |
*/ |
*/ |
1261 |
void ccs_finish_execve(int retval) |
static void ccs_finish_execve(int retval, struct ccs_execve *ee) |
1262 |
{ |
{ |
1263 |
struct task_struct *task = current; |
struct task_struct *task = current; |
|
struct ccs_execve_entry *ee = ccs_find_execve_entry(); |
|
|
task->ccs_flags &= ~CCS_CHECK_READ_FOR_OPEN_EXEC; |
|
1264 |
if (!ee) |
if (!ee) |
1265 |
return; |
return; |
1266 |
if (retval < 0) |
if (retval < 0) { |
1267 |
goto out; |
task->ccs_domain_info = ee->previous_domain; |
1268 |
/* Proceed to next domain if execution suceeded. */ |
/* |
1269 |
task->ccs_domain_info = ee->r.domain; |
* Make task->ccs_domain_info visible to GC before changing |
1270 |
/* Mark the current process as execute handler. */ |
* task->ccs_flags . |
1271 |
if (ee->handler) |
*/ |
1272 |
task->ccs_flags |= CCS_TASK_IS_EXECUTE_HANDLER; |
smp_mb(); |
1273 |
/* Mark the current process as normal process. */ |
} else { |
1274 |
else |
/* Mark the current process as execute handler. */ |
1275 |
task->ccs_flags &= ~CCS_TASK_IS_EXECUTE_HANDLER; |
if (ee->handler) |
1276 |
out: |
task->ccs_flags |= CCS_TASK_IS_EXECUTE_HANDLER; |
1277 |
ccs_free_execve_entry(ee); |
/* Mark the current process as normal process. */ |
1278 |
|
else |
1279 |
|
task->ccs_flags &= ~CCS_TASK_IS_EXECUTE_HANDLER; |
1280 |
|
} |
1281 |
|
/* Tell GC that I finished execve(). */ |
1282 |
|
task->ccs_flags &= ~CCS_TASK_IS_IN_EXECVE; |
1283 |
|
ccs_read_unlock(ee->reader_idx); |
1284 |
|
kfree(ee->handler_path); |
1285 |
|
kfree(ee->tmp); |
1286 |
|
kfree(ee->dump.data); |
1287 |
|
kfree(ee); |
1288 |
|
} |
1289 |
|
|
1290 |
|
/** |
1291 |
|
* ccs_may_transit - Check permission and do domain transition without execve(). |
1292 |
|
* |
1293 |
|
* @domainname: Domainname to transit to. |
1294 |
|
* @pathname: Pathname to check. |
1295 |
|
* |
1296 |
|
* Returns 0 on success, negative value otherwise. |
1297 |
|
* |
1298 |
|
* Caller holds ccs_read_lock(). |
1299 |
|
*/ |
1300 |
|
int ccs_may_transit(const char *domainname, const char *pathname) |
1301 |
|
{ |
1302 |
|
struct ccs_path_info name; |
1303 |
|
struct ccs_request_info r; |
1304 |
|
struct ccs_domain_info *domain; |
1305 |
|
int error; |
1306 |
|
bool domain_created = false; |
1307 |
|
name.name = pathname; |
1308 |
|
ccs_fill_path_info(&name); |
1309 |
|
/* Check allow_transit permission. */ |
1310 |
|
ccs_init_request_info(&r, CCS_MAC_FILE_TRANSIT); |
1311 |
|
error = ccs_path_permission(&r, CCS_TYPE_TRANSIT, &name); |
1312 |
|
if (error) |
1313 |
|
return error; |
1314 |
|
/* Check destination domain. */ |
1315 |
|
domain = ccs_find_domain(domainname); |
1316 |
|
if (!domain && r.mode != CCS_CONFIG_ENFORCING && |
1317 |
|
strlen(domainname) < CCS_EXEC_TMPSIZE - 10) { |
1318 |
|
domain = ccs_assign_domain(domainname, r.profile); |
1319 |
|
if (domain) |
1320 |
|
domain_created = true; |
1321 |
|
} |
1322 |
|
if (domain) { |
1323 |
|
error = 0; |
1324 |
|
current->ccs_domain_info = domain; |
1325 |
|
if (domain_created) |
1326 |
|
ccs_audit_domain_creation_log(); |
1327 |
|
} else { |
1328 |
|
error = -ENOENT; |
1329 |
|
} |
1330 |
|
return error; |
1331 |
|
} |
1332 |
|
|
1333 |
|
static int __ccs_search_binary_handler(struct linux_binprm *bprm, |
1334 |
|
struct pt_regs *regs) |
1335 |
|
{ |
1336 |
|
struct ccs_execve *ee; |
1337 |
|
int retval; |
1338 |
|
if (!ccs_policy_loaded) |
1339 |
|
ccsecurity_exports.load_policy(bprm->filename); |
1340 |
|
retval = ccs_start_execve(bprm, &ee); |
1341 |
|
if (!retval) |
1342 |
|
retval = search_binary_handler(bprm, regs); |
1343 |
|
ccs_finish_execve(retval, ee); |
1344 |
|
return retval; |
1345 |
|
} |
1346 |
|
|
1347 |
|
void __init ccs_domain_init(void) |
1348 |
|
{ |
1349 |
|
ccsecurity_ops.search_binary_handler = __ccs_search_binary_handler; |
1350 |
} |
} |