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.0 2009/10/01 |
* Version: 1.7.2 2010/04/01 |
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. |
33 |
.preference.permissive_verbose = true |
.preference.permissive_verbose = true |
34 |
}; |
}; |
35 |
|
|
36 |
|
/* Profile version. Currently only 20090903 is defined. */ |
37 |
|
static unsigned int ccs_profile_version; |
38 |
|
|
39 |
/* Profile table. Memory is allocated as needed. */ |
/* Profile table. Memory is allocated as needed. */ |
40 |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
41 |
|
|
|
/* Lock for protecting "struct ccs_profile"->comment */ |
|
|
static DEFINE_SPINLOCK(ccs_profile_comment_lock); |
|
|
|
|
42 |
/* String table for functionality that takes 4 modes. */ |
/* String table for functionality that takes 4 modes. */ |
43 |
static const char *ccs_mode_4[4] = { |
static const char *ccs_mode_4[4] = { |
44 |
"disabled", "learning", "permissive", "enforcing" |
"disabled", "learning", "permissive", "enforcing" |
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] |
262 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
263 |
if (ptr) |
if (ptr) |
264 |
return ptr; |
return ptr; |
265 |
entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
266 |
mutex_lock(&ccs_policy_lock); |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
267 |
|
goto out; |
268 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
269 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
270 |
ptr = entry; |
ptr = entry; |
281 |
entry = NULL; |
entry = NULL; |
282 |
} |
} |
283 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
284 |
|
out: |
285 |
kfree(entry); |
kfree(entry); |
286 |
return ptr; |
return ptr; |
287 |
} |
} |
289 |
/** |
/** |
290 |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
291 |
*/ |
*/ |
292 |
void ccs_check_profile(void) |
static void ccs_check_profile(void) |
293 |
{ |
{ |
294 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
295 |
|
const int idx = ccs_read_lock(); |
296 |
ccs_policy_loaded = true; |
ccs_policy_loaded = true; |
297 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
298 |
const u8 profile = domain->profile; |
const u8 profile = domain->profile; |
301 |
panic("Profile %u (used by '%s') not defined.\n", |
panic("Profile %u (used by '%s') not defined.\n", |
302 |
profile, domain->domainname->name); |
profile, domain->domainname->name); |
303 |
} |
} |
304 |
|
ccs_read_unlock(idx); |
305 |
|
if (ccs_profile_version != 20090903) |
306 |
|
panic("Profile version %u is not supported.\n", |
307 |
|
ccs_profile_version); |
308 |
|
printk(KERN_INFO "CCSecurity: 1.7.2 2010/04/01\n"); |
309 |
|
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
310 |
} |
} |
311 |
|
|
312 |
/** |
/** |
342 |
bool use_default = false; |
bool use_default = false; |
343 |
char *cp; |
char *cp; |
344 |
struct ccs_profile *profile; |
struct ccs_profile *profile; |
345 |
|
if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1) |
346 |
|
return 0; |
347 |
i = simple_strtoul(data, &cp, 10); |
i = simple_strtoul(data, &cp, 10); |
348 |
if (data == cp) { |
if (data == cp) { |
349 |
profile = &ccs_default_profile; |
profile = &ccs_default_profile; |
367 |
value = 0; |
value = 0; |
368 |
else |
else |
369 |
value = -1; |
value = -1; |
370 |
if (!strcmp(data, "PREFERENCE::audit")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_AUDIT)) { |
371 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
372 |
char *cp2; |
char *cp2; |
373 |
#endif |
#endif |
396 |
profile->preference.audit_path_info = false; |
profile->preference.audit_path_info = false; |
397 |
return 0; |
return 0; |
398 |
} |
} |
399 |
if (!strcmp(data, "PREFERENCE::enforcing")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_ENFORCING)) { |
400 |
char *cp2; |
char *cp2; |
401 |
if (use_default) { |
if (use_default) { |
402 |
profile->enforcing = &ccs_default_profile.preference; |
profile->enforcing = &ccs_default_profile.preference; |
411 |
&profile->preference.enforcing_penalty); |
&profile->preference.enforcing_penalty); |
412 |
return 0; |
return 0; |
413 |
} |
} |
414 |
if (!strcmp(data, "PREFERENCE::permissive")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_PERMISSIVE)) { |
415 |
if (use_default) { |
if (use_default) { |
416 |
profile->permissive = &ccs_default_profile.preference; |
profile->permissive = &ccs_default_profile.preference; |
417 |
return 0; |
return 0; |
421 |
profile->preference.permissive_verbose = value; |
profile->preference.permissive_verbose = value; |
422 |
return 0; |
return 0; |
423 |
} |
} |
424 |
if (!strcmp(data, "PREFERENCE::learning")) { |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_LEARNING)) { |
425 |
char *cp2; |
char *cp2; |
426 |
if (use_default) { |
if (use_default) { |
427 |
profile->learning = &ccs_default_profile.preference; |
profile->learning = &ccs_default_profile.preference; |
451 |
if (profile == &ccs_default_profile) |
if (profile == &ccs_default_profile) |
452 |
return -EINVAL; |
return -EINVAL; |
453 |
if (!strcmp(data, "COMMENT")) { |
if (!strcmp(data, "COMMENT")) { |
454 |
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
const struct ccs_path_info *old_comment = profile->comment; |
455 |
const struct ccs_path_info *old_comment; |
profile->comment = ccs_get_name(cp); |
|
/* Protect reader from ccs_put_name(). */ |
|
|
spin_lock(&ccs_profile_comment_lock); |
|
|
old_comment = profile->comment; |
|
|
profile->comment = new_comment; |
|
|
spin_unlock(&ccs_profile_comment_lock); |
|
456 |
ccs_put_name(old_comment); |
ccs_put_name(old_comment); |
457 |
return 0; |
return 0; |
458 |
} |
} |
506 |
return 0; |
return 0; |
507 |
} |
} |
508 |
|
|
509 |
|
static bool ccs_print_preference(struct ccs_io_buffer *head, const int idx) |
510 |
|
{ |
511 |
|
struct ccs_preference *pref = &ccs_default_profile.preference; |
512 |
|
const struct ccs_profile *profile = idx >= 0 ? |
513 |
|
ccs_profile_ptr[idx] : NULL; |
514 |
|
char buffer[16] = ""; |
515 |
|
if (profile) { |
516 |
|
buffer[sizeof(buffer) - 1] = '\0'; |
517 |
|
snprintf(buffer, sizeof(buffer) - 1, "%u-", idx); |
518 |
|
} |
519 |
|
if (profile) { |
520 |
|
pref = profile->audit; |
521 |
|
if (pref == &ccs_default_profile.preference) |
522 |
|
pref = NULL; |
523 |
|
} |
524 |
|
if (pref && !ccs_io_printf(head, "%s%s={ " |
525 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
526 |
|
"max_grant_log=%u max_reject_log=%u " |
527 |
|
#endif |
528 |
|
"task_info=%s path_info=%s }\n", buffer, |
529 |
|
CCS_KEYWORD_PREFERENCE_AUDIT, |
530 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
531 |
|
pref->audit_max_grant_log, |
532 |
|
pref->audit_max_reject_log, |
533 |
|
#endif |
534 |
|
ccs_yesno(pref->audit_task_info), |
535 |
|
ccs_yesno(pref->audit_path_info))) |
536 |
|
return false; |
537 |
|
if (profile) { |
538 |
|
pref = profile->learning; |
539 |
|
if (pref == &ccs_default_profile.preference) |
540 |
|
pref = NULL; |
541 |
|
} |
542 |
|
if (pref && !ccs_io_printf(head, "%s%s={ " |
543 |
|
"verbose=%s max_entry=%u exec.realpath=%s " |
544 |
|
"exec.argv0=%s symlink.target=%s }\n", |
545 |
|
buffer, CCS_KEYWORD_PREFERENCE_LEARNING, |
546 |
|
ccs_yesno(pref->learning_verbose), |
547 |
|
pref->learning_max_entry, |
548 |
|
ccs_yesno(pref->learning_exec_realpath), |
549 |
|
ccs_yesno(pref->learning_exec_argv0), |
550 |
|
ccs_yesno(pref->learning_symlink_target))) |
551 |
|
return false; |
552 |
|
if (profile) { |
553 |
|
pref = profile->permissive; |
554 |
|
if (pref == &ccs_default_profile.preference) |
555 |
|
pref = NULL; |
556 |
|
} |
557 |
|
if (pref && !ccs_io_printf(head, "%s%s={ verbose=%s }\n", buffer, |
558 |
|
CCS_KEYWORD_PREFERENCE_PERMISSIVE, |
559 |
|
ccs_yesno(pref->permissive_verbose))) |
560 |
|
return false; |
561 |
|
if (profile) { |
562 |
|
pref = profile->enforcing; |
563 |
|
if (pref == &ccs_default_profile.preference) |
564 |
|
pref = NULL; |
565 |
|
} |
566 |
|
return !pref || ccs_io_printf(head, "%s%s={ verbose=%s penalty=%u }\n", |
567 |
|
buffer, CCS_KEYWORD_PREFERENCE_ENFORCING, |
568 |
|
ccs_yesno(pref->enforcing_verbose), |
569 |
|
pref->enforcing_penalty); |
570 |
|
} |
571 |
|
|
572 |
/** |
/** |
573 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
574 |
* |
* |
582 |
if (head->read_bit) |
if (head->read_bit) |
583 |
goto body; |
goto body; |
584 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
585 |
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); |
|
586 |
head->read_bit = 1; |
head->read_bit = 1; |
587 |
body: |
body: |
588 |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
591 |
int i; |
int i; |
592 |
int pos; |
int pos; |
593 |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
594 |
|
const struct ccs_path_info *comment; |
595 |
head->read_step = index; |
head->read_step = index; |
596 |
if (!profile) |
if (!profile) |
597 |
continue; |
continue; |
598 |
pos = head->read_avail; |
pos = head->read_avail; |
599 |
spin_lock(&ccs_profile_comment_lock); |
comment = profile->comment; |
600 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
601 |
profile->comment ? profile->comment->name |
comment ? comment->name : ""); |
|
: ""); |
|
|
spin_unlock(&ccs_profile_comment_lock); |
|
602 |
if (!done) |
if (!done) |
603 |
goto out; |
goto out; |
604 |
config = profile->default_config; |
config = profile->default_config; |
605 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
606 |
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
607 |
"reject_log=%s }\n", index, |
"grant_log=%s reject_log=%s }\n", index, |
608 |
ccs_mode_4[config & 3], |
"CONFIG", "", ccs_mode_4[config & 3], |
609 |
ccs_yesno(config & |
ccs_yesno(config & |
610 |
CCS_CONFIG_WANT_GRANT_LOG), |
CCS_CONFIG_WANT_GRANT_LOG), |
611 |
ccs_yesno(config & |
ccs_yesno(config & |
612 |
CCS_CONFIG_WANT_REJECT_LOG))) |
CCS_CONFIG_WANT_REJECT_LOG))) |
613 |
goto out; |
goto out; |
614 |
#else |
#else |
615 |
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", index, |
616 |
ccs_mode_4[config & 3])) |
"CONFIG", "", ccs_mode_4[config & 3])) |
617 |
goto out; |
goto out; |
618 |
#endif |
#endif |
619 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
628 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
629 |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
630 |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
631 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
632 |
"grant_log=%s reject_log=%s }\n", |
"grant_log=%s reject_log=%s }\n", |
633 |
index, ccs_mac_keywords[i], |
index, "CONFIG::", |
634 |
|
ccs_mac_keywords[i], |
635 |
ccs_mode_4[config & 3], g, r)) |
ccs_mode_4[config & 3], g, r)) |
636 |
goto out; |
goto out; |
637 |
#else |
#else |
638 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", |
639 |
index, ccs_mac_keywords[i], |
index, "CONFIG::", |
640 |
|
ccs_mac_keywords[i], |
641 |
ccs_mode_4[config & 3])) |
ccs_mode_4[config & 3])) |
642 |
goto out; |
goto out; |
643 |
#endif |
#endif |
644 |
} |
} |
645 |
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)) |
|
646 |
goto out; |
goto out; |
647 |
continue; |
continue; |
648 |
out: |
out: |
653 |
head->read_eof = true; |
head->read_eof = true; |
654 |
} |
} |
655 |
|
|
656 |
/* The list for "struct ccs_policy_manager_entry". */ |
static bool ccs_same_manager_entry(const struct ccs_acl_head *a, |
657 |
LIST_HEAD(ccs_policy_manager_list); |
const struct ccs_acl_head *b) |
658 |
|
{ |
659 |
|
return container_of(a, struct ccs_manager, head)->manager |
660 |
|
== container_of(b, struct ccs_manager, head)->manager; |
661 |
|
} |
662 |
|
|
663 |
/** |
/** |
664 |
* ccs_update_manager_entry - Add a manager entry. |
* ccs_update_manager_entry - Add a manager entry. |
670 |
*/ |
*/ |
671 |
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) |
672 |
{ |
{ |
673 |
struct ccs_policy_manager_entry *entry = NULL; |
struct ccs_manager e = { }; |
|
struct ccs_policy_manager_entry *ptr; |
|
|
struct ccs_policy_manager_entry e = { }; |
|
674 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
675 |
if (ccs_is_domain_def(manager)) { |
if (ccs_domain_def(manager)) { |
676 |
if (!ccs_is_correct_domain(manager)) |
if (!ccs_correct_domain(manager)) |
677 |
return -EINVAL; |
return -EINVAL; |
678 |
e.is_domain = true; |
e.is_domain = true; |
679 |
} else { |
} else { |
680 |
if (!ccs_is_correct_path(manager, 1, -1, -1)) |
if (!ccs_correct_path(manager, 1, -1, -1)) |
681 |
return -EINVAL; |
return -EINVAL; |
682 |
} |
} |
683 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
684 |
if (!e.manager) |
if (!e.manager) |
685 |
return -ENOMEM; |
return error; |
686 |
if (!is_delete) |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
687 |
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); |
|
688 |
ccs_put_name(e.manager); |
ccs_put_name(e.manager); |
|
kfree(entry); |
|
689 |
return error; |
return error; |
690 |
} |
} |
691 |
|
|
692 |
/** |
/** |
693 |
* ccs_write_manager_policy - Write manager policy. |
* ccs_write_manager - Write manager policy. |
694 |
* |
* |
695 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
696 |
* |
* |
697 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
698 |
*/ |
*/ |
699 |
static int ccs_write_manager_policy(struct ccs_io_buffer *head) |
static int ccs_write_manager(struct ccs_io_buffer *head) |
700 |
{ |
{ |
701 |
char *data = head->write_buf; |
char *data = head->write_buf; |
702 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
708 |
} |
} |
709 |
|
|
710 |
/** |
/** |
711 |
* ccs_read_manager_policy - Read manager policy. |
* ccs_read_manager - Read manager policy. |
712 |
* |
* |
713 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
714 |
* |
* |
715 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
716 |
*/ |
*/ |
717 |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager(struct ccs_io_buffer *head) |
718 |
{ |
{ |
719 |
struct list_head *pos; |
struct list_head *pos; |
720 |
if (head->read_eof) |
if (head->read_eof) |
721 |
return; |
return; |
722 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(pos, head->read_var2, |
723 |
struct ccs_policy_manager_entry *ptr; |
&ccs_policy_list[CCS_ID_MANAGER]) { |
724 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
struct ccs_manager *ptr |
725 |
if (ptr->is_deleted) |
= list_entry(pos, typeof(*ptr), head.list); |
726 |
|
if (ptr->head.is_deleted) |
727 |
continue; |
continue; |
728 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
729 |
return; |
return; |
732 |
} |
} |
733 |
|
|
734 |
/** |
/** |
735 |
* ccs_is_policy_manager - Check whether the current process is a policy manager. |
* ccs_manager - Check whether the current process is a policy manager. |
736 |
* |
* |
737 |
* Returns true if the current process is permitted to modify policy |
* Returns true if the current process is permitted to modify policy |
738 |
* via /proc/ccs/ interface. |
* via /proc/ccs/ interface. |
739 |
* |
* |
740 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
741 |
*/ |
*/ |
742 |
static bool ccs_is_policy_manager(void) |
static bool ccs_manager(void) |
743 |
{ |
{ |
744 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_manager *ptr; |
745 |
const char *exe; |
const char *exe; |
746 |
struct task_struct *task = current; |
struct task_struct *task = current; |
747 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
749 |
bool found = false; |
bool found = false; |
750 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
751 |
return true; |
return true; |
752 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_MANAGER) |
753 |
return true; |
return true; |
754 |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
755 |
return false; |
return false; |
756 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
757 |
if (!ptr->is_deleted && ptr->is_domain |
head.list) { |
758 |
|
if (!ptr->head.is_deleted && ptr->is_domain |
759 |
&& !ccs_pathcmp(domainname, ptr->manager)) { |
&& !ccs_pathcmp(domainname, ptr->manager)) { |
760 |
/* Set manager flag. */ |
/* Set manager flag. */ |
761 |
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
762 |
return true; |
return true; |
763 |
} |
} |
764 |
} |
} |
765 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
766 |
if (!exe) |
if (!exe) |
767 |
return false; |
return false; |
768 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
769 |
if (!ptr->is_deleted && !ptr->is_domain |
head.list) { |
770 |
|
if (!ptr->head.is_deleted && !ptr->is_domain |
771 |
&& !strcmp(exe, ptr->manager->name)) { |
&& !strcmp(exe, ptr->manager->name)) { |
772 |
found = true; |
found = true; |
773 |
/* Set manager flag. */ |
/* Set manager flag. */ |
774 |
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
775 |
break; |
break; |
776 |
} |
} |
777 |
} |
} |
816 |
} |
} |
817 |
|
|
818 |
/** |
/** |
819 |
* ccs_is_select_one - Parse select command. |
* ccs_select_one - Parse select command. |
820 |
* |
* |
821 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
822 |
* @data: String to parse. |
* @data: String to parse. |
825 |
* |
* |
826 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
827 |
*/ |
*/ |
828 |
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) |
829 |
{ |
{ |
830 |
unsigned int pid; |
unsigned int pid; |
831 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
837 |
if (sscanf(data, "pid=%u", &pid) == 1 || |
if (sscanf(data, "pid=%u", &pid) == 1 || |
838 |
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
839 |
struct task_struct *p; |
struct task_struct *p; |
840 |
read_lock(&tasklist_lock); |
ccs_tasklist_lock(); |
841 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
842 |
if (global_pid) |
if (global_pid) |
843 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, |
844 |
|
&init_pid_ns); |
845 |
else |
else |
846 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
847 |
#else |
#else |
848 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
849 |
#endif |
#endif |
850 |
if (p) |
if (p) |
851 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
852 |
read_unlock(&tasklist_lock); |
ccs_tasklist_unlock(); |
853 |
} else if (!strncmp(data, "domain=", 7)) { |
} else if (!strncmp(data, "domain=", 7)) { |
854 |
if (ccs_is_domain_def(data + 7)) |
if (ccs_domain_def(data + 7)) |
855 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
856 |
} else |
} else |
857 |
return false; |
return false; |
880 |
return true; |
return true; |
881 |
} |
} |
882 |
|
|
883 |
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, |
884 |
struct ccs_condition *cond, |
struct ccs_condition *cond, const bool is_delete) |
885 |
const bool is_delete) |
{ |
886 |
{ |
u8 i; |
887 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CAPABILITY)) |
static const struct { |
888 |
return ccs_write_capability_policy(data, domain, cond, |
const char *keyword; |
889 |
is_delete); |
int (*write) (char *, struct ccs_domain_info *, |
890 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_NETWORK)) |
struct ccs_condition *, const bool); |
891 |
return ccs_write_network_policy(data, domain, cond, is_delete); |
} ccs_callback[5] = { |
892 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_SIGNAL)) |
{ CCS_KEYWORD_ALLOW_NETWORK, ccs_write_network }, |
893 |
return ccs_write_signal_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_ENV, ccs_write_env }, |
894 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
{ CCS_KEYWORD_ALLOW_CAPABILITY, ccs_write_capability }, |
895 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_SIGNAL, ccs_write_signal }, |
896 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
{ CCS_KEYWORD_ALLOW_MOUNT, ccs_write_mount } |
897 |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
}; |
898 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
int (*write) (char *, struct ccs_domain_info *, struct ccs_condition *, |
899 |
|
const bool) = ccs_write_file; |
900 |
|
for (i = 0; i < 5; i++) { |
901 |
|
if (!ccs_str_starts(&data, ccs_callback[i].keyword)) |
902 |
|
continue; |
903 |
|
write = ccs_callback[i].write; |
904 |
|
break; |
905 |
|
} |
906 |
|
return write(data, domain, cond, is_delete); |
907 |
} |
} |
908 |
|
|
909 |
/** |
/** |
910 |
* ccs_write_domain_policy - Write domain policy. |
* ccs_write_domain - Write domain policy. |
911 |
* |
* |
912 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
913 |
* |
* |
914 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
915 |
*/ |
*/ |
916 |
static int ccs_write_domain_policy(struct ccs_io_buffer *head) |
static int ccs_write_domain(struct ccs_io_buffer *head) |
917 |
{ |
{ |
918 |
char *data = head->write_buf; |
char *data = head->write_buf; |
919 |
struct ccs_domain_info *domain = head->write_var1; |
struct ccs_domain_info *domain = head->write_var1; |
927 |
is_delete = true; |
is_delete = true; |
928 |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
929 |
is_select = true; |
is_select = true; |
930 |
if (is_select && ccs_is_select_one(head, data)) |
if (is_select && ccs_select_one(head, data)) |
931 |
return 0; |
return 0; |
932 |
/* Don't allow updating policies by non manager programs. */ |
/* Don't allow updating policies by non manager programs. */ |
933 |
if (!ccs_is_policy_manager()) |
if (!ccs_manager()) |
934 |
return -EPERM; |
return -EPERM; |
935 |
if (ccs_is_domain_def(data)) { |
if (ccs_domain_def(data)) { |
936 |
domain = NULL; |
domain = NULL; |
937 |
if (is_delete) |
if (is_delete) |
938 |
ccs_delete_domain(data); |
ccs_delete_domain(data); |
960 |
domain->ignore_global_allow_env = !is_delete; |
domain->ignore_global_allow_env = !is_delete; |
961 |
return 0; |
return 0; |
962 |
} |
} |
963 |
|
if (!strcmp(data, CCS_KEYWORD_QUOTA_EXCEEDED)) { |
964 |
|
domain->quota_warned = !is_delete; |
965 |
|
return 0; |
966 |
|
} |
967 |
|
if (!strcmp(data, CCS_KEYWORD_TRANSITION_FAILED)) { |
968 |
|
domain->domain_transition_failed = !is_delete; |
969 |
|
return 0; |
970 |
|
} |
971 |
cp = ccs_find_condition_part(data); |
cp = ccs_find_condition_part(data); |
972 |
if (cp) { |
if (cp) { |
973 |
cond = ccs_get_condition(cp); |
cond = ccs_get_condition(cp); |
974 |
if (!cond) |
if (!cond) |
975 |
return -EINVAL; |
return -EINVAL; |
976 |
} |
} |
977 |
error = ccs_write_domain_policy2(data, domain, cond, is_delete); |
error = ccs_write_domain2(data, domain, cond, is_delete); |
978 |
if (cond) |
if (cond) |
979 |
ccs_put_condition(cond); |
ccs_put_condition(cond); |
980 |
return error; |
return error; |
1017 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
1018 |
} |
} |
1019 |
|
|
1020 |
|
static void ccs_print_number(char *buffer, int buffer_len, |
1021 |
|
const struct ccs_number_union *ptr) |
1022 |
|
{ |
1023 |
|
int i; |
1024 |
|
unsigned long min = ptr->values[0]; |
1025 |
|
const unsigned long max = ptr->values[1]; |
1026 |
|
u8 min_type = ptr->value_type[0]; |
1027 |
|
const u8 max_type = ptr->value_type[1]; |
1028 |
|
memset(buffer, 0, buffer_len); |
1029 |
|
buffer_len -= 2; |
1030 |
|
for (i = 0; i < 2; i++) { |
1031 |
|
int len; |
1032 |
|
switch (min_type) { |
1033 |
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
1034 |
|
snprintf(buffer, buffer_len, "0x%lX", min); |
1035 |
|
break; |
1036 |
|
case CCS_VALUE_TYPE_OCTAL: |
1037 |
|
snprintf(buffer, buffer_len, "0%lo", min); |
1038 |
|
break; |
1039 |
|
default: |
1040 |
|
snprintf(buffer, buffer_len, "%lu", min); |
1041 |
|
break; |
1042 |
|
} |
1043 |
|
if (min == max && min_type == max_type) |
1044 |
|
break; |
1045 |
|
len = strlen(buffer); |
1046 |
|
buffer[len++] = '-'; |
1047 |
|
buffer += len; |
1048 |
|
buffer_len -= len; |
1049 |
|
min_type = max_type; |
1050 |
|
min = max; |
1051 |
|
} |
1052 |
|
} |
1053 |
|
|
1054 |
/** |
/** |
1055 |
* ccs_print_number_union_common - Print a ccs_number_union. |
* ccs_print_number_union_common - Print a ccs_number_union. |
1056 |
* |
* |
1064 |
const struct ccs_number_union *ptr, |
const struct ccs_number_union *ptr, |
1065 |
const bool need_space) |
const bool need_space) |
1066 |
{ |
{ |
1067 |
unsigned long min; |
char buffer[128]; |
|
unsigned long max; |
|
|
u8 min_type; |
|
|
u8 max_type; |
|
1068 |
if (need_space && !ccs_io_printf(head, " ")) |
if (need_space && !ccs_io_printf(head, " ")) |
1069 |
return false; |
return false; |
1070 |
if (ptr->is_group) |
if (ptr->is_group) |
1071 |
return ccs_io_printf(head, "@%s", |
return ccs_io_printf(head, "@%s", |
1072 |
ptr->group->group_name->name); |
ptr->group->group_name->name); |
1073 |
min_type = ptr->min_type; |
ccs_print_number(buffer, sizeof(buffer), ptr); |
1074 |
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); |
|
|
} |
|
1075 |
} |
} |
1076 |
|
|
1077 |
/** |
/** |
1116 |
const struct ccs_condition_element *condp; |
const struct ccs_condition_element *condp; |
1117 |
const struct ccs_number_union *numbers_p; |
const struct ccs_number_union *numbers_p; |
1118 |
const struct ccs_name_union *names_p; |
const struct ccs_name_union *names_p; |
1119 |
const struct ccs_argv_entry *argv; |
const struct ccs_argv *argv; |
1120 |
const struct ccs_envp_entry *envp; |
const struct ccs_envp *envp; |
1121 |
u16 condc; |
u16 condc; |
1122 |
u16 i; |
u16 i; |
1123 |
u16 j; |
u16 j; |
1129 |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
1130 |
names_p = (const struct ccs_name_union *) |
names_p = (const struct ccs_name_union *) |
1131 |
(numbers_p + cond->numbers_count); |
(numbers_p + cond->numbers_count); |
1132 |
argv = (const struct ccs_argv_entry *) (names_p + cond->names_count); |
argv = (const struct ccs_argv *) (names_p + cond->names_count); |
1133 |
envp = (const struct ccs_envp_entry *) (argv + cond->argc); |
envp = (const struct ccs_envp *) (argv + cond->argc); |
1134 |
memset(buffer, 0, sizeof(buffer)); |
memset(buffer, 0, sizeof(buffer)); |
1135 |
if (condc && !ccs_io_printf(head, "%s", " if")) |
if (condc && !ccs_io_printf(head, "%s", " if")) |
1136 |
goto out; |
goto out; |
1214 |
} |
} |
1215 |
|
|
1216 |
/** |
/** |
1217 |
* ccs_print_path_acl - Print a single path ACL entry. |
* ccs_print_path_acl - Print a path ACL entry. |
1218 |
* |
* |
1219 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1220 |
* @ptr: Pointer to "struct ccs_path_acl". |
* @ptr: Pointer to "struct ccs_path_acl". |
1232 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1233 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1234 |
continue; |
continue; |
1235 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE) |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
1236 |
|
&& bit != CCS_TYPE_TRANSIT) |
1237 |
continue; |
continue; |
1238 |
/* Print "read/write" instead of "read" and "write". */ |
/* Print "read/write" instead of "read" and "write". */ |
1239 |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
1404 |
} |
} |
1405 |
|
|
1406 |
/** |
/** |
|
* 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; |
|
|
} |
|
|
|
|
|
/** |
|
1407 |
* ccs_print_network_acl - Print a network ACL entry. |
* ccs_print_network_acl - Print a network ACL entry. |
1408 |
* |
* |
1409 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1419 |
int pos; |
int pos; |
1420 |
u8 bit; |
u8 bit; |
1421 |
const u16 perm = ptr->perm; |
const u16 perm = ptr->perm; |
1422 |
|
char buf[128]; |
1423 |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
1424 |
|
const char *w[2] = { "", "" }; |
1425 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1426 |
continue; |
continue; |
1427 |
pos = head->read_avail; |
pos = head->read_avail; |
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
|
|
ccs_net2keyword(bit))) |
|
|
goto out; |
|
1428 |
switch (ptr->address_type) { |
switch (ptr->address_type) { |
1429 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
1430 |
if (!ccs_io_printf(head, "@%s", ptr->address.group-> |
w[0] = "@"; |
1431 |
group_name->name)) |
w[1] = ptr->address.group->group_name->name; |
|
goto out; |
|
1432 |
break; |
break; |
1433 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
case CCS_IP_ADDRESS_TYPE_IPv4: |
1434 |
if (!ccs_print_ipv4_entry(head, ptr)) |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
1435 |
goto out; |
ptr->address.ipv4.max); |
1436 |
|
w[0] = buf; |
1437 |
break; |
break; |
1438 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_IPv6: |
1439 |
if (!ccs_print_ipv6_entry(head, ptr)) |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
1440 |
goto out; |
ptr->address.ipv6.max); |
1441 |
|
w[0] = buf; |
1442 |
break; |
break; |
1443 |
} |
} |
1444 |
if (!ccs_print_number_union(head, &ptr->port) || |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s %s%s", |
1445 |
|
ccs_net2keyword(bit), w[0], w[1]) || |
1446 |
|
!ccs_print_number_union(head, &ptr->port) || |
1447 |
!ccs_print_condition(head, cond)) |
!ccs_print_condition(head, cond)) |
1448 |
goto out; |
goto out; |
1449 |
} |
} |
1489 |
*/ |
*/ |
1490 |
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
1491 |
const char *keyword, |
const char *keyword, |
1492 |
struct ccs_execute_handler_record * |
struct ccs_execute_handler_record |
1493 |
ptr) |
*ptr) |
1494 |
{ |
{ |
1495 |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
1496 |
} |
} |
1564 |
} |
} |
1565 |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
1566 |
struct ccs_path2_acl *acl |
struct ccs_path2_acl *acl |
1567 |
= container_of(ptr, struct ccs_path2_acl, |
= container_of(ptr, struct ccs_path2_acl, head); |
|
head); |
|
1568 |
return ccs_print_path2_acl(head, acl, cond); |
return ccs_print_path2_acl(head, acl, cond); |
1569 |
} |
} |
1570 |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1571 |
struct ccs_path_number_acl *acl |
struct ccs_path_number_acl *acl |
1572 |
= container_of(ptr, struct ccs_path_number_acl, |
= container_of(ptr, struct ccs_path_number_acl, head); |
|
head); |
|
1573 |
return ccs_print_path_number_acl(head, acl, cond); |
return ccs_print_path_number_acl(head, acl, cond); |
1574 |
} |
} |
1575 |
if (acl_type == CCS_TYPE_ENV_ACL) { |
if (acl_type == CCS_TYPE_ENV_ACL) { |
1579 |
} |
} |
1580 |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1581 |
struct ccs_capability_acl *acl |
struct ccs_capability_acl *acl |
1582 |
= container_of(ptr, struct ccs_capability_acl, |
= container_of(ptr, struct ccs_capability_acl, head); |
|
head); |
|
1583 |
return ccs_print_capability_acl(head, acl, cond); |
return ccs_print_capability_acl(head, acl, cond); |
1584 |
} |
} |
1585 |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
1586 |
struct ccs_ip_network_acl *acl |
struct ccs_ip_network_acl *acl |
1587 |
= container_of(ptr, struct ccs_ip_network_acl, |
= container_of(ptr, struct ccs_ip_network_acl, head); |
|
head); |
|
1588 |
return ccs_print_network_acl(head, acl, cond); |
return ccs_print_network_acl(head, acl, cond); |
1589 |
} |
} |
1590 |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1602 |
} |
} |
1603 |
|
|
1604 |
/** |
/** |
1605 |
* ccs_read_domain_policy - Read domain policy. |
* ccs_read_domain - Read domain policy. |
1606 |
* |
* |
1607 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1608 |
* |
* |
1609 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1610 |
*/ |
*/ |
1611 |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain(struct ccs_io_buffer *head) |
1612 |
{ |
{ |
1613 |
struct list_head *dpos; |
struct list_head *dpos; |
1614 |
struct list_head *apos; |
struct list_head *apos; |
1629 |
continue; |
continue; |
1630 |
/* Print domainname and flags. */ |
/* Print domainname and flags. */ |
1631 |
if (domain->quota_warned) |
if (domain->quota_warned) |
1632 |
quota_exceeded = "quota_exceeded\n"; |
quota_exceeded = CCS_KEYWORD_QUOTA_EXCEEDED "\n"; |
1633 |
if (domain->domain_transition_failed) |
if (domain->domain_transition_failed) |
1634 |
transition_failed = "transition_failed\n"; |
transition_failed = CCS_KEYWORD_TRANSITION_FAILED "\n"; |
1635 |
if (domain->ignore_global_allow_read) |
if (domain->ignore_global_allow_read) |
1636 |
ignore_global_allow_read |
ignore_global_allow_read |
1637 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
1765 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
1766 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
1767 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1768 |
if (!buf) |
if (!buf) { |
1769 |
|
head->read_eof = true; |
1770 |
return; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1771 |
|
} |
1772 |
if (head->read_avail || head->read_eof) |
if (head->read_avail || head->read_eof) |
1773 |
return; |
return; |
1774 |
head->read_eof = true; |
head->read_eof = true; |
1777 |
if (ccs_str_starts(&buf, "global-pid ")) |
if (ccs_str_starts(&buf, "global-pid ")) |
1778 |
global_pid = true; |
global_pid = true; |
1779 |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
1780 |
read_lock(&tasklist_lock); |
ccs_tasklist_lock(); |
1781 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1782 |
if (global_pid) |
if (global_pid) |
1783 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, &init_pid_ns); |
1784 |
else |
else |
1785 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
1786 |
#else |
#else |
1787 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1788 |
#endif |
#endif |
1790 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1791 |
ccs_flags = p->ccs_flags; |
ccs_flags = p->ccs_flags; |
1792 |
} |
} |
1793 |
read_unlock(&tasklist_lock); |
ccs_tasklist_unlock(); |
1794 |
if (!domain) |
if (!domain) |
1795 |
return; |
return; |
1796 |
if (!task_info) |
if (!task_info) |
1800 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1801 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1802 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1803 |
CCS_TASK_IS_POLICY_MANAGER), |
CCS_TASK_IS_MANAGER), |
1804 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1805 |
CCS_TASK_IS_EXECUTE_HANDLER), |
CCS_TASK_IS_EXECUTE_HANDLER), |
1806 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1809 |
} |
} |
1810 |
|
|
1811 |
/** |
/** |
1812 |
* ccs_write_exception_policy - Write exception policy. |
* ccs_write_exception - Write exception policy. |
1813 |
* |
* |
1814 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1815 |
* |
* |
1816 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1817 |
*/ |
*/ |
1818 |
static int ccs_write_exception_policy(struct ccs_io_buffer *head) |
static int ccs_write_exception(struct ccs_io_buffer *head) |
1819 |
{ |
{ |
1820 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1821 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
const bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
1822 |
if (ccs_str_starts(&data, CCS_KEYWORD_KEEP_DOMAIN)) |
u8 i; |
1823 |
return ccs_write_domain_keeper_policy(data, false, is_delete); |
static const struct { |
1824 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_KEEP_DOMAIN)) |
const char *keyword; |
1825 |
return ccs_write_domain_keeper_policy(data, true, is_delete); |
int (*write) (char *, const bool, const u8); |
1826 |
if (ccs_str_starts(&data, CCS_KEYWORD_INITIALIZE_DOMAIN)) |
} ccs_callback[10] = { |
1827 |
return ccs_write_domain_initializer_policy(data, false, |
{ CCS_KEYWORD_NO_KEEP_DOMAIN, ccs_write_domain_keeper }, |
1828 |
is_delete); |
{ CCS_KEYWORD_NO_INITIALIZE_DOMAIN, |
1829 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_INITIALIZE_DOMAIN)) |
ccs_write_domain_initializer }, |
1830 |
return ccs_write_domain_initializer_policy(data, true, |
{ CCS_KEYWORD_KEEP_DOMAIN, ccs_write_domain_keeper }, |
1831 |
is_delete); |
{ CCS_KEYWORD_INITIALIZE_DOMAIN, |
1832 |
if (ccs_str_starts(&data, CCS_KEYWORD_AGGREGATOR)) |
ccs_write_domain_initializer }, |
1833 |
return ccs_write_aggregator_policy(data, is_delete); |
{ CCS_KEYWORD_AGGREGATOR, ccs_write_aggregator }, |
1834 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_READ)) |
{ CCS_KEYWORD_ALLOW_READ, ccs_write_global_read }, |
1835 |
return ccs_write_globally_readable_policy(data, is_delete); |
{ CCS_KEYWORD_ALLOW_ENV, ccs_write_global_env }, |
1836 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
{ CCS_KEYWORD_FILE_PATTERN, ccs_write_pattern }, |
1837 |
return ccs_write_globally_usable_env_policy(data, is_delete); |
{ CCS_KEYWORD_DENY_REWRITE, ccs_write_no_rewrite }, |
1838 |
if (ccs_str_starts(&data, CCS_KEYWORD_FILE_PATTERN)) |
{ CCS_KEYWORD_DENY_AUTOBIND, ccs_write_reserved_port } |
1839 |
return ccs_write_pattern_policy(data, is_delete); |
}; |
1840 |
if (ccs_str_starts(&data, CCS_KEYWORD_PATH_GROUP)) |
static const char *ccs_name[CCS_MAX_GROUP] = { |
1841 |
return ccs_write_path_group_policy(data, is_delete); |
[CCS_PATH_GROUP] = CCS_KEYWORD_PATH_GROUP, |
1842 |
if (ccs_str_starts(&data, CCS_KEYWORD_NUMBER_GROUP)) |
[CCS_NUMBER_GROUP] = CCS_KEYWORD_NUMBER_GROUP, |
1843 |
return ccs_write_number_group_policy(data, is_delete); |
[CCS_ADDRESS_GROUP] = CCS_KEYWORD_ADDRESS_GROUP |
1844 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_REWRITE)) |
}; |
1845 |
return ccs_write_no_rewrite_policy(data, is_delete); |
for (i = 0; i < 10; i++) { |
1846 |
if (ccs_str_starts(&data, CCS_KEYWORD_ADDRESS_GROUP)) |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
1847 |
return ccs_write_address_group_policy(data, is_delete); |
return ccs_callback[i].write(data, is_delete, i < 2); |
1848 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_AUTOBIND)) |
} |
1849 |
return ccs_write_reserved_port_policy(data, is_delete); |
for (i = 0; i < CCS_MAX_GROUP; i++) { |
1850 |
|
if (ccs_str_starts(&data, ccs_name[i])) |
1851 |
|
return ccs_write_group(data, is_delete, i); |
1852 |
|
} |
1853 |
return -EINVAL; |
return -EINVAL; |
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 |
|
} else if (idx == CCS_NUMBER_GROUP) { |
1892 |
|
w[2] = buffer; |
1893 |
|
ccs_print_number(buffer, sizeof(buffer), |
1894 |
|
&container_of |
1895 |
|
(ptr, struct ccs_number_group, |
1896 |
|
head)->number); |
1897 |
|
} else if (idx == CCS_ADDRESS_GROUP) { |
1898 |
|
struct ccs_address_group *member = |
1899 |
|
container_of(ptr, typeof(*member), |
1900 |
|
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 = 6; |
{ |
1956 |
case 6: |
struct ccs_domain_initializer *ptr = |
1957 |
if (!ccs_read_aggregator_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 = 7; |
{ |
1970 |
case 7: |
struct ccs_aggregator *ptr = |
1971 |
if (!ccs_read_file_pattern(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_var2 = NULL; |
case CCS_ID_GLOBAL_READ: |
1979 |
head->read_step = 8; |
{ |
1980 |
case 8: |
struct ccs_global_read *ptr = |
1981 |
if (!ccs_read_no_rewrite_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1982 |
|
w[0] = CCS_KEYWORD_ALLOW_READ; |
1983 |
|
w[1] = ptr->filename->name; |
1984 |
|
} |
1985 |
break; |
break; |
1986 |
head->read_var2 = NULL; |
case CCS_ID_PATTERN: |
1987 |
head->read_step = 9; |
{ |
1988 |
case 9: |
struct ccs_pattern *ptr = |
1989 |
if (!ccs_read_path_group_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1990 |
|
w[0] = CCS_KEYWORD_FILE_PATTERN; |
1991 |
|
w[1] = ptr->pattern->name; |
1992 |
|
} |
1993 |
break; |
break; |
1994 |
head->read_var1 = NULL; |
case CCS_ID_NO_REWRITE: |
1995 |
head->read_var2 = NULL; |
{ |
1996 |
head->read_step = 10; |
struct ccs_no_rewrite *ptr = |
1997 |
case 10: |
container_of(acl, typeof(*ptr), head); |
1998 |
if (!ccs_read_number_group_policy(head)) |
w[0] = CCS_KEYWORD_DENY_REWRITE; |
1999 |
|
w[1] = ptr->pattern->name; |
2000 |
|
} |
2001 |
break; |
break; |
2002 |
head->read_var1 = NULL; |
case CCS_ID_GLOBAL_ENV: |
2003 |
head->read_var2 = NULL; |
{ |
2004 |
head->read_step = 11; |
struct ccs_global_env *ptr = |
2005 |
case 11: |
container_of(acl, typeof(*ptr), head); |
2006 |
if (!ccs_read_address_group_policy(head)) |
w[0] = CCS_KEYWORD_ALLOW_ENV; |
2007 |
|
w[1] = ptr->env->name; |
2008 |
|
} |
2009 |
break; |
break; |
2010 |
head->read_var2 = NULL; |
case CCS_ID_RESERVEDPORT: |
2011 |
head->read_step = 12; |
{ |
2012 |
case 12: |
struct ccs_reserved *ptr = |
2013 |
if (!ccs_read_reserved_port_policy(head)) |
container_of(acl, typeof(*ptr), head); |
2014 |
|
const u16 min_port = ptr->min_port; |
2015 |
|
const u16 max_port = ptr->max_port; |
2016 |
|
w[0] = CCS_KEYWORD_DENY_AUTOBIND; |
2017 |
|
snprintf(buffer, sizeof(buffer) - 1, "%u%c%u", |
2018 |
|
min_port, min_port != max_port ? |
2019 |
|
'-' : '\0', max_port); |
2020 |
|
buffer[sizeof(buffer) - 1] = '\0'; |
2021 |
|
w[1] = buffer; |
2022 |
|
} |
2023 |
break; |
break; |
2024 |
head->read_eof = true; |
} |
2025 |
|
if (!ccs_io_printf(head, "%s%s%s%s\n", w[0], w[1], w[2], w[3])) |
2026 |
|
return false; |
2027 |
} |
} |
2028 |
|
return true; |
2029 |
|
} |
2030 |
|
|
2031 |
|
/** |
2032 |
|
* ccs_read_exception - Read exception policy. |
2033 |
|
* |
2034 |
|
* @head: Pointer to "struct ccs_io_buffer". |
2035 |
|
* |
2036 |
|
* Caller holds ccs_read_lock(). |
2037 |
|
*/ |
2038 |
|
static void ccs_read_exception(struct ccs_io_buffer *head) |
2039 |
|
{ |
2040 |
|
if (head->read_eof) |
2041 |
|
return; |
2042 |
|
while (head->read_step < CCS_MAX_POLICY && |
2043 |
|
ccs_read_policy(head, head->read_step)) |
2044 |
|
head->read_step++; |
2045 |
|
if (head->read_step < CCS_MAX_POLICY) |
2046 |
|
return; |
2047 |
|
while (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
2048 |
|
ccs_read_group(head, head->read_step - CCS_MAX_POLICY)) |
2049 |
|
head->read_step++; |
2050 |
|
head->read_eof = head->read_step == CCS_MAX_POLICY + CCS_MAX_GROUP; |
2051 |
} |
} |
2052 |
|
|
2053 |
/** |
/** |
2054 |
* ccs_get_argv0 - Get argv[0]. |
* ccs_get_argv0 - Get argv[0]. |
2055 |
* |
* |
2056 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
2057 |
* |
* |
2058 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
2059 |
*/ |
*/ |
2060 |
static bool ccs_get_argv0(struct ccs_execve_entry *ee) |
static bool ccs_get_argv0(struct ccs_execve *ee) |
2061 |
{ |
{ |
2062 |
struct linux_binprm *bprm = ee->bprm; |
struct linux_binprm *bprm = ee->bprm; |
2063 |
char *arg_ptr = ee->tmp; |
char *arg_ptr = ee->tmp; |
2106 |
/** |
/** |
2107 |
* ccs_get_execute_condition - Get condition part for execute requests. |
* ccs_get_execute_condition - Get condition part for execute requests. |
2108 |
* |
* |
2109 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
2110 |
* |
* |
2111 |
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2112 |
*/ |
*/ |
2113 |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve |
2114 |
*ee) |
*ee) |
2115 |
{ |
{ |
2116 |
struct ccs_condition *cond; |
struct ccs_condition *cond; |
2118 |
int len = 256; |
int len = 256; |
2119 |
char *realpath = NULL; |
char *realpath = NULL; |
2120 |
char *argv0 = NULL; |
char *argv0 = NULL; |
2121 |
const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile); |
const struct ccs_profile *profile = ccs_profile(ccs_current_domain()-> |
2122 |
|
profile); |
2123 |
if (profile->learning->learning_exec_realpath) { |
if (profile->learning->learning_exec_realpath) { |
2124 |
struct file *file = ee->bprm->file; |
struct file *file = ee->bprm->file; |
2125 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
2137 |
len += strlen(argv0) + 16; |
len += strlen(argv0) + 16; |
2138 |
} |
} |
2139 |
} |
} |
2140 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, CCS_GFP_FLAGS); |
2141 |
if (!buf) { |
if (!buf) { |
2142 |
kfree(realpath); |
kfree(realpath); |
2143 |
return NULL; |
return NULL; |
2183 |
symlink = r->obj->symlink_target->name; |
symlink = r->obj->symlink_target->name; |
2184 |
len += strlen(symlink) + 18; |
len += strlen(symlink) + 18; |
2185 |
} |
} |
2186 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, CCS_GFP_FLAGS); |
2187 |
if (!buf) |
if (!buf) |
2188 |
return NULL; |
return NULL; |
2189 |
snprintf(buf, len - 1, "if"); |
snprintf(buf, len - 1, "if"); |
2231 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
2232 |
* |
* |
2233 |
* Returns 0 if the supervisor decided to permit the access request which |
* Returns 0 if the supervisor decided to permit the access request which |
2234 |
* violated the policy in enforcing mode, 1 if the supervisor decided to |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
2235 |
* retry the access request which violated the policy in enforcing mode, |
* decided to retry the access request which violated the policy in enforcing |
2236 |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
* mode, 0 if it is not in enforcing mode, -EPERM otherwise. |
2237 |
*/ |
*/ |
2238 |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2239 |
{ |
{ |
2245 |
struct ccs_query_entry *ccs_query_entry = NULL; |
struct ccs_query_entry *ccs_query_entry = NULL; |
2246 |
bool quota_exceeded = false; |
bool quota_exceeded = false; |
2247 |
char *header; |
char *header; |
2248 |
if (!r->domain) |
struct ccs_domain_info * const domain = ccs_current_domain(); |
|
r->domain = ccs_current_domain(); |
|
2249 |
switch (r->mode) { |
switch (r->mode) { |
2250 |
char *buffer; |
char *buffer; |
2251 |
struct ccs_condition *cond; |
struct ccs_condition *cond; |
2255 |
va_start(args, fmt); |
va_start(args, fmt); |
2256 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
2257 |
va_end(args); |
va_end(args); |
2258 |
buffer = kmalloc(len, GFP_KERNEL); |
buffer = kmalloc(len, CCS_GFP_FLAGS); |
2259 |
if (!buffer) |
if (!buffer) |
2260 |
return 0; |
return 0; |
2261 |
va_start(args, fmt); |
va_start(args, fmt); |
2271 |
cond = ccs_get_condition(str); |
cond = ccs_get_condition(str); |
2272 |
} else |
} else |
2273 |
cond = NULL; |
cond = NULL; |
2274 |
ccs_write_domain_policy2(buffer, r->domain, cond, false); |
ccs_write_domain2(buffer, domain, cond, false); |
2275 |
ccs_put_condition(cond); |
ccs_put_condition(cond); |
2276 |
kfree(buffer); |
kfree(buffer); |
2277 |
/* fall through */ |
/* fall through */ |
2282 |
int i; |
int i; |
2283 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2284 |
return -EPERM; |
return -EPERM; |
2285 |
for (i = 0; i < ccs_profile(r->domain->profile)->enforcing-> |
for (i = 0; i < ccs_profile(domain->profile)->enforcing-> |
2286 |
enforcing_penalty; i++) { |
enforcing_penalty; i++) { |
2287 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2288 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2295 |
header = ccs_init_audit_log(&len, r); |
header = ccs_init_audit_log(&len, r); |
2296 |
if (!header) |
if (!header) |
2297 |
goto out; |
goto out; |
2298 |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), GFP_KERNEL); |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), CCS_GFP_FLAGS); |
2299 |
if (!ccs_query_entry) |
if (!ccs_query_entry) |
2300 |
goto out; |
goto out; |
2301 |
len = ccs_round2(len); |
len = ccs_round2(len); |
2302 |
ccs_query_entry->query = kzalloc(len, GFP_KERNEL); |
ccs_query_entry->query = kzalloc(len, CCS_GFP_FLAGS); |
2303 |
if (!ccs_query_entry->query) |
if (!ccs_query_entry->query) |
2304 |
goto out; |
goto out; |
2305 |
INIT_LIST_HEAD(&ccs_query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
2341 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2342 |
switch (ccs_query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2343 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2344 |
error = 1; |
error = CCS_RETRY_REQUEST; |
2345 |
r->retry++; |
r->retry++; |
2346 |
break; |
break; |
2347 |
case 1: |
case 1: |
2381 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
2382 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2383 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2384 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr = |
2385 |
= list_entry(tmp, struct ccs_query_entry, list); |
list_entry(tmp, struct ccs_query_entry, list); |
2386 |
if (ptr->answer) |
if (ptr->answer) |
2387 |
continue; |
continue; |
2388 |
found = true; |
found = true; |
2432 |
head->read_step = 0; |
head->read_step = 0; |
2433 |
return; |
return; |
2434 |
} |
} |
2435 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2436 |
if (!buf) |
if (!buf) |
2437 |
return; |
return; |
2438 |
pos = 0; |
pos = 0; |
2508 |
{ |
{ |
2509 |
if (head->read_eof) |
if (head->read_eof) |
2510 |
return; |
return; |
2511 |
ccs_io_printf(head, "1.7.0"); |
ccs_io_printf(head, "1.7.2"); |
2512 |
head->read_eof = true; |
head->read_eof = true; |
2513 |
} |
} |
2514 |
|
|
2539 |
*/ |
*/ |
2540 |
int ccs_open_control(const u8 type, struct file *file) |
int ccs_open_control(const u8 type, struct file *file) |
2541 |
{ |
{ |
2542 |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), GFP_KERNEL); |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), CCS_GFP_FLAGS); |
2543 |
if (!head) |
if (!head) |
2544 |
return -ENOMEM; |
return -ENOMEM; |
2545 |
mutex_init(&head->io_sem); |
mutex_init(&head->io_sem); |
2546 |
head->type = type; |
head->type = type; |
2547 |
switch (type) { |
switch (type) { |
2548 |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
2549 |
head->write = ccs_write_domain_policy; |
head->write = ccs_write_domain; |
2550 |
head->read = ccs_read_domain_policy; |
head->read = ccs_read_domain; |
2551 |
break; |
break; |
2552 |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
2553 |
head->write = ccs_write_exception_policy; |
head->write = ccs_write_exception; |
2554 |
head->read = ccs_read_exception_policy; |
head->read = ccs_read_exception; |
2555 |
break; |
break; |
2556 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
2557 |
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; |
|
2558 |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
2559 |
head->poll = ccs_poll_reject_log; |
head->poll = ccs_poll_audit_log; |
2560 |
head->read = ccs_read_reject_log; |
head->read = ccs_read_audit_log; |
2561 |
break; |
break; |
2562 |
#endif |
#endif |
2563 |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
2597 |
head->read = ccs_read_query; |
head->read = ccs_read_query; |
2598 |
break; |
break; |
2599 |
case CCS_MANAGER: /* /proc/ccs/manager */ |
case CCS_MANAGER: /* /proc/ccs/manager */ |
2600 |
head->write = ccs_write_manager_policy; |
head->write = ccs_write_manager; |
2601 |
head->read = ccs_read_manager_policy; |
head->read = ccs_read_manager; |
2602 |
break; |
break; |
2603 |
} |
} |
2604 |
if (!(file->f_mode & FMODE_READ)) { |
if (!(file->f_mode & FMODE_READ)) { |
2612 |
/* Don't allocate read_buf for poll() access. */ |
/* Don't allocate read_buf for poll() access. */ |
2613 |
if (!head->readbuf_size) |
if (!head->readbuf_size) |
2614 |
head->readbuf_size = 4096; |
head->readbuf_size = 4096; |
2615 |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
head->read_buf = kzalloc(head->readbuf_size, CCS_GFP_FLAGS); |
2616 |
if (!head->read_buf) { |
if (!head->read_buf) { |
2617 |
kfree(head); |
kfree(head); |
2618 |
return -ENOMEM; |
return -ENOMEM; |
2626 |
head->write = NULL; |
head->write = NULL; |
2627 |
} else if (head->write) { |
} else if (head->write) { |
2628 |
head->writebuf_size = 4096; |
head->writebuf_size = 4096; |
2629 |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
head->write_buf = kzalloc(head->writebuf_size, CCS_GFP_FLAGS); |
2630 |
if (!head->write_buf) { |
if (!head->write_buf) { |
2631 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2632 |
kfree(head); |
kfree(head); |
2635 |
} |
} |
2636 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2637 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2638 |
head->reader_idx = ccs_read_lock(); |
head->reader_idx = ccs_lock(); |
2639 |
file->private_data = head; |
file->private_data = head; |
2640 |
/* |
/* |
2641 |
* Call the handler now if the file is /proc/ccs/self_domain |
* Call the handler now if the file is /proc/ccs/self_domain |
2688 |
int len = 0; |
int len = 0; |
2689 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
2690 |
char *cp; |
char *cp; |
2691 |
|
int idx; |
2692 |
if (!head->read) |
if (!head->read) |
2693 |
return -ENOSYS; |
return -ENOSYS; |
2694 |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
2695 |
return -EFAULT; |
return -EFAULT; |
2696 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2697 |
return -EINTR; |
return -EINTR; |
2698 |
|
idx = ccs_read_lock(); |
2699 |
while (1) { |
while (1) { |
2700 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2701 |
head->read(head); |
head->read(head); |
2704 |
if (len || head->poll || head->read_eof) |
if (len || head->poll || head->read_eof) |
2705 |
break; |
break; |
2706 |
len = head->readbuf_size * 2; |
len = head->readbuf_size * 2; |
2707 |
cp = kzalloc(len, GFP_KERNEL); |
cp = kzalloc(len, CCS_GFP_FLAGS); |
2708 |
if (!cp) { |
if (!cp) { |
2709 |
len = -ENOMEM; |
len = -ENOMEM; |
2710 |
goto out; |
goto out; |
2726 |
head->read_avail -= len; |
head->read_avail -= len; |
2727 |
memmove(cp, cp + len, head->read_avail); |
memmove(cp, cp + len, head->read_avail); |
2728 |
out: |
out: |
2729 |
|
ccs_read_unlock(idx); |
2730 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2731 |
return len; |
return len; |
2732 |
} |
} |
2747 |
int error = buffer_len; |
int error = buffer_len; |
2748 |
int avail_len = buffer_len; |
int avail_len = buffer_len; |
2749 |
char *cp0 = head->write_buf; |
char *cp0 = head->write_buf; |
2750 |
|
int idx; |
2751 |
if (!head->write) |
if (!head->write) |
2752 |
return -ENOSYS; |
return -ENOSYS; |
2753 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
2754 |
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; |
|
2755 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2756 |
return -EINTR; |
return -EINTR; |
2757 |
|
idx = ccs_read_lock(); |
2758 |
|
/* Don't allow updating policies by non manager programs. */ |
2759 |
|
if (head->write != ccs_write_pid && head->write != ccs_write_domain && |
2760 |
|
!ccs_manager()) { |
2761 |
|
ccs_read_unlock(idx); |
2762 |
|
mutex_unlock(&head->io_sem); |
2763 |
|
return -EPERM; |
2764 |
|
} |
2765 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2766 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2767 |
char c; |
char c; |
2768 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->write_avail >= head->writebuf_size - 1) { |
2769 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2770 |
char *cp = kzalloc(len, GFP_KERNEL); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2771 |
if (!cp) { |
if (!cp) { |
2772 |
error = -ENOMEM; |
error = -ENOMEM; |
2773 |
break; |
break; |
2792 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2793 |
head->write(head); |
head->write(head); |
2794 |
} |
} |
2795 |
|
ccs_read_unlock(idx); |
2796 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2797 |
return error; |
return error; |
2798 |
} |
} |
2816 |
atomic_dec(&ccs_query_observers); |
atomic_dec(&ccs_query_observers); |
2817 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2818 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2819 |
ccs_read_unlock(head->reader_idx); |
ccs_unlock(head->reader_idx); |
2820 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
2821 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2822 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2829 |
ccs_run_gc(); |
ccs_run_gc(); |
2830 |
return 0; |
return 0; |
2831 |
} |
} |
2832 |
|
|
2833 |
|
void __init ccs_policy_io_init(void) |
2834 |
|
{ |
2835 |
|
ccsecurity_ops.check_profile = ccs_check_profile; |
2836 |
|
} |