1 |
/* |
/* |
2 |
* security/ccsecurity/policy_io.c |
* security/ccsecurity/policy_io.c |
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.1+ 2009/12/20 |
* Version: 1.7.2+ 2010/06/04 |
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. |
94 |
= "file::umount", |
= "file::umount", |
95 |
[CCS_MAC_FILE_PIVOT_ROOT] |
[CCS_MAC_FILE_PIVOT_ROOT] |
96 |
= "file::pivot_root", |
= "file::pivot_root", |
97 |
|
[CCS_MAC_FILE_TRANSIT] |
98 |
|
= "file::transit", |
99 |
[CCS_MAC_ENVIRON] |
[CCS_MAC_ENVIRON] |
100 |
= "misc::env", |
= "misc::env", |
101 |
[CCS_MAC_NETWORK_UDP_BIND] |
[CCS_MAC_NETWORK_UDP_BIND] |
246 |
} |
} |
247 |
|
|
248 |
/** |
/** |
249 |
* ccs_find_or_assign_new_profile - Create a new profile. |
* ccs_assign_profile - Create a new profile. |
250 |
* |
* |
251 |
* @profile: Profile number to create. |
* @profile: Profile number to create. |
252 |
* |
* |
253 |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
254 |
*/ |
*/ |
255 |
static struct ccs_profile *ccs_find_or_assign_new_profile(const unsigned int |
static struct ccs_profile *ccs_assign_profile(const unsigned int profile) |
|
profile) |
|
256 |
{ |
{ |
257 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
258 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
261 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
262 |
if (ptr) |
if (ptr) |
263 |
return ptr; |
return ptr; |
264 |
entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
265 |
mutex_lock(&ccs_policy_lock); |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
266 |
|
goto out; |
267 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
268 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
269 |
ptr = entry; |
ptr = entry; |
280 |
entry = NULL; |
entry = NULL; |
281 |
} |
} |
282 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
283 |
|
out: |
284 |
kfree(entry); |
kfree(entry); |
285 |
return ptr; |
return ptr; |
286 |
} |
} |
288 |
/** |
/** |
289 |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
290 |
*/ |
*/ |
291 |
void ccs_check_profile(void) |
static void ccs_check_profile(void) |
292 |
{ |
{ |
293 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
294 |
|
const int idx = ccs_read_lock(); |
295 |
ccs_policy_loaded = true; |
ccs_policy_loaded = true; |
296 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
297 |
const u8 profile = domain->profile; |
const u8 profile = domain->profile; |
300 |
panic("Profile %u (used by '%s') not defined.\n", |
panic("Profile %u (used by '%s') not defined.\n", |
301 |
profile, domain->domainname->name); |
profile, domain->domainname->name); |
302 |
} |
} |
303 |
|
ccs_read_unlock(idx); |
304 |
if (ccs_profile_version != 20090903) |
if (ccs_profile_version != 20090903) |
305 |
panic("Profile version %u is not supported.\n", |
panic("Profile version %u is not supported.\n", |
306 |
ccs_profile_version); |
ccs_profile_version); |
307 |
|
printk(KERN_INFO "CCSecurity: 1.7.2+ 2010/06/04\n"); |
308 |
|
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
309 |
} |
} |
310 |
|
|
311 |
/** |
/** |
350 |
if (*cp != '-') |
if (*cp != '-') |
351 |
return -EINVAL; |
return -EINVAL; |
352 |
data = cp + 1; |
data = cp + 1; |
353 |
profile = ccs_find_or_assign_new_profile(i); |
profile = ccs_assign_profile(i); |
354 |
if (!profile) |
if (!profile) |
355 |
return -EINVAL; |
return -EINVAL; |
356 |
} |
} |
366 |
value = 0; |
value = 0; |
367 |
else |
else |
368 |
value = -1; |
value = -1; |
369 |
if (!strcmp(data, "PREFERENCE::audit")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_AUDIT)) { |
370 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
371 |
char *cp2; |
char *cp2; |
372 |
#endif |
#endif |
395 |
profile->preference.audit_path_info = false; |
profile->preference.audit_path_info = false; |
396 |
return 0; |
return 0; |
397 |
} |
} |
398 |
if (!strcmp(data, "PREFERENCE::enforcing")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_ENFORCING)) { |
399 |
char *cp2; |
char *cp2; |
400 |
if (use_default) { |
if (use_default) { |
401 |
profile->enforcing = &ccs_default_profile.preference; |
profile->enforcing = &ccs_default_profile.preference; |
410 |
&profile->preference.enforcing_penalty); |
&profile->preference.enforcing_penalty); |
411 |
return 0; |
return 0; |
412 |
} |
} |
413 |
if (!strcmp(data, "PREFERENCE::permissive")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_PERMISSIVE)) { |
414 |
if (use_default) { |
if (use_default) { |
415 |
profile->permissive = &ccs_default_profile.preference; |
profile->permissive = &ccs_default_profile.preference; |
416 |
return 0; |
return 0; |
420 |
profile->preference.permissive_verbose = value; |
profile->preference.permissive_verbose = value; |
421 |
return 0; |
return 0; |
422 |
} |
} |
423 |
if (!strcmp(data, "PREFERENCE::learning")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_LEARNING)) { |
424 |
char *cp2; |
char *cp2; |
425 |
if (use_default) { |
if (use_default) { |
426 |
profile->learning = &ccs_default_profile.preference; |
profile->learning = &ccs_default_profile.preference; |
505 |
return 0; |
return 0; |
506 |
} |
} |
507 |
|
|
508 |
|
static bool ccs_print_preference(struct ccs_io_buffer *head, const int idx) |
509 |
|
{ |
510 |
|
struct ccs_preference *pref = &ccs_default_profile.preference; |
511 |
|
const struct ccs_profile *profile = idx >= 0 ? |
512 |
|
ccs_profile_ptr[idx] : NULL; |
513 |
|
char buffer[16] = ""; |
514 |
|
if (profile) { |
515 |
|
buffer[sizeof(buffer) - 1] = '\0'; |
516 |
|
snprintf(buffer, sizeof(buffer) - 1, "%u-", idx); |
517 |
|
} |
518 |
|
if (profile) { |
519 |
|
pref = profile->audit; |
520 |
|
if (pref == &ccs_default_profile.preference) |
521 |
|
pref = NULL; |
522 |
|
} |
523 |
|
if (pref && !ccs_io_printf(head, "%s%s={ " |
524 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
525 |
|
"max_grant_log=%u max_reject_log=%u " |
526 |
|
#endif |
527 |
|
"task_info=%s path_info=%s }\n", buffer, |
528 |
|
CCS_KEYWORD_PREFERENCE_AUDIT, |
529 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
530 |
|
pref->audit_max_grant_log, |
531 |
|
pref->audit_max_reject_log, |
532 |
|
#endif |
533 |
|
ccs_yesno(pref->audit_task_info), |
534 |
|
ccs_yesno(pref->audit_path_info))) |
535 |
|
return false; |
536 |
|
if (profile) { |
537 |
|
pref = profile->learning; |
538 |
|
if (pref == &ccs_default_profile.preference) |
539 |
|
pref = NULL; |
540 |
|
} |
541 |
|
if (pref && !ccs_io_printf(head, "%s%s={ " |
542 |
|
"verbose=%s max_entry=%u exec.realpath=%s " |
543 |
|
"exec.argv0=%s symlink.target=%s }\n", |
544 |
|
buffer, CCS_KEYWORD_PREFERENCE_LEARNING, |
545 |
|
ccs_yesno(pref->learning_verbose), |
546 |
|
pref->learning_max_entry, |
547 |
|
ccs_yesno(pref->learning_exec_realpath), |
548 |
|
ccs_yesno(pref->learning_exec_argv0), |
549 |
|
ccs_yesno(pref->learning_symlink_target))) |
550 |
|
return false; |
551 |
|
if (profile) { |
552 |
|
pref = profile->permissive; |
553 |
|
if (pref == &ccs_default_profile.preference) |
554 |
|
pref = NULL; |
555 |
|
} |
556 |
|
if (pref && !ccs_io_printf(head, "%s%s={ verbose=%s }\n", buffer, |
557 |
|
CCS_KEYWORD_PREFERENCE_PERMISSIVE, |
558 |
|
ccs_yesno(pref->permissive_verbose))) |
559 |
|
return false; |
560 |
|
if (profile) { |
561 |
|
pref = profile->enforcing; |
562 |
|
if (pref == &ccs_default_profile.preference) |
563 |
|
pref = NULL; |
564 |
|
} |
565 |
|
return !pref || ccs_io_printf(head, "%s%s={ verbose=%s penalty=%u }\n", |
566 |
|
buffer, CCS_KEYWORD_PREFERENCE_ENFORCING, |
567 |
|
ccs_yesno(pref->enforcing_verbose), |
568 |
|
pref->enforcing_penalty); |
569 |
|
} |
570 |
|
|
571 |
/** |
/** |
572 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
573 |
* |
* |
581 |
if (head->read_bit) |
if (head->read_bit) |
582 |
goto body; |
goto body; |
583 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
584 |
ccs_io_printf(head, "PREFERENCE::audit={ " |
ccs_print_preference(head, -1); |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
"max_grant_log=%u max_reject_log=%u " |
|
|
#endif |
|
|
"task_info=%s path_info=%s }\n", |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
ccs_default_profile.preference.audit_max_grant_log, |
|
|
ccs_default_profile.preference.audit_max_reject_log, |
|
|
#endif |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
audit_task_info), |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
audit_path_info)); |
|
|
ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u " |
|
|
"exec.realpath=%s exec.argv0=%s symlink.target=%s }\n", |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_verbose), |
|
|
ccs_default_profile.preference.learning_max_entry, |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_exec_realpath), |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_exec_argv0), |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_symlink_target)); |
|
|
ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n", |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
permissive_verbose)); |
|
|
ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u " |
|
|
"}\n", |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
enforcing_verbose), |
|
|
ccs_default_profile.preference.enforcing_penalty); |
|
585 |
head->read_bit = 1; |
head->read_bit = 1; |
586 |
body: |
body: |
587 |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
602 |
goto out; |
goto out; |
603 |
config = profile->default_config; |
config = profile->default_config; |
604 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
605 |
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
606 |
"reject_log=%s }\n", index, |
"grant_log=%s reject_log=%s }\n", index, |
607 |
ccs_mode_4[config & 3], |
"CONFIG", "", ccs_mode_4[config & 3], |
608 |
ccs_yesno(config & |
ccs_yesno(config & |
609 |
CCS_CONFIG_WANT_GRANT_LOG), |
CCS_CONFIG_WANT_GRANT_LOG), |
610 |
ccs_yesno(config & |
ccs_yesno(config & |
611 |
CCS_CONFIG_WANT_REJECT_LOG))) |
CCS_CONFIG_WANT_REJECT_LOG))) |
612 |
goto out; |
goto out; |
613 |
#else |
#else |
614 |
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", index, |
615 |
ccs_mode_4[config & 3])) |
"CONFIG", "", ccs_mode_4[config & 3])) |
616 |
goto out; |
goto out; |
617 |
#endif |
#endif |
618 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
627 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
628 |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
629 |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
630 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
631 |
"grant_log=%s reject_log=%s }\n", |
"grant_log=%s reject_log=%s }\n", |
632 |
index, ccs_mac_keywords[i], |
index, "CONFIG::", |
633 |
|
ccs_mac_keywords[i], |
634 |
ccs_mode_4[config & 3], g, r)) |
ccs_mode_4[config & 3], g, r)) |
635 |
goto out; |
goto out; |
636 |
#else |
#else |
637 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", |
638 |
index, ccs_mac_keywords[i], |
index, "CONFIG::", |
639 |
|
ccs_mac_keywords[i], |
640 |
ccs_mode_4[config & 3])) |
ccs_mode_4[config & 3])) |
641 |
goto out; |
goto out; |
642 |
#endif |
#endif |
643 |
} |
} |
644 |
if (profile->audit != &ccs_default_profile.preference && |
if (!ccs_print_preference(head, index)) |
|
!ccs_io_printf(head, "%u-PREFERENCE::audit={ " |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
"max_grant_log=%u max_reject_log=%u " |
|
|
#endif |
|
|
"task_info=%s path_info=%s }\n", index, |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
profile->preference.audit_max_grant_log, |
|
|
profile->preference.audit_max_reject_log, |
|
|
#endif |
|
|
ccs_yesno(profile->preference. |
|
|
audit_task_info), |
|
|
ccs_yesno(profile->preference. |
|
|
audit_path_info))) |
|
|
goto out; |
|
|
if (profile->learning != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::learning={ " |
|
|
"verbose=%s max_entry=%u exec.realpath=%s " |
|
|
"exec.argv0=%s symlink.target=%s }\n", |
|
|
index, |
|
|
ccs_yesno(profile->preference. |
|
|
learning_verbose), |
|
|
profile->preference.learning_max_entry, |
|
|
ccs_yesno(profile->preference. |
|
|
learning_exec_realpath), |
|
|
ccs_yesno(profile->preference. |
|
|
learning_exec_argv0), |
|
|
ccs_yesno(profile->preference. |
|
|
learning_symlink_target))) |
|
|
goto out; |
|
|
if (profile->permissive != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::permissive={ " |
|
|
"verbose=%s }\n", index, |
|
|
ccs_yesno(profile->preference. |
|
|
permissive_verbose))) |
|
|
goto out; |
|
|
if (profile->enforcing != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::enforcing={ " |
|
|
"verbose=%s penalty=%u }\n", index, |
|
|
ccs_yesno(profile->preference. |
|
|
enforcing_verbose), |
|
|
profile->preference.enforcing_penalty)) |
|
645 |
goto out; |
goto out; |
646 |
continue; |
continue; |
647 |
out: |
out: |
652 |
head->read_eof = true; |
head->read_eof = true; |
653 |
} |
} |
654 |
|
|
655 |
/* The list for "struct ccs_policy_manager_entry". */ |
static bool ccs_same_manager_entry(const struct ccs_acl_head *a, |
656 |
LIST_HEAD(ccs_policy_manager_list); |
const struct ccs_acl_head *b) |
657 |
|
{ |
658 |
|
return container_of(a, struct ccs_manager, head)->manager |
659 |
|
== container_of(b, struct ccs_manager, head)->manager; |
660 |
|
} |
661 |
|
|
662 |
/** |
/** |
663 |
* ccs_update_manager_entry - Add a manager entry. |
* ccs_update_manager_entry - Add a manager entry. |
669 |
*/ |
*/ |
670 |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
671 |
{ |
{ |
672 |
struct ccs_policy_manager_entry *entry = NULL; |
struct ccs_manager e = { }; |
|
struct ccs_policy_manager_entry *ptr; |
|
|
struct ccs_policy_manager_entry e = { }; |
|
673 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
674 |
if (ccs_is_domain_def(manager)) { |
if (ccs_domain_def(manager)) { |
675 |
if (!ccs_is_correct_domain(manager)) |
if (!ccs_correct_domain(manager)) |
676 |
return -EINVAL; |
return -EINVAL; |
677 |
e.is_domain = true; |
e.is_domain = true; |
678 |
} else { |
} else { |
679 |
if (!ccs_is_correct_path(manager, 1, -1, -1)) |
if (!ccs_correct_path(manager)) |
680 |
return -EINVAL; |
return -EINVAL; |
681 |
} |
} |
682 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
683 |
if (!e.manager) |
if (!e.manager) |
684 |
return -ENOMEM; |
return error; |
685 |
if (!is_delete) |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
686 |
entry = kmalloc(sizeof(e), GFP_KERNEL); |
CCS_ID_MANAGER, ccs_same_manager_entry); |
|
mutex_lock(&ccs_policy_lock); |
|
|
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
|
|
if (ptr->manager != e.manager) |
|
|
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_policy_manager_list); |
|
|
entry = NULL; |
|
|
error = 0; |
|
|
} |
|
|
mutex_unlock(&ccs_policy_lock); |
|
687 |
ccs_put_name(e.manager); |
ccs_put_name(e.manager); |
|
kfree(entry); |
|
688 |
return error; |
return error; |
689 |
} |
} |
690 |
|
|
691 |
/** |
/** |
692 |
* ccs_write_manager_policy - Write manager policy. |
* ccs_write_manager - Write manager policy. |
693 |
* |
* |
694 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
695 |
* |
* |
696 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
697 |
*/ |
*/ |
698 |
static int ccs_write_manager_policy(struct ccs_io_buffer *head) |
static int ccs_write_manager(struct ccs_io_buffer *head) |
699 |
{ |
{ |
700 |
char *data = head->write_buf; |
char *data = head->write_buf; |
701 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
707 |
} |
} |
708 |
|
|
709 |
/** |
/** |
710 |
* ccs_read_manager_policy - Read manager policy. |
* ccs_read_manager - Read manager policy. |
711 |
* |
* |
712 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
713 |
* |
* |
714 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
715 |
*/ |
*/ |
716 |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager(struct ccs_io_buffer *head) |
717 |
{ |
{ |
718 |
struct list_head *pos; |
struct list_head *pos; |
719 |
if (head->read_eof) |
if (head->read_eof) |
720 |
return; |
return; |
721 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(pos, head->read_var2, |
722 |
struct ccs_policy_manager_entry *ptr; |
&ccs_policy_list[CCS_ID_MANAGER]) { |
723 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
struct ccs_manager *ptr |
724 |
if (ptr->is_deleted) |
= list_entry(pos, typeof(*ptr), head.list); |
725 |
|
if (ptr->head.is_deleted) |
726 |
continue; |
continue; |
727 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
728 |
return; |
return; |
731 |
} |
} |
732 |
|
|
733 |
/** |
/** |
734 |
* ccs_is_policy_manager - Check whether the current process is a policy manager. |
* ccs_manager - Check whether the current process is a policy manager. |
735 |
* |
* |
736 |
* Returns true if the current process is permitted to modify policy |
* Returns true if the current process is permitted to modify policy |
737 |
* via /proc/ccs/ interface. |
* via /proc/ccs/ interface. |
738 |
* |
* |
739 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
740 |
*/ |
*/ |
741 |
static bool ccs_is_policy_manager(void) |
static bool ccs_manager(void) |
742 |
{ |
{ |
743 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_manager *ptr; |
744 |
const char *exe; |
const char *exe; |
745 |
struct task_struct *task = current; |
struct task_struct *task = current; |
746 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
748 |
bool found = false; |
bool found = false; |
749 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
750 |
return true; |
return true; |
751 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_MANAGER) |
752 |
return true; |
return true; |
753 |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
754 |
return false; |
return false; |
|
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
|
|
if (!ptr->is_deleted && ptr->is_domain |
|
|
&& !ccs_pathcmp(domainname, ptr->manager)) { |
|
|
/* Set manager flag. */ |
|
|
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
|
|
return true; |
|
|
} |
|
|
} |
|
755 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
756 |
if (!exe) |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
757 |
return false; |
head.list) { |
758 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
if (ptr->head.is_deleted) |
759 |
if (!ptr->is_deleted && !ptr->is_domain |
continue; |
760 |
&& !strcmp(exe, ptr->manager->name)) { |
if (ptr->is_domain) { |
761 |
found = true; |
if (ccs_pathcmp(domainname, ptr->manager)) |
762 |
/* Set manager flag. */ |
continue; |
763 |
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
} else { |
764 |
break; |
if (!exe || strcmp(exe, ptr->manager->name)) |
765 |
|
continue; |
766 |
} |
} |
767 |
|
/* Set manager flag. */ |
768 |
|
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
769 |
|
found = true; |
770 |
|
break; |
771 |
} |
} |
772 |
if (!found) { /* Reduce error messages. */ |
if (!found) { /* Reduce error messages. */ |
773 |
static pid_t ccs_last_pid; |
static pid_t ccs_last_pid; |
793 |
static char *ccs_find_condition_part(char *data) |
static char *ccs_find_condition_part(char *data) |
794 |
{ |
{ |
795 |
char *cp = strstr(data, " if "); |
char *cp = strstr(data, " if "); |
796 |
if (cp) { |
if (!cp) |
|
while (1) { |
|
|
char *cp2 = strstr(cp + 3, " if "); |
|
|
if (!cp2) |
|
|
break; |
|
|
cp = cp2; |
|
|
} |
|
|
*cp++ = '\0'; |
|
|
} else { |
|
797 |
cp = strstr(data, " ; set "); |
cp = strstr(data, " ; set "); |
798 |
if (cp) |
if (cp) |
799 |
*cp++ = '\0'; |
*cp++ = '\0'; |
|
} |
|
800 |
return cp; |
return cp; |
801 |
} |
} |
802 |
|
|
803 |
/** |
/** |
804 |
* ccs_is_select_one - Parse select command. |
* ccs_select_one - Parse select command. |
805 |
* |
* |
806 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
807 |
* @data: String to parse. |
* @data: String to parse. |
810 |
* |
* |
811 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
812 |
*/ |
*/ |
813 |
static bool ccs_is_select_one(struct ccs_io_buffer *head, const char *data) |
static bool ccs_select_one(struct ccs_io_buffer *head, const char *data) |
814 |
{ |
{ |
815 |
unsigned int pid; |
unsigned int pid; |
816 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
825 |
ccs_tasklist_lock(); |
ccs_tasklist_lock(); |
826 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
827 |
if (global_pid) |
if (global_pid) |
828 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, |
829 |
|
&init_pid_ns); |
830 |
else |
else |
831 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
832 |
#else |
#else |
833 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
834 |
#endif |
#endif |
836 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
837 |
ccs_tasklist_unlock(); |
ccs_tasklist_unlock(); |
838 |
} else if (!strncmp(data, "domain=", 7)) { |
} else if (!strncmp(data, "domain=", 7)) { |
839 |
if (ccs_is_domain_def(data + 7)) |
if (ccs_domain_def(data + 7)) |
840 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
841 |
} else |
} else |
842 |
return false; |
return false; |
865 |
return true; |
return true; |
866 |
} |
} |
867 |
|
|
868 |
static int ccs_write_domain_policy2(char *data, struct ccs_domain_info *domain, |
static int ccs_write_domain2(char *data, struct ccs_domain_info *domain, |
869 |
struct ccs_condition *cond, |
const bool is_delete) |
870 |
const bool is_delete) |
{ |
871 |
{ |
static const struct { |
872 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CAPABILITY)) |
const char *keyword; |
873 |
return ccs_write_capability_policy(data, domain, cond, |
int (*write) (char *, struct ccs_domain_info *, |
874 |
is_delete); |
struct ccs_condition *, const bool); |
875 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_NETWORK)) |
} ccs_callback[5] = { |
876 |
return ccs_write_network_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_NETWORK, ccs_write_network }, |
877 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_SIGNAL)) |
{ CCS_KEYWORD_ALLOW_ENV, ccs_write_env }, |
878 |
return ccs_write_signal_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_CAPABILITY, ccs_write_capability }, |
879 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
{ CCS_KEYWORD_ALLOW_SIGNAL, ccs_write_signal }, |
880 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_MOUNT, ccs_write_mount } |
881 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
}; |
882 |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
int (*write) (char *, struct ccs_domain_info *, struct ccs_condition *, |
883 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
const bool) = ccs_write_file; |
884 |
|
int error; |
885 |
|
u8 i; |
886 |
|
struct ccs_condition *cond = NULL; |
887 |
|
char *cp = ccs_find_condition_part(data); |
888 |
|
if (cp) { |
889 |
|
cond = ccs_get_condition(cp); |
890 |
|
if (!cond) |
891 |
|
return -EINVAL; |
892 |
|
} |
893 |
|
for (i = 0; i < 5; i++) { |
894 |
|
if (!ccs_str_starts(&data, ccs_callback[i].keyword)) |
895 |
|
continue; |
896 |
|
write = ccs_callback[i].write; |
897 |
|
break; |
898 |
|
} |
899 |
|
error = write(data, domain, cond, is_delete); |
900 |
|
if (cond) |
901 |
|
ccs_put_condition(cond); |
902 |
|
return error; |
903 |
} |
} |
904 |
|
|
905 |
/** |
/** |
906 |
* ccs_write_domain_policy - Write domain policy. |
* ccs_write_domain - Write domain policy. |
907 |
* |
* |
908 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
909 |
* |
* |
910 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
911 |
*/ |
*/ |
912 |
static int ccs_write_domain_policy(struct ccs_io_buffer *head) |
static int ccs_write_domain(struct ccs_io_buffer *head) |
913 |
{ |
{ |
914 |
char *data = head->write_buf; |
char *data = head->write_buf; |
915 |
struct ccs_domain_info *domain = head->write_var1; |
struct ccs_domain_info *domain = head->write_var1; |
916 |
bool is_delete = false; |
bool is_delete = false; |
917 |
bool is_select = false; |
bool is_select = false; |
918 |
unsigned int profile; |
unsigned int profile; |
|
struct ccs_condition *cond = NULL; |
|
|
char *cp; |
|
|
int error; |
|
919 |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
920 |
is_delete = true; |
is_delete = true; |
921 |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
922 |
is_select = true; |
is_select = true; |
923 |
if (is_select && ccs_is_select_one(head, data)) |
if (is_select && ccs_select_one(head, data)) |
924 |
return 0; |
return 0; |
925 |
/* Don't allow updating policies by non manager programs. */ |
/* Don't allow updating policies by non manager programs. */ |
926 |
if (!ccs_is_policy_manager()) |
if (!ccs_manager()) |
927 |
return -EPERM; |
return -EPERM; |
928 |
if (ccs_is_domain_def(data)) { |
if (ccs_domain_def(data)) { |
929 |
domain = NULL; |
domain = NULL; |
930 |
if (is_delete) |
if (is_delete) |
931 |
ccs_delete_domain(data); |
ccs_delete_domain(data); |
932 |
else if (is_select) |
else if (is_select) |
933 |
domain = ccs_find_domain(data); |
domain = ccs_find_domain(data); |
934 |
else |
else |
935 |
domain = ccs_find_or_assign_new_domain(data, 0); |
domain = ccs_assign_domain(data, 0); |
936 |
head->write_var1 = domain; |
head->write_var1 = domain; |
937 |
return 0; |
return 0; |
938 |
} |
} |
945 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
946 |
return 0; |
return 0; |
947 |
} |
} |
948 |
|
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL)) { |
949 |
|
domain->ignore_global = !is_delete; |
950 |
|
return 0; |
951 |
|
} |
952 |
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ)) { |
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ)) { |
953 |
domain->ignore_global_allow_read = !is_delete; |
domain->ignore_global_allow_read = !is_delete; |
954 |
return 0; |
return 0; |
965 |
domain->domain_transition_failed = !is_delete; |
domain->domain_transition_failed = !is_delete; |
966 |
return 0; |
return 0; |
967 |
} |
} |
968 |
cp = ccs_find_condition_part(data); |
return ccs_write_domain2(data, domain, is_delete); |
|
if (cp) { |
|
|
cond = ccs_get_condition(cp); |
|
|
if (!cond) |
|
|
return -EINVAL; |
|
|
} |
|
|
error = ccs_write_domain_policy2(data, domain, cond, is_delete); |
|
|
if (cond) |
|
|
ccs_put_condition(cond); |
|
|
return error; |
|
969 |
} |
} |
970 |
|
|
971 |
/** |
/** |
1005 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
1006 |
} |
} |
1007 |
|
|
1008 |
|
static void ccs_print_number(char *buffer, int buffer_len, |
1009 |
|
const struct ccs_number_union *ptr) |
1010 |
|
{ |
1011 |
|
int i; |
1012 |
|
unsigned long min = ptr->values[0]; |
1013 |
|
const unsigned long max = ptr->values[1]; |
1014 |
|
u8 min_type = ptr->value_type[0]; |
1015 |
|
const u8 max_type = ptr->value_type[1]; |
1016 |
|
memset(buffer, 0, buffer_len); |
1017 |
|
buffer_len -= 2; |
1018 |
|
for (i = 0; i < 2; i++) { |
1019 |
|
int len; |
1020 |
|
switch (min_type) { |
1021 |
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
1022 |
|
snprintf(buffer, buffer_len, "0x%lX", min); |
1023 |
|
break; |
1024 |
|
case CCS_VALUE_TYPE_OCTAL: |
1025 |
|
snprintf(buffer, buffer_len, "0%lo", min); |
1026 |
|
break; |
1027 |
|
default: |
1028 |
|
snprintf(buffer, buffer_len, "%lu", min); |
1029 |
|
break; |
1030 |
|
} |
1031 |
|
if (min == max && min_type == max_type) |
1032 |
|
break; |
1033 |
|
len = strlen(buffer); |
1034 |
|
buffer[len++] = '-'; |
1035 |
|
buffer += len; |
1036 |
|
buffer_len -= len; |
1037 |
|
min_type = max_type; |
1038 |
|
min = max; |
1039 |
|
} |
1040 |
|
} |
1041 |
|
|
1042 |
/** |
/** |
1043 |
* ccs_print_number_union_common - Print a ccs_number_union. |
* ccs_print_number_union_common - Print a ccs_number_union. |
1044 |
* |
* |
1052 |
const struct ccs_number_union *ptr, |
const struct ccs_number_union *ptr, |
1053 |
const bool need_space) |
const bool need_space) |
1054 |
{ |
{ |
1055 |
unsigned long min; |
char buffer[128]; |
|
unsigned long max; |
|
|
u8 min_type; |
|
|
u8 max_type; |
|
1056 |
if (need_space && !ccs_io_printf(head, " ")) |
if (need_space && !ccs_io_printf(head, " ")) |
1057 |
return false; |
return false; |
1058 |
if (ptr->is_group) |
if (ptr->is_group) |
1059 |
return ccs_io_printf(head, "@%s", |
return ccs_io_printf(head, "@%s", |
1060 |
ptr->group->group_name->name); |
ptr->group->group_name->name); |
1061 |
min_type = ptr->min_type; |
ccs_print_number(buffer, sizeof(buffer), ptr); |
1062 |
max_type = ptr->max_type; |
return ccs_io_printf(head, "%s", buffer); |
|
min = ptr->values[0]; |
|
|
max = ptr->values[1]; |
|
|
switch (min_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
if (!ccs_io_printf(head, "0x%lX", min)) |
|
|
return false; |
|
|
break; |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
if (!ccs_io_printf(head, "0%lo", min)) |
|
|
return false; |
|
|
break; |
|
|
default: |
|
|
if (!ccs_io_printf(head, "%lu", min)) |
|
|
return false; |
|
|
break; |
|
|
} |
|
|
if (min == max && min_type == max_type) |
|
|
return true; |
|
|
switch (max_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
return ccs_io_printf(head, "-0x%lX", max); |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
return ccs_io_printf(head, "-0%lo", max); |
|
|
default: |
|
|
return ccs_io_printf(head, "-%lu", max); |
|
|
} |
|
1063 |
} |
} |
1064 |
|
|
1065 |
/** |
/** |
1070 |
* |
* |
1071 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1072 |
*/ |
*/ |
1073 |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
static bool ccs_print_number_union(struct ccs_io_buffer *head, |
1074 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1075 |
{ |
{ |
1076 |
return ccs_print_number_union_common(head, ptr, true); |
return ccs_print_number_union_common(head, ptr, true); |
1077 |
} |
} |
1104 |
const struct ccs_condition_element *condp; |
const struct ccs_condition_element *condp; |
1105 |
const struct ccs_number_union *numbers_p; |
const struct ccs_number_union *numbers_p; |
1106 |
const struct ccs_name_union *names_p; |
const struct ccs_name_union *names_p; |
1107 |
const struct ccs_argv_entry *argv; |
const struct ccs_argv *argv; |
1108 |
const struct ccs_envp_entry *envp; |
const struct ccs_envp *envp; |
1109 |
u16 condc; |
u16 condc; |
1110 |
u16 i; |
u16 i; |
1111 |
u16 j; |
u16 j; |
1117 |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
1118 |
names_p = (const struct ccs_name_union *) |
names_p = (const struct ccs_name_union *) |
1119 |
(numbers_p + cond->numbers_count); |
(numbers_p + cond->numbers_count); |
1120 |
argv = (const struct ccs_argv_entry *) (names_p + cond->names_count); |
argv = (const struct ccs_argv *) (names_p + cond->names_count); |
1121 |
envp = (const struct ccs_envp_entry *) (argv + cond->argc); |
envp = (const struct ccs_envp *) (argv + cond->argc); |
1122 |
memset(buffer, 0, sizeof(buffer)); |
memset(buffer, 0, sizeof(buffer)); |
1123 |
if (condc && !ccs_io_printf(head, "%s", " if")) |
if (condc && !ccs_io_printf(head, "%s", " if")) |
1124 |
goto out; |
goto out; |
1194 |
cond->post_state[j])) |
cond->post_state[j])) |
1195 |
goto out; |
goto out; |
1196 |
} |
} |
1197 |
|
if (i & (1 << 4)) { |
1198 |
|
if (!ccs_io_printf(head, " audit=%s", |
1199 |
|
ccs_yesno(cond->post_state[4]))) |
1200 |
|
goto out; |
1201 |
|
} |
1202 |
no_condition: |
no_condition: |
1203 |
if (ccs_io_printf(head, "\n")) |
if (ccs_io_printf(head, "\n")) |
1204 |
return true; |
return true; |
1225 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1226 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1227 |
continue; |
continue; |
1228 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE) |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
1229 |
|
&& bit != CCS_TYPE_TRANSIT) |
1230 |
continue; |
continue; |
1231 |
/* Print "read/write" instead of "read" and "write". */ |
/* Print "read/write" instead of "read" and "write". */ |
1232 |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
1397 |
} |
} |
1398 |
|
|
1399 |
/** |
/** |
|
* ccs_print_ipv4_entry - Print IPv4 address of a network ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_ip_network_acl". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_ipv4_entry(struct ccs_io_buffer *head, |
|
|
struct ccs_ip_network_acl *ptr) |
|
|
{ |
|
|
const u32 min_address = ptr->address.ipv4.min; |
|
|
const u32 max_address = ptr->address.ipv4.max; |
|
|
if (!ccs_io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) |
|
|
return false; |
|
|
if (min_address != max_address |
|
|
&& !ccs_io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) |
|
|
return false; |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_ipv6_entry - Print IPv6 address of a network ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_ip_network_acl". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_ipv6_entry(struct ccs_io_buffer *head, |
|
|
struct ccs_ip_network_acl *ptr) |
|
|
{ |
|
|
char buf[64]; |
|
|
const struct in6_addr *min_address = ptr->address.ipv6.min; |
|
|
const struct in6_addr *max_address = ptr->address.ipv6.max; |
|
|
ccs_print_ipv6(buf, sizeof(buf), min_address); |
|
|
if (!ccs_io_printf(head, "%s", buf)) |
|
|
return false; |
|
|
if (min_address != max_address) { |
|
|
ccs_print_ipv6(buf, sizeof(buf), max_address); |
|
|
if (!ccs_io_printf(head, "-%s", buf)) |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
1400 |
* ccs_print_network_acl - Print a network ACL entry. |
* ccs_print_network_acl - Print a network ACL entry. |
1401 |
* |
* |
1402 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1411 |
{ |
{ |
1412 |
int pos; |
int pos; |
1413 |
u8 bit; |
u8 bit; |
1414 |
const u16 perm = ptr->perm; |
const u8 perm = ptr->perm; |
1415 |
|
char buf[128]; |
1416 |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
1417 |
|
const char *w[2] = { "", "" }; |
1418 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1419 |
continue; |
continue; |
1420 |
pos = head->read_avail; |
pos = head->read_avail; |
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
|
|
ccs_net2keyword(bit))) |
|
|
goto out; |
|
1421 |
switch (ptr->address_type) { |
switch (ptr->address_type) { |
1422 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
1423 |
if (!ccs_io_printf(head, "@%s", ptr->address.group-> |
w[0] = "@"; |
1424 |
group_name->name)) |
w[1] = ptr->address.group->group_name->name; |
|
goto out; |
|
1425 |
break; |
break; |
1426 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
case CCS_IP_ADDRESS_TYPE_IPv4: |
1427 |
if (!ccs_print_ipv4_entry(head, ptr)) |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
1428 |
goto out; |
ptr->address.ipv4.max); |
1429 |
|
w[0] = buf; |
1430 |
break; |
break; |
1431 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_IPv6: |
1432 |
if (!ccs_print_ipv6_entry(head, ptr)) |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
1433 |
goto out; |
ptr->address.ipv6.max); |
1434 |
|
w[0] = buf; |
1435 |
break; |
break; |
1436 |
} |
} |
1437 |
if (!ccs_print_number_union(head, &ptr->port) || |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s %s%s", |
1438 |
|
ccs_net2keyword(bit), w[0], w[1]) || |
1439 |
|
!ccs_print_number_union(head, &ptr->port) || |
1440 |
!ccs_print_condition(head, cond)) |
!ccs_print_condition(head, cond)) |
1441 |
goto out; |
goto out; |
1442 |
} |
} |
1472 |
} |
} |
1473 |
|
|
1474 |
/** |
/** |
1475 |
* ccs_print_execute_handler_record - Print an execute handler ACL entry. |
* ccs_print_execute_handler - Print an execute handler ACL entry. |
1476 |
* |
* |
1477 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1478 |
* @keyword: Name of the keyword. |
* @keyword: Name of the keyword. |
1479 |
* @ptr: Pointer to "struct ccs_execute_handler_record". |
* @ptr: Pointer to "struct ccs_execute_handler". |
1480 |
* |
* |
1481 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1482 |
*/ |
*/ |
1483 |
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
static bool ccs_print_execute_handler(struct ccs_io_buffer *head, |
1484 |
const char *keyword, |
const char *keyword, |
1485 |
struct ccs_execute_handler_record * |
struct ccs_execute_handler *ptr) |
|
ptr) |
|
1486 |
{ |
{ |
1487 |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
1488 |
} |
} |
1533 |
= container_of(ptr, struct ccs_path_acl, head); |
= container_of(ptr, struct ccs_path_acl, head); |
1534 |
return ccs_print_path_acl(head, acl, cond); |
return ccs_print_path_acl(head, acl, cond); |
1535 |
} |
} |
1536 |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER || |
1537 |
struct ccs_execute_handler_record *acl |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
1538 |
= container_of(ptr, struct ccs_execute_handler_record, |
struct ccs_execute_handler *acl |
1539 |
head); |
= container_of(ptr, struct ccs_execute_handler, head); |
1540 |
const char *keyword = CCS_KEYWORD_EXECUTE_HANDLER; |
const char *keyword = acl_type == CCS_TYPE_EXECUTE_HANDLER ? |
1541 |
return ccs_print_execute_handler_record(head, keyword, acl); |
CCS_KEYWORD_EXECUTE_HANDLER : |
1542 |
} |
CCS_KEYWORD_DENIED_EXECUTE_HANDLER; |
1543 |
if (acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
return ccs_print_execute_handler(head, keyword, acl); |
|
struct ccs_execute_handler_record *acl |
|
|
= container_of(ptr, struct ccs_execute_handler_record, |
|
|
head); |
|
|
const char *keyword = CCS_KEYWORD_DENIED_EXECUTE_HANDLER; |
|
|
return ccs_print_execute_handler_record(head, keyword, acl); |
|
1544 |
} |
} |
1545 |
if (head->read_execute_only) |
if (head->read_execute_only) |
1546 |
return true; |
return true; |
1589 |
} |
} |
1590 |
|
|
1591 |
/** |
/** |
1592 |
* ccs_read_domain_policy - Read domain policy. |
* ccs_read_domain2 - Read domain policy. |
1593 |
|
* |
1594 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1595 |
|
* @domain: Pointer to "struct ccs_domain_info". |
1596 |
|
* |
1597 |
|
* Caller holds ccs_read_lock(). |
1598 |
|
* |
1599 |
|
* Returns true on success, false otherwise. |
1600 |
|
*/ |
1601 |
|
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
1602 |
|
struct ccs_domain_info *domain) |
1603 |
|
{ |
1604 |
|
struct list_head *pos; |
1605 |
|
/* Print ACL entries in the domain. */ |
1606 |
|
list_for_each_cookie(pos, head->read_var2, &domain->acl_info_list) { |
1607 |
|
struct ccs_acl_info *ptr |
1608 |
|
= list_entry(pos, struct ccs_acl_info, list); |
1609 |
|
if (!ccs_print_entry(head, ptr)) |
1610 |
|
return false; |
1611 |
|
} |
1612 |
|
return true; |
1613 |
|
} |
1614 |
|
|
1615 |
|
/** |
1616 |
|
* ccs_read_domain - Read domain policy. |
1617 |
* |
* |
1618 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1619 |
* |
* |
1620 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1621 |
*/ |
*/ |
1622 |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain(struct ccs_io_buffer *head) |
1623 |
{ |
{ |
1624 |
struct list_head *dpos; |
struct list_head *pos; |
|
struct list_head *apos; |
|
1625 |
if (head->read_eof) |
if (head->read_eof) |
1626 |
return; |
return; |
1627 |
if (head->read_step == 0) |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
1628 |
head->read_step = 1; |
struct ccs_domain_info *domain = |
1629 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
list_entry(pos, struct ccs_domain_info, list); |
1630 |
struct ccs_domain_info *domain; |
const char *w[5] = { "", "", "", "", "" }; |
1631 |
const char *quota_exceeded = ""; |
switch (head->read_step) { |
1632 |
const char *transition_failed = ""; |
case 0: |
1633 |
const char *ignore_global_allow_read = ""; |
if (domain->is_deleted && !head->read_single_domain) |
1634 |
const char *ignore_global_allow_env = ""; |
continue; |
1635 |
domain = list_entry(dpos, struct ccs_domain_info, list); |
/* Print domainname and flags. */ |
1636 |
if (head->read_step != 1) |
if (domain->quota_warned) |
1637 |
goto acl_loop; |
w[0] = CCS_KEYWORD_QUOTA_EXCEEDED "\n"; |
1638 |
if (domain->is_deleted && !head->read_single_domain) |
if (domain->domain_transition_failed) |
1639 |
continue; |
w[1] = CCS_KEYWORD_TRANSITION_FAILED "\n"; |
1640 |
/* Print domainname and flags. */ |
if (domain->ignore_global) |
1641 |
if (domain->quota_warned) |
w[2] = CCS_KEYWORD_IGNORE_GLOBAL "\n"; |
1642 |
quota_exceeded = CCS_KEYWORD_QUOTA_EXCEEDED "\n"; |
if (domain->ignore_global_allow_read) |
1643 |
if (domain->domain_transition_failed) |
w[3] = CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ |
1644 |
transition_failed = CCS_KEYWORD_TRANSITION_FAILED "\n"; |
"\n"; |
1645 |
if (domain->ignore_global_allow_read) |
if (domain->ignore_global_allow_env) |
1646 |
ignore_global_allow_read |
w[4] = CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV |
1647 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
"\n"; |
1648 |
if (domain->ignore_global_allow_env) |
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE |
1649 |
ignore_global_allow_env |
"%u\n%s%s%s%s%s\n", |
1650 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV "\n"; |
domain->domainname->name, |
1651 |
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE "%u\n" |
domain->profile, w[0], w[1], w[2], |
1652 |
"%s%s%s%s\n", domain->domainname->name, |
w[3], w[4])) |
1653 |
domain->profile, quota_exceeded, |
return; |
1654 |
transition_failed, |
head->read_step++; |
1655 |
ignore_global_allow_read, |
/* fall through */ |
1656 |
ignore_global_allow_env)) |
case 1: |
1657 |
return; |
if (!ccs_read_domain2(head, domain)) |
1658 |
head->read_step = 2; |
return; |
1659 |
acl_loop: |
head->read_step++; |
1660 |
if (head->read_step == 3) |
/* fall through */ |
1661 |
goto tail_mark; |
case 2: |
1662 |
/* Print ACL entries in the domain. */ |
if (!ccs_io_printf(head, "\n")) |
|
list_for_each_cookie(apos, head->read_var2, |
|
|
&domain->acl_info_list) { |
|
|
struct ccs_acl_info *ptr |
|
|
= list_entry(apos, struct ccs_acl_info, list); |
|
|
if (!ccs_print_entry(head, ptr)) |
|
1663 |
return; |
return; |
1664 |
|
head->read_step = 0; |
1665 |
|
if (head->read_single_domain) |
1666 |
|
goto out; |
1667 |
} |
} |
|
head->read_step = 3; |
|
|
tail_mark: |
|
|
if (!ccs_io_printf(head, "\n")) |
|
|
return; |
|
|
head->read_step = 1; |
|
|
if (head->read_single_domain) |
|
|
break; |
|
1668 |
} |
} |
1669 |
|
out: |
1670 |
head->read_eof = true; |
head->read_eof = true; |
1671 |
} |
} |
1672 |
|
|
1782 |
ccs_tasklist_lock(); |
ccs_tasklist_lock(); |
1783 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1784 |
if (global_pid) |
if (global_pid) |
1785 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, &init_pid_ns); |
1786 |
else |
else |
1787 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
1788 |
#else |
#else |
1789 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1790 |
#endif |
#endif |
1802 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1803 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1804 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1805 |
CCS_TASK_IS_POLICY_MANAGER), |
CCS_TASK_IS_MANAGER), |
1806 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1807 |
CCS_TASK_IS_EXECUTE_HANDLER), |
CCS_TASK_IS_EXECUTE_HANDLER), |
1808 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1811 |
} |
} |
1812 |
|
|
1813 |
/** |
/** |
1814 |
* ccs_write_exception_policy - Write exception policy. |
* ccs_write_exception - Write exception policy. |
1815 |
* |
* |
1816 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1817 |
* |
* |
1818 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1819 |
*/ |
*/ |
1820 |
static int ccs_write_exception_policy(struct ccs_io_buffer *head) |
static int ccs_write_exception(struct ccs_io_buffer *head) |
1821 |
{ |
{ |
1822 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1823 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
const bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
1824 |
if (ccs_str_starts(&data, CCS_KEYWORD_KEEP_DOMAIN)) |
u8 i; |
1825 |
return ccs_write_domain_keeper_policy(data, false, is_delete); |
static const struct { |
1826 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_KEEP_DOMAIN)) |
const char *keyword; |
1827 |
return ccs_write_domain_keeper_policy(data, true, is_delete); |
int (*write) (char *, const bool, const u8); |
1828 |
if (ccs_str_starts(&data, CCS_KEYWORD_INITIALIZE_DOMAIN)) |
} ccs_callback[8] = { |
1829 |
return ccs_write_domain_initializer_policy(data, false, |
{ CCS_KEYWORD_NO_KEEP_DOMAIN, ccs_write_domain_keeper }, |
1830 |
is_delete); |
{ CCS_KEYWORD_NO_INITIALIZE_DOMAIN, |
1831 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_INITIALIZE_DOMAIN)) |
ccs_write_domain_initializer }, |
1832 |
return ccs_write_domain_initializer_policy(data, true, |
{ CCS_KEYWORD_KEEP_DOMAIN, ccs_write_domain_keeper }, |
1833 |
is_delete); |
{ CCS_KEYWORD_INITIALIZE_DOMAIN, |
1834 |
if (ccs_str_starts(&data, CCS_KEYWORD_AGGREGATOR)) |
ccs_write_domain_initializer }, |
1835 |
return ccs_write_aggregator_policy(data, is_delete); |
{ CCS_KEYWORD_AGGREGATOR, ccs_write_aggregator }, |
1836 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_READ)) |
{ CCS_KEYWORD_FILE_PATTERN, ccs_write_pattern }, |
1837 |
return ccs_write_globally_readable_policy(data, is_delete); |
{ CCS_KEYWORD_DENY_REWRITE, ccs_write_no_rewrite }, |
1838 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
{ CCS_KEYWORD_DENY_AUTOBIND, ccs_write_reserved_port } |
1839 |
return ccs_write_globally_usable_env_policy(data, is_delete); |
}; |
1840 |
if (ccs_str_starts(&data, CCS_KEYWORD_FILE_PATTERN)) |
static const char *ccs_name[CCS_MAX_GROUP] = { |
1841 |
return ccs_write_pattern_policy(data, is_delete); |
[CCS_PATH_GROUP] = CCS_KEYWORD_PATH_GROUP, |
1842 |
if (ccs_str_starts(&data, CCS_KEYWORD_PATH_GROUP)) |
[CCS_NUMBER_GROUP] = CCS_KEYWORD_NUMBER_GROUP, |
1843 |
return ccs_write_path_group_policy(data, is_delete); |
[CCS_ADDRESS_GROUP] = CCS_KEYWORD_ADDRESS_GROUP |
1844 |
if (ccs_str_starts(&data, CCS_KEYWORD_NUMBER_GROUP)) |
}; |
1845 |
return ccs_write_number_group_policy(data, is_delete); |
for (i = 0; i < 8; i++) { |
1846 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_REWRITE)) |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
1847 |
return ccs_write_no_rewrite_policy(data, is_delete); |
return ccs_callback[i].write(data, is_delete, i < 2); |
1848 |
if (ccs_str_starts(&data, CCS_KEYWORD_ADDRESS_GROUP)) |
} |
1849 |
return ccs_write_address_group_policy(data, is_delete); |
for (i = 0; i < CCS_MAX_GROUP; i++) { |
1850 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_AUTOBIND)) |
if (ccs_str_starts(&data, ccs_name[i])) |
1851 |
return ccs_write_reserved_port_policy(data, is_delete); |
return ccs_write_group(data, is_delete, i); |
1852 |
return -EINVAL; |
} |
1853 |
|
return ccs_write_domain2(data, &ccs_global_domain, is_delete); |
1854 |
} |
} |
1855 |
|
|
1856 |
/** |
/** |
1857 |
* ccs_read_exception_policy - Read exception policy. |
* ccs_read_group - Read "struct ccs_path_group"/"struct ccs_number_group"/"struct ccs_address_group" list. |
1858 |
* |
* |
1859 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1860 |
|
* @idx: Index number. |
1861 |
|
* |
1862 |
|
* Returns true on success, false otherwise. |
1863 |
* |
* |
1864 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1865 |
*/ |
*/ |
1866 |
static void ccs_read_exception_policy(struct ccs_io_buffer *head) |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
1867 |
{ |
{ |
1868 |
if (head->read_eof) |
struct list_head *gpos; |
1869 |
return; |
struct list_head *mpos; |
1870 |
switch (head->read_step) { |
const char *w[3] = { "", "", "" }; |
1871 |
case 0: |
if (idx == CCS_PATH_GROUP) |
1872 |
head->read_var2 = NULL; |
w[0] = CCS_KEYWORD_PATH_GROUP; |
1873 |
head->read_step = 1; |
else if (idx == CCS_NUMBER_GROUP) |
1874 |
case 1: |
w[0] = CCS_KEYWORD_NUMBER_GROUP; |
1875 |
if (!ccs_read_domain_keeper_policy(head)) |
else if (idx == CCS_ADDRESS_GROUP) |
1876 |
break; |
w[0] = CCS_KEYWORD_ADDRESS_GROUP; |
1877 |
head->read_var2 = NULL; |
list_for_each_cookie(gpos, head->read_var1, &ccs_group_list[idx]) { |
1878 |
head->read_step = 2; |
struct ccs_group *group = |
1879 |
case 2: |
list_entry(gpos, struct ccs_group, head.list); |
1880 |
if (!ccs_read_globally_readable_policy(head)) |
w[1] = group->group_name->name; |
1881 |
break; |
list_for_each_cookie(mpos, head->read_var2, |
1882 |
head->read_var2 = NULL; |
&group->member_list) { |
1883 |
head->read_step = 3; |
char buffer[128]; |
1884 |
case 3: |
struct ccs_acl_head *ptr = |
1885 |
if (!ccs_read_globally_usable_env_policy(head)) |
list_entry(mpos, struct ccs_acl_head, list); |
1886 |
break; |
if (ptr->is_deleted) |
1887 |
head->read_var2 = NULL; |
continue; |
1888 |
head->read_step = 4; |
if (idx == CCS_PATH_GROUP) { |
1889 |
case 4: |
w[2] = container_of(ptr, struct ccs_path_group, |
1890 |
if (!ccs_read_domain_initializer_policy(head)) |
head)->member_name->name; |
1891 |
break; |
} else if (idx == CCS_NUMBER_GROUP) { |
1892 |
head->read_var2 = NULL; |
w[2] = buffer; |
1893 |
head->read_step = 6; |
ccs_print_number(buffer, sizeof(buffer), |
1894 |
case 6: |
&container_of |
1895 |
if (!ccs_read_aggregator_policy(head)) |
(ptr, struct ccs_number_group, |
1896 |
break; |
head)->number); |
1897 |
head->read_var2 = NULL; |
} else if (idx == CCS_ADDRESS_GROUP) { |
1898 |
head->read_step = 7; |
struct ccs_address_group *member = |
1899 |
case 7: |
container_of(ptr, typeof(*member), |
1900 |
if (!ccs_read_file_pattern(head)) |
head); |
1901 |
|
w[2] = buffer; |
1902 |
|
if (member->is_ipv6) |
1903 |
|
ccs_print_ipv6(buffer, sizeof(buffer), |
1904 |
|
member->min.ipv6, |
1905 |
|
member->max.ipv6); |
1906 |
|
else |
1907 |
|
ccs_print_ipv4(buffer, sizeof(buffer), |
1908 |
|
member->min.ipv4, |
1909 |
|
member->max.ipv4); |
1910 |
|
} |
1911 |
|
if (!ccs_io_printf(head, "%s%s %s\n", w[0], w[1], |
1912 |
|
w[2])) |
1913 |
|
return false; |
1914 |
|
} |
1915 |
|
} |
1916 |
|
return true; |
1917 |
|
} |
1918 |
|
|
1919 |
|
/** |
1920 |
|
* ccs_read_policy - Read "struct ccs_..._entry" list. |
1921 |
|
* |
1922 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1923 |
|
* @idx: Index number. |
1924 |
|
* |
1925 |
|
* Returns true on success, false otherwise. |
1926 |
|
* |
1927 |
|
* Caller holds ccs_read_lock(). |
1928 |
|
*/ |
1929 |
|
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
1930 |
|
{ |
1931 |
|
struct list_head *pos; |
1932 |
|
list_for_each_cookie(pos, head->read_var2, &ccs_policy_list[idx]) { |
1933 |
|
const char *w[4] = { "", "", "", "" }; |
1934 |
|
char buffer[16]; |
1935 |
|
struct ccs_acl_head *acl = container_of(pos, typeof(*acl), |
1936 |
|
list); |
1937 |
|
if (acl->is_deleted) |
1938 |
|
continue; |
1939 |
|
switch (idx) { |
1940 |
|
case CCS_ID_DOMAIN_KEEPER: |
1941 |
|
{ |
1942 |
|
struct ccs_domain_keeper *ptr = |
1943 |
|
container_of(acl, typeof(*ptr), head); |
1944 |
|
w[0] = ptr->is_not ? |
1945 |
|
CCS_KEYWORD_NO_KEEP_DOMAIN : |
1946 |
|
CCS_KEYWORD_KEEP_DOMAIN; |
1947 |
|
if (ptr->program) { |
1948 |
|
w[1] = ptr->program->name; |
1949 |
|
w[2] = " from "; |
1950 |
|
} |
1951 |
|
w[3] = ptr->domainname->name; |
1952 |
|
} |
1953 |
break; |
break; |
1954 |
head->read_var2 = NULL; |
case CCS_ID_DOMAIN_INITIALIZER: |
1955 |
head->read_step = 8; |
{ |
1956 |
case 8: |
struct ccs_domain_initializer *ptr = |
1957 |
if (!ccs_read_no_rewrite_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1958 |
|
w[0] = ptr->is_not ? |
1959 |
|
CCS_KEYWORD_NO_INITIALIZE_DOMAIN : |
1960 |
|
CCS_KEYWORD_INITIALIZE_DOMAIN; |
1961 |
|
w[1] = ptr->program->name; |
1962 |
|
if (ptr->domainname) { |
1963 |
|
w[2] = " from "; |
1964 |
|
w[3] = ptr->domainname->name; |
1965 |
|
} |
1966 |
|
} |
1967 |
break; |
break; |
1968 |
head->read_var2 = NULL; |
case CCS_ID_AGGREGATOR: |
1969 |
head->read_step = 9; |
{ |
1970 |
case 9: |
struct ccs_aggregator *ptr = |
1971 |
if (!ccs_read_path_group_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1972 |
|
w[0] = CCS_KEYWORD_AGGREGATOR; |
1973 |
|
w[1] = ptr->original_name->name; |
1974 |
|
w[2] = " "; |
1975 |
|
w[3] = ptr->aggregated_name->name; |
1976 |
|
} |
1977 |
break; |
break; |
1978 |
head->read_var1 = NULL; |
case CCS_ID_PATTERN: |
1979 |
head->read_var2 = NULL; |
{ |
1980 |
head->read_step = 10; |
struct ccs_pattern *ptr = |
1981 |
case 10: |
container_of(acl, typeof(*ptr), head); |
1982 |
if (!ccs_read_number_group_policy(head)) |
w[0] = CCS_KEYWORD_FILE_PATTERN; |
1983 |
|
w[1] = ptr->pattern->name; |
1984 |
|
} |
1985 |
break; |
break; |
1986 |
head->read_var1 = NULL; |
case CCS_ID_NO_REWRITE: |
1987 |
head->read_var2 = NULL; |
{ |
1988 |
head->read_step = 11; |
struct ccs_no_rewrite *ptr = |
1989 |
case 11: |
container_of(acl, typeof(*ptr), head); |
1990 |
if (!ccs_read_address_group_policy(head)) |
w[0] = CCS_KEYWORD_DENY_REWRITE; |
1991 |
|
w[1] = ptr->pattern->name; |
1992 |
|
} |
1993 |
break; |
break; |
1994 |
head->read_var2 = NULL; |
case CCS_ID_RESERVEDPORT: |
1995 |
head->read_step = 12; |
{ |
1996 |
case 12: |
struct ccs_reserved *ptr = |
1997 |
if (!ccs_read_reserved_port_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1998 |
|
const u16 min_port = ptr->min_port; |
1999 |
|
const u16 max_port = ptr->max_port; |
2000 |
|
w[0] = CCS_KEYWORD_DENY_AUTOBIND; |
2001 |
|
snprintf(buffer, sizeof(buffer) - 1, "%u%c%u", |
2002 |
|
min_port, min_port != max_port ? |
2003 |
|
'-' : '\0', max_port); |
2004 |
|
buffer[sizeof(buffer) - 1] = '\0'; |
2005 |
|
w[1] = buffer; |
2006 |
|
} |
2007 |
break; |
break; |
2008 |
head->read_eof = true; |
default: |
2009 |
|
continue; |
2010 |
|
} |
2011 |
|
if (!ccs_io_printf(head, "%s%s%s%s\n", w[0], w[1], w[2], w[3])) |
2012 |
|
return false; |
2013 |
} |
} |
2014 |
|
return true; |
2015 |
|
} |
2016 |
|
|
2017 |
|
static void ccs_read_global_domain(struct ccs_io_buffer *head) |
2018 |
|
{ |
2019 |
|
if (!head->read_eof) |
2020 |
|
head->read_eof = ccs_read_domain2(head, &ccs_global_domain); |
2021 |
|
} |
2022 |
|
|
2023 |
|
/** |
2024 |
|
* ccs_read_exception - Read exception policy. |
2025 |
|
* |
2026 |
|
* @head: Pointer to "struct ccs_io_buffer". |
2027 |
|
* |
2028 |
|
* Caller holds ccs_read_lock(). |
2029 |
|
*/ |
2030 |
|
static void ccs_read_exception(struct ccs_io_buffer *head) |
2031 |
|
{ |
2032 |
|
if (head->read_eof) |
2033 |
|
return; |
2034 |
|
while (head->read_step < CCS_MAX_POLICY && |
2035 |
|
ccs_read_policy(head, head->read_step)) |
2036 |
|
head->read_step++; |
2037 |
|
if (head->read_step < CCS_MAX_POLICY) |
2038 |
|
return; |
2039 |
|
while (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
2040 |
|
ccs_read_group(head, head->read_step - CCS_MAX_POLICY)) |
2041 |
|
head->read_step++; |
2042 |
|
if (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
2043 |
|
return; |
2044 |
|
head->read = ccs_read_global_domain; |
2045 |
} |
} |
2046 |
|
|
2047 |
/** |
/** |
2048 |
* ccs_get_argv0 - Get argv[0]. |
* ccs_get_argv0 - Get argv[0]. |
2049 |
* |
* |
2050 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
2051 |
* |
* |
2052 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
2053 |
*/ |
*/ |
2054 |
static bool ccs_get_argv0(struct ccs_execve_entry *ee) |
static bool ccs_get_argv0(struct ccs_execve *ee) |
2055 |
{ |
{ |
2056 |
struct linux_binprm *bprm = ee->bprm; |
struct linux_binprm *bprm = ee->bprm; |
2057 |
char *arg_ptr = ee->tmp; |
char *arg_ptr = ee->tmp; |
2097 |
return false; |
return false; |
2098 |
} |
} |
2099 |
|
|
|
/** |
|
|
* ccs_get_execute_condition - Get condition part for execute requests. |
|
|
* |
|
|
* @ee: Pointer to "struct ccs_execve_entry". |
|
|
* |
|
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
|
|
*ee) |
|
|
{ |
|
|
struct ccs_condition *cond; |
|
|
char *buf; |
|
|
int len = 256; |
|
|
char *realpath = NULL; |
|
|
char *argv0 = NULL; |
|
|
const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile); |
|
|
if (profile->learning->learning_exec_realpath) { |
|
|
struct file *file = ee->bprm->file; |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
|
|
struct path path = { file->f_vfsmnt, file->f_dentry }; |
|
|
realpath = ccs_realpath_from_path(&path); |
|
|
#else |
|
|
realpath = ccs_realpath_from_path(&file->f_path); |
|
|
#endif |
|
|
if (realpath) |
|
|
len += strlen(realpath) + 17; |
|
|
} |
|
|
if (profile->learning->learning_exec_argv0) { |
|
|
if (ccs_get_argv0(ee)) { |
|
|
argv0 = ee->tmp; |
|
|
len += strlen(argv0) + 16; |
|
|
} |
|
|
} |
|
|
buf = kmalloc(len, GFP_KERNEL); |
|
|
if (!buf) { |
|
|
kfree(realpath); |
|
|
return NULL; |
|
|
} |
|
|
snprintf(buf, len - 1, "if"); |
|
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, |
|
|
" task.type=execute_handler"); |
|
|
} |
|
|
if (realpath) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, " exec.realpath=\"%s\"", |
|
|
realpath); |
|
|
kfree(realpath); |
|
|
} |
|
|
if (argv0) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, " exec.argv[0]=\"%s\"", |
|
|
argv0); |
|
|
} |
|
|
cond = ccs_get_condition(buf); |
|
|
kfree(buf); |
|
|
return cond; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_get_symlink_condition - Get condition part for symlink requests. |
|
|
* |
|
|
* @r: Pointer to "struct ccs_request_info". |
|
|
* |
|
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_condition *ccs_get_symlink_condition(struct ccs_request_info |
|
|
*r) |
|
|
{ |
|
|
struct ccs_condition *cond; |
|
|
char *buf; |
|
|
int len = 256; |
|
|
const char *symlink = NULL; |
|
|
const struct ccs_profile *profile = ccs_profile(r->profile); |
|
|
if (profile->learning->learning_symlink_target) { |
|
|
symlink = r->obj->symlink_target->name; |
|
|
len += strlen(symlink) + 18; |
|
|
} |
|
|
buf = kmalloc(len, GFP_KERNEL); |
|
|
if (!buf) |
|
|
return NULL; |
|
|
snprintf(buf, len - 1, "if"); |
|
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, |
|
|
" task.type=execute_handler"); |
|
|
} |
|
|
if (symlink) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, " symlink.target=\"%s\"", |
|
|
symlink); |
|
|
} |
|
|
cond = ccs_get_condition(buf); |
|
|
kfree(buf); |
|
|
return cond; |
|
|
} |
|
|
|
|
2100 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
2101 |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
2102 |
|
|
2119 |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
2120 |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
2121 |
|
|
2122 |
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
2123 |
|
{ |
2124 |
|
va_list args; |
2125 |
|
const int pos = strlen(buffer); |
2126 |
|
va_start(args, fmt); |
2127 |
|
vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
2128 |
|
va_end(args); |
2129 |
|
} |
2130 |
|
|
2131 |
/** |
/** |
2132 |
* ccs_supervisor - Ask for the supervisor's decision. |
* ccs_supervisor - Ask for the supervisor's decision. |
2133 |
* |
* |
2134 |
* @r: Pointer to "struct ccs_request_info". |
* @r: Pointer to "struct ccs_request_info". |
2135 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
2136 |
* |
* |
2137 |
* Returns 0 if the supervisor decided to permit the access request which |
* Returns 0 if the supervisor decided to permit the access request which |
2138 |
* violated the policy in enforcing mode, 1 if the supervisor decided to |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
2139 |
* retry the access request which violated the policy in enforcing mode, |
* decided to retry the access request which violated the policy in enforcing |
2140 |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
* mode, 0 if it is not in enforcing mode, -EPERM otherwise. |
2141 |
*/ |
*/ |
2142 |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2143 |
{ |
{ |
2149 |
struct ccs_query_entry *ccs_query_entry = NULL; |
struct ccs_query_entry *ccs_query_entry = NULL; |
2150 |
bool quota_exceeded = false; |
bool quota_exceeded = false; |
2151 |
char *header; |
char *header; |
2152 |
if (!r->domain) |
struct ccs_domain_info * const domain = ccs_current_domain(); |
2153 |
r->domain = ccs_current_domain(); |
va_start(args, fmt); |
2154 |
switch (r->mode) { |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 80; |
2155 |
|
va_end(args); |
2156 |
|
if (r->mode == CCS_CONFIG_LEARNING) { |
2157 |
char *buffer; |
char *buffer; |
2158 |
struct ccs_condition *cond; |
char *realpath = NULL; |
2159 |
case CCS_CONFIG_LEARNING: |
char *argv0 = NULL; |
2160 |
|
const char *symlink = NULL; |
2161 |
|
const struct ccs_preference *pref; |
2162 |
if (!ccs_domain_quota_ok(r)) |
if (!ccs_domain_quota_ok(r)) |
2163 |
return 0; |
return 0; |
2164 |
va_start(args, fmt); |
pref = ccs_profile(r->profile)->learning; |
2165 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
if (r->param_type == CCS_TYPE_PATH_ACL && |
2166 |
va_end(args); |
r->param.path.operation == CCS_TYPE_EXECUTE) { |
2167 |
buffer = kmalloc(len, GFP_KERNEL); |
if (pref->learning_exec_realpath) { |
2168 |
if (!buffer) |
struct file *file = r->ee->bprm->file; |
2169 |
return 0; |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
2170 |
va_start(args, fmt); |
struct path path = { file->f_vfsmnt, |
2171 |
vsnprintf(buffer, len - 1, fmt, args); |
file->f_dentry }; |
2172 |
va_end(args); |
realpath = ccs_realpath_from_path(&path); |
2173 |
ccs_normalize_line(buffer); |
#else |
2174 |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
realpath = ccs_realpath_from_path(&file-> |
2175 |
cond = ccs_get_execute_condition(r->ee); |
f_path); |
2176 |
else if (r->obj && r->obj->symlink_target) |
#endif |
2177 |
cond = ccs_get_symlink_condition(r); |
if (realpath) |
2178 |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
len += strlen(realpath); |
2179 |
char str[] = "if task.type=execute_handler"; |
} |
2180 |
cond = ccs_get_condition(str); |
if (pref->learning_exec_argv0) { |
2181 |
} else |
if (ccs_get_argv0(r->ee)) { |
2182 |
cond = NULL; |
argv0 = r->ee->tmp; |
2183 |
ccs_write_domain_policy2(buffer, r->domain, cond, false); |
len += strlen(argv0); |
2184 |
ccs_put_condition(cond); |
} |
2185 |
kfree(buffer); |
} |
2186 |
/* fall through */ |
} |
2187 |
case CCS_CONFIG_PERMISSIVE: |
if (r->param_type == CCS_TYPE_PATH_ACL && |
2188 |
|
r->param.path.operation == CCS_TYPE_SYMLINK && |
2189 |
|
pref->learning_symlink_target) { |
2190 |
|
symlink = r->obj->symlink_target->name; |
2191 |
|
len += strlen(symlink); |
2192 |
|
} |
2193 |
|
buffer = kmalloc(len, CCS_GFP_FLAGS); |
2194 |
|
if (buffer) { |
2195 |
|
const bool handler = (current->ccs_flags & |
2196 |
|
CCS_TASK_IS_EXECUTE_HANDLER) |
2197 |
|
!= 0; |
2198 |
|
va_start(args, fmt); |
2199 |
|
vsnprintf(buffer, len - 1, fmt, args); |
2200 |
|
va_end(args); |
2201 |
|
if (handler || realpath || argv0 || symlink) { |
2202 |
|
ccs_addprintf(buffer, len, " if"); |
2203 |
|
if (handler) |
2204 |
|
ccs_addprintf(buffer, len, " task.type" |
2205 |
|
"=execute_handler"); |
2206 |
|
if (realpath) |
2207 |
|
ccs_addprintf(buffer, len, |
2208 |
|
" exec.realpath=\"%s\"", |
2209 |
|
realpath); |
2210 |
|
if (argv0) |
2211 |
|
ccs_addprintf(buffer, len, |
2212 |
|
" exec.argv[0]=\"%s\"", |
2213 |
|
argv0); |
2214 |
|
if (symlink) |
2215 |
|
ccs_addprintf(buffer, len, |
2216 |
|
" symlink.target=\"%s\"", |
2217 |
|
symlink); |
2218 |
|
} |
2219 |
|
ccs_normalize_line(buffer); |
2220 |
|
ccs_write_domain2(buffer, domain, false); |
2221 |
|
kfree(buffer); |
2222 |
|
} |
2223 |
|
kfree(realpath); |
2224 |
return 0; |
return 0; |
2225 |
} |
} |
2226 |
|
if (r->mode != CCS_CONFIG_ENFORCING) |
2227 |
|
return 0; |
2228 |
if (!atomic_read(&ccs_query_observers)) { |
if (!atomic_read(&ccs_query_observers)) { |
2229 |
int i; |
int i; |
2230 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2231 |
return -EPERM; |
return -EPERM; |
2232 |
for (i = 0; i < ccs_profile(r->domain->profile)->enforcing-> |
for (i = 0; i < ccs_profile(domain->profile)->enforcing-> |
2233 |
enforcing_penalty; i++) { |
enforcing_penalty; i++) { |
2234 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2235 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2236 |
} |
} |
2237 |
return -EPERM; |
return -EPERM; |
2238 |
} |
} |
2239 |
va_start(args, fmt); |
header = ccs_init_log(&len, r); |
|
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 32; |
|
|
va_end(args); |
|
|
header = ccs_init_audit_log(&len, r); |
|
2240 |
if (!header) |
if (!header) |
2241 |
goto out; |
goto out; |
2242 |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), GFP_KERNEL); |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), CCS_GFP_FLAGS); |
2243 |
if (!ccs_query_entry) |
if (!ccs_query_entry) |
2244 |
goto out; |
goto out; |
2245 |
len = ccs_round2(len); |
len = ccs_round2(len); |
2246 |
ccs_query_entry->query = kzalloc(len, GFP_KERNEL); |
ccs_query_entry->query = kzalloc(len, CCS_GFP_FLAGS); |
2247 |
if (!ccs_query_entry->query) |
if (!ccs_query_entry->query) |
2248 |
goto out; |
goto out; |
2249 |
INIT_LIST_HEAD(&ccs_query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
2258 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2259 |
if (quota_exceeded) |
if (quota_exceeded) |
2260 |
goto out; |
goto out; |
2261 |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
2262 |
ccs_query_entry->serial, r->retry, header); |
ccs_query_entry->serial, r->retry, header); |
2263 |
kfree(header); |
kfree(header); |
2264 |
header = NULL; |
header = NULL; |
2265 |
va_start(args, fmt); |
ccs_addprintf(ccs_query_entry->query, len, fmt, args); |
|
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
|
2266 |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
|
va_end(args); |
|
2267 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2268 |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
2269 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2283 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2284 |
switch (ccs_query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2285 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2286 |
error = 1; |
error = CCS_RETRY_REQUEST; |
2287 |
r->retry++; |
r->retry++; |
2288 |
break; |
break; |
2289 |
case 1: |
case 1: |
2323 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
2324 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2325 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2326 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr = |
2327 |
= list_entry(tmp, struct ccs_query_entry, list); |
list_entry(tmp, struct ccs_query_entry, list); |
2328 |
if (ptr->answer) |
if (ptr->answer) |
2329 |
continue; |
continue; |
2330 |
found = true; |
found = true; |
2374 |
head->read_step = 0; |
head->read_step = 0; |
2375 |
return; |
return; |
2376 |
} |
} |
2377 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2378 |
if (!buf) |
if (!buf) |
2379 |
return; |
return; |
2380 |
pos = 0; |
pos = 0; |
2450 |
{ |
{ |
2451 |
if (head->read_eof) |
if (head->read_eof) |
2452 |
return; |
return; |
2453 |
ccs_io_printf(head, "1.7.1"); |
ccs_io_printf(head, "1.7.2"); |
2454 |
head->read_eof = true; |
head->read_eof = true; |
2455 |
} |
} |
2456 |
|
|
2481 |
*/ |
*/ |
2482 |
int ccs_open_control(const u8 type, struct file *file) |
int ccs_open_control(const u8 type, struct file *file) |
2483 |
{ |
{ |
2484 |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), GFP_KERNEL); |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), CCS_GFP_FLAGS); |
2485 |
if (!head) |
if (!head) |
2486 |
return -ENOMEM; |
return -ENOMEM; |
2487 |
mutex_init(&head->io_sem); |
mutex_init(&head->io_sem); |
2488 |
head->type = type; |
head->type = type; |
2489 |
switch (type) { |
switch (type) { |
2490 |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
2491 |
head->write = ccs_write_domain_policy; |
head->write = ccs_write_domain; |
2492 |
head->read = ccs_read_domain_policy; |
head->read = ccs_read_domain; |
2493 |
break; |
break; |
2494 |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
2495 |
head->write = ccs_write_exception_policy; |
head->write = ccs_write_exception; |
2496 |
head->read = ccs_read_exception_policy; |
head->read = ccs_read_exception; |
2497 |
break; |
break; |
2498 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
2499 |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
|
head->poll = ccs_poll_grant_log; |
|
|
head->read = ccs_read_grant_log; |
|
|
break; |
|
2500 |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
2501 |
head->poll = ccs_poll_reject_log; |
head->poll = ccs_poll_log; |
2502 |
head->read = ccs_read_reject_log; |
head->read = ccs_read_log; |
2503 |
break; |
break; |
2504 |
#endif |
#endif |
2505 |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
2539 |
head->read = ccs_read_query; |
head->read = ccs_read_query; |
2540 |
break; |
break; |
2541 |
case CCS_MANAGER: /* /proc/ccs/manager */ |
case CCS_MANAGER: /* /proc/ccs/manager */ |
2542 |
head->write = ccs_write_manager_policy; |
head->write = ccs_write_manager; |
2543 |
head->read = ccs_read_manager_policy; |
head->read = ccs_read_manager; |
2544 |
break; |
break; |
2545 |
} |
} |
2546 |
if (!(file->f_mode & FMODE_READ)) { |
if (!(file->f_mode & FMODE_READ)) { |
2554 |
/* Don't allocate read_buf for poll() access. */ |
/* Don't allocate read_buf for poll() access. */ |
2555 |
if (!head->readbuf_size) |
if (!head->readbuf_size) |
2556 |
head->readbuf_size = 4096; |
head->readbuf_size = 4096; |
2557 |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
head->read_buf = kzalloc(head->readbuf_size, CCS_GFP_FLAGS); |
2558 |
if (!head->read_buf) { |
if (!head->read_buf) { |
2559 |
kfree(head); |
kfree(head); |
2560 |
return -ENOMEM; |
return -ENOMEM; |
2568 |
head->write = NULL; |
head->write = NULL; |
2569 |
} else if (head->write) { |
} else if (head->write) { |
2570 |
head->writebuf_size = 4096; |
head->writebuf_size = 4096; |
2571 |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
head->write_buf = kzalloc(head->writebuf_size, CCS_GFP_FLAGS); |
2572 |
if (!head->write_buf) { |
if (!head->write_buf) { |
2573 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2574 |
kfree(head); |
kfree(head); |
2577 |
} |
} |
2578 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2579 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2580 |
head->reader_idx = ccs_read_lock(); |
head->reader_idx = ccs_lock(); |
2581 |
file->private_data = head; |
file->private_data = head; |
2582 |
/* |
/* |
2583 |
* Call the handler now if the file is /proc/ccs/self_domain |
* Call the handler now if the file is /proc/ccs/self_domain |
2630 |
int len = 0; |
int len = 0; |
2631 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
2632 |
char *cp; |
char *cp; |
2633 |
|
int idx; |
2634 |
if (!head->read) |
if (!head->read) |
2635 |
return -ENOSYS; |
return -ENOSYS; |
2636 |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
2637 |
return -EFAULT; |
return -EFAULT; |
2638 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2639 |
return -EINTR; |
return -EINTR; |
2640 |
|
idx = ccs_read_lock(); |
2641 |
while (1) { |
while (1) { |
2642 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2643 |
head->read(head); |
head->read(head); |
2646 |
if (len || head->poll || head->read_eof) |
if (len || head->poll || head->read_eof) |
2647 |
break; |
break; |
2648 |
len = head->readbuf_size * 2; |
len = head->readbuf_size * 2; |
2649 |
cp = kzalloc(len, GFP_KERNEL); |
cp = kzalloc(len, CCS_GFP_FLAGS); |
2650 |
if (!cp) { |
if (!cp) { |
2651 |
len = -ENOMEM; |
len = -ENOMEM; |
2652 |
goto out; |
goto out; |
2668 |
head->read_avail -= len; |
head->read_avail -= len; |
2669 |
memmove(cp, cp + len, head->read_avail); |
memmove(cp, cp + len, head->read_avail); |
2670 |
out: |
out: |
2671 |
|
ccs_read_unlock(idx); |
2672 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2673 |
return len; |
return len; |
2674 |
} |
} |
2689 |
int error = buffer_len; |
int error = buffer_len; |
2690 |
int avail_len = buffer_len; |
int avail_len = buffer_len; |
2691 |
char *cp0 = head->write_buf; |
char *cp0 = head->write_buf; |
2692 |
|
int idx; |
2693 |
if (!head->write) |
if (!head->write) |
2694 |
return -ENOSYS; |
return -ENOSYS; |
2695 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
2696 |
return -EFAULT; |
return -EFAULT; |
|
/* Don't allow updating policies by non manager programs. */ |
|
|
if (head->write != ccs_write_pid && |
|
|
head->write != ccs_write_domain_policy && |
|
|
!ccs_is_policy_manager()) |
|
|
return -EPERM; |
|
2697 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2698 |
return -EINTR; |
return -EINTR; |
2699 |
|
idx = ccs_read_lock(); |
2700 |
|
/* Don't allow updating policies by non manager programs. */ |
2701 |
|
if (head->write != ccs_write_pid && head->write != ccs_write_domain && |
2702 |
|
!ccs_manager()) { |
2703 |
|
ccs_read_unlock(idx); |
2704 |
|
mutex_unlock(&head->io_sem); |
2705 |
|
return -EPERM; |
2706 |
|
} |
2707 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2708 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2709 |
char c; |
char c; |
2710 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->write_avail >= head->writebuf_size - 1) { |
2711 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2712 |
char *cp = kzalloc(len, GFP_KERNEL); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2713 |
if (!cp) { |
if (!cp) { |
2714 |
error = -ENOMEM; |
error = -ENOMEM; |
2715 |
break; |
break; |
2734 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2735 |
head->write(head); |
head->write(head); |
2736 |
} |
} |
2737 |
|
ccs_read_unlock(idx); |
2738 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2739 |
return error; |
return error; |
2740 |
} |
} |
2758 |
atomic_dec(&ccs_query_observers); |
atomic_dec(&ccs_query_observers); |
2759 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2760 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2761 |
ccs_read_unlock(head->reader_idx); |
ccs_unlock(head->reader_idx); |
2762 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
2763 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2764 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2771 |
ccs_run_gc(); |
ccs_run_gc(); |
2772 |
return 0; |
return 0; |
2773 |
} |
} |
2774 |
|
|
2775 |
|
void __init ccs_policy_io_init(void) |
2776 |
|
{ |
2777 |
|
ccsecurity_ops.check_profile = ccs_check_profile; |
2778 |
|
} |