5 |
* |
* |
6 |
* Copyright (C) 2005-2008 NTT DATA CORPORATION |
* Copyright (C) 2005-2008 NTT DATA CORPORATION |
7 |
* |
* |
8 |
* Version: 1.5.3-pre 2008/01/02 |
* Version: 1.6.0-pre 2008/02/05 |
9 |
* |
* |
10 |
* 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. |
11 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
32 |
#include <linux/ccs_common.h> |
#include <linux/ccs_common.h> |
33 |
#include <linux/ccs_proc.h> |
#include <linux/ccs_proc.h> |
34 |
#include <linux/tomoyo.h> |
#include <linux/tomoyo.h> |
35 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) |
36 |
|
#define find_task_by_pid find_task_by_vpid |
37 |
|
#endif |
38 |
|
|
39 |
#ifdef CONFIG_TOMOYO_MAX_ACCEPT_ENTRY |
#ifdef CONFIG_TOMOYO_MAX_ACCEPT_ENTRY |
40 |
#define MAX_ACCEPT_ENTRY (CONFIG_TOMOYO_MAX_ACCEPT_ENTRY) |
#define MAX_ACCEPT_ENTRY (CONFIG_TOMOYO_MAX_ACCEPT_ENTRY) |
106 |
#endif |
#endif |
107 |
|
|
108 |
/* Am I root? */ |
/* Am I root? */ |
109 |
static int isRoot(void) |
static int isRoot(struct io_buffer *head) |
110 |
{ |
{ |
111 |
return !current->uid && !current->euid; |
const struct task_struct *task = current; |
112 |
|
return (!task->uid && !task->euid) || (task->uid && task->uid == head->uid) || (task->gid && task->gid == head->gid); |
113 |
} |
} |
114 |
|
|
115 |
/* |
/* |
507 |
/************************* DOMAIN POLICY HANDLER *************************/ |
/************************* DOMAIN POLICY HANDLER *************************/ |
508 |
|
|
509 |
/* Check whether the given access control is enabled. */ |
/* Check whether the given access control is enabled. */ |
510 |
unsigned int CheckCCSFlags(const u8 index) |
unsigned int CheckCCSFlags_NoSleepCheck(const u8 index) |
511 |
{ |
{ |
512 |
const u8 profile = current->domain_info->profile; |
const u8 profile = current->domain_info->profile; |
513 |
return sbin_init_started && index < CCS_MAX_CONTROL_INDEX |
return sbin_init_started && index < CCS_MAX_CONTROL_INDEX |
517 |
&& profile_ptr[profile] ? profile_ptr[profile]->value[index] : 0; |
&& profile_ptr[profile] ? profile_ptr[profile]->value[index] : 0; |
518 |
} |
} |
519 |
|
|
520 |
|
unsigned int CheckCCSFlags(const u8 index) |
521 |
|
{ |
522 |
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) |
523 |
|
if (unlikely(in_interrupt())) |
524 |
|
#else |
525 |
|
if (unlikely(in_atomic())) |
526 |
|
#endif |
527 |
|
{ |
528 |
|
static u8 count = 20; |
529 |
|
if (count) { |
530 |
|
count--; |
531 |
|
printk(KERN_ERR "BUG: sleeping function called from invalid context.\n"); |
532 |
|
dump_stack(); |
533 |
|
} |
534 |
|
/* Return 0 so that no MAC checks are performed. */ |
535 |
|
return 0; |
536 |
|
} |
537 |
|
return CheckCCSFlags_NoSleepCheck(index); |
538 |
|
} |
539 |
|
|
540 |
bool TomoyoVerboseMode(void) |
bool TomoyoVerboseMode(void) |
541 |
{ |
{ |
542 |
return CheckCCSFlags(CCS_TOMOYO_VERBOSE) != 0; |
return CheckCCSFlags(CCS_TOMOYO_VERBOSE) != 0; |
548 |
struct acl_info *ptr; |
struct acl_info *ptr; |
549 |
if (!domain) return 1; |
if (!domain) return 1; |
550 |
list1_for_each_entry(ptr, &domain->acl_info_list, list) { |
list1_for_each_entry(ptr, &domain->acl_info_list, list) { |
551 |
if (!ptr->is_deleted) count++; |
if (!(ptr->type & ACL_DELETED)) count++; |
552 |
} |
} |
553 |
if (count < CheckCCSFlags(CCS_TOMOYO_MAX_ACCEPT_ENTRY)) return 1; |
if (count < CheckCCSFlags(CCS_TOMOYO_MAX_ACCEPT_ENTRY)) return 1; |
554 |
if (!domain->quota_warned) { |
if (!domain->quota_warned) { |
583 |
unsigned int i, value; |
unsigned int i, value; |
584 |
char *cp; |
char *cp; |
585 |
struct profile *profile; |
struct profile *profile; |
586 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
587 |
i = simple_strtoul(data, &cp, 10); |
i = simple_strtoul(data, &cp, 10); |
588 |
if (data != cp) { |
if (data != cp) { |
589 |
if (*cp != '-') return -EINVAL; |
if (*cp != '-') return -EINVAL; |
627 |
static int ReadProfile(struct io_buffer *head) |
static int ReadProfile(struct io_buffer *head) |
628 |
{ |
{ |
629 |
if (!head->read_eof) { |
if (!head->read_eof) { |
630 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
631 |
if (!head->read_var2) { |
if (!head->read_var2) { |
632 |
int step; |
int step; |
633 |
for (step = head->read_step; step < MAX_PROFILES * CCS_MAX_CONTROL_INDEX; step++) { |
for (step = head->read_step; step < MAX_PROFILES * CCS_MAX_CONTROL_INDEX; step++) { |
704 |
const struct path_info *saved_manager; |
const struct path_info *saved_manager; |
705 |
int error = -ENOMEM; |
int error = -ENOMEM; |
706 |
bool is_domain = 0; |
bool is_domain = 0; |
|
if (!isRoot()) return -EPERM; |
|
707 |
if (IsDomainDef(manager)) { |
if (IsDomainDef(manager)) { |
708 |
if (!IsCorrectDomain(manager, __FUNCTION__)) return -EINVAL; |
if (!IsCorrectDomain(manager, __FUNCTION__)) return -EINVAL; |
709 |
is_domain = 1; |
is_domain = 1; |
738 |
{ |
{ |
739 |
const char *data = head->write_buf; |
const char *data = head->write_buf; |
740 |
bool is_delete = 0; |
bool is_delete = 0; |
741 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
742 |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
743 |
data += KEYWORD_DELETE_LEN; |
data += KEYWORD_DELETE_LEN; |
744 |
is_delete = 1; |
is_delete = 1; |
750 |
{ |
{ |
751 |
struct list1_head *pos; |
struct list1_head *pos; |
752 |
if (head->read_eof) return 0; |
if (head->read_eof) return 0; |
753 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
754 |
list1_for_each_cookie(pos, head->read_var2, &policy_manager_list) { |
list1_for_each_cookie(pos, head->read_var2, &policy_manager_list) { |
755 |
struct policy_manager_entry *ptr; |
struct policy_manager_entry *ptr; |
756 |
ptr = list1_entry(pos, struct policy_manager_entry, list); |
ptr = list1_entry(pos, struct policy_manager_entry, list); |
812 |
bool is_delete = 0, is_select = 0, is_undelete = 0; |
bool is_delete = 0, is_select = 0, is_undelete = 0; |
813 |
unsigned int profile; |
unsigned int profile; |
814 |
const struct condition_list *cond = NULL; |
const struct condition_list *cond = NULL; |
815 |
char *cp; |
char *cp; |
816 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
817 |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
818 |
data += KEYWORD_DELETE_LEN; |
data += KEYWORD_DELETE_LEN; |
819 |
is_delete = 1; |
is_delete = 1; |
824 |
data += KEYWORD_UNDELETE_LEN; |
data += KEYWORD_UNDELETE_LEN; |
825 |
is_undelete = 1; |
is_undelete = 1; |
826 |
} |
} |
|
UpdateCounter(CCS_UPDATES_COUNTER_DOMAIN_POLICY); |
|
827 |
if (IsDomainDef(data)) { |
if (IsDomainDef(data)) { |
828 |
if (is_delete) { |
if (is_delete) { |
829 |
DeleteDomain(data); |
DeleteDomain(data); |
836 |
domain = FindOrAssignNewDomain(data, 0); |
domain = FindOrAssignNewDomain(data, 0); |
837 |
} |
} |
838 |
head->write_var1 = domain; |
head->write_var1 = domain; |
839 |
|
UpdateCounter(CCS_UPDATES_COUNTER_DOMAIN_POLICY); |
840 |
return 0; |
return 0; |
841 |
} |
} |
842 |
if (!domain) return -EINVAL; |
if (!domain) return -EINVAL; |
863 |
return -EINVAL; |
return -EINVAL; |
864 |
} |
} |
865 |
|
|
866 |
|
static bool print_single_path_acl(struct io_buffer *head, struct single_path_acl_record *ptr, const struct condition_list *cond) |
867 |
|
{ |
868 |
|
int pos; |
869 |
|
u8 bit; |
870 |
|
const bool b = ptr->u_is_group; |
871 |
|
const u16 perm = ptr->perm; |
872 |
|
for (bit = head->read_bit; bit < MAX_SINGLE_PATH_OPERATION; bit++) { |
873 |
|
const char *msg; |
874 |
|
if (!(perm & (1 << bit))) continue; |
875 |
|
/* Print "read/write" instead of "read" and "write". */ |
876 |
|
if ((bit == TYPE_READ_ACL || bit == TYPE_WRITE_ACL) && (perm & (1 << TYPE_READ_WRITE_ACL))) continue; |
877 |
|
msg = sp_operation2keyword(bit); |
878 |
|
pos = head->read_avail; |
879 |
|
if (b && io_printf(head, "allow_%s @%s ", msg, ptr->u.group->group_name->name)) goto out; |
880 |
|
if (!b && io_printf(head, "allow_%s %s ", msg, ptr->u.filename->name)) goto out; |
881 |
|
if (DumpCondition(head, cond)) goto out; |
882 |
|
} |
883 |
|
head->read_bit = 0; |
884 |
|
return 1; |
885 |
|
out: |
886 |
|
head->read_bit = bit; |
887 |
|
head->read_avail = pos; |
888 |
|
return 0; |
889 |
|
} |
890 |
|
|
891 |
|
static bool print_double_path_acl(struct io_buffer *head, struct double_path_acl_record *ptr, const struct condition_list *cond) |
892 |
|
{ |
893 |
|
int pos; |
894 |
|
const bool b0 = ptr->u1_is_group, b1 = ptr->u2_is_group; |
895 |
|
const u8 perm = ptr->perm; |
896 |
|
u8 bit; |
897 |
|
for (bit = head->read_bit; bit < MAX_DOUBLE_PATH_OPERATION; bit++) { |
898 |
|
const char *msg; |
899 |
|
if (!(perm & (1 << bit))) continue; |
900 |
|
msg = dp_operation2keyword(bit); |
901 |
|
pos = head->read_avail; |
902 |
|
if (io_printf(head, "allow_%s ", msg)) goto out; |
903 |
|
if (b0 && io_printf(head, "@%s ", ptr->u1.group1->group_name->name)) goto out; |
904 |
|
if (!b0 && io_printf(head, "%s ", ptr->u1.filename1->name)) goto out; |
905 |
|
if (b1 && io_printf(head, "@%s", ptr->u2.group2->group_name->name)) goto out; |
906 |
|
if (!b1 && io_printf(head, "%s", ptr->u2.filename2->name)) goto out; |
907 |
|
if (DumpCondition(head, cond)) goto out; |
908 |
|
} |
909 |
|
head->read_bit = 0; |
910 |
|
return 1; |
911 |
|
out: |
912 |
|
head->read_bit = bit; |
913 |
|
head->read_avail = pos; |
914 |
|
return 0; |
915 |
|
} |
916 |
|
|
917 |
|
static bool print_argv0_acl(struct io_buffer *head, struct argv0_acl_record *ptr, const struct condition_list *cond) |
918 |
|
{ |
919 |
|
int pos = head->read_avail; |
920 |
|
if (io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
921 |
|
ptr->filename->name, ptr->argv0->name)) goto out; |
922 |
|
if (DumpCondition(head, cond)) goto out; |
923 |
|
return 1; |
924 |
|
out: |
925 |
|
head->read_avail = pos; |
926 |
|
return 0; |
927 |
|
} |
928 |
|
|
929 |
|
static bool print_env_acl(struct io_buffer *head, struct env_acl_record *ptr, const struct condition_list *cond) |
930 |
|
{ |
931 |
|
int pos = head->read_avail; |
932 |
|
if (io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr->env->name)) goto out; |
933 |
|
if (DumpCondition(head, cond)) goto out; |
934 |
|
return 1; |
935 |
|
out: |
936 |
|
head->read_avail = pos; |
937 |
|
return 0; |
938 |
|
} |
939 |
|
|
940 |
|
static bool print_capability_acl(struct io_buffer *head, struct capability_acl_record *ptr, const struct condition_list *cond) |
941 |
|
{ |
942 |
|
int pos = head->read_avail; |
943 |
|
if (io_printf(head, KEYWORD_ALLOW_CAPABILITY "%s", cap_operation2keyword(ptr->operation))) goto out; |
944 |
|
if (DumpCondition(head, cond)) goto out; |
945 |
|
return 1; |
946 |
|
out: |
947 |
|
head->read_avail = pos; |
948 |
|
return 0; |
949 |
|
} |
950 |
|
|
951 |
|
static bool print_network_acl(struct io_buffer *head, struct ip_network_acl_record *ptr, const struct condition_list *cond) |
952 |
|
{ |
953 |
|
int pos = head->read_avail; |
954 |
|
if (io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", net_operation2keyword(ptr->operation_type))) goto out; |
955 |
|
switch (ptr->record_type) { |
956 |
|
case IP_RECORD_TYPE_ADDRESS_GROUP: |
957 |
|
if (io_printf(head, "@%s", ptr->u.group->group_name->name)) goto out; |
958 |
|
break; |
959 |
|
case IP_RECORD_TYPE_IPv4: |
960 |
|
{ |
961 |
|
const u32 min_address = ptr->u.ipv4.min, max_address = ptr->u.ipv4.max; |
962 |
|
if (io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) goto out; |
963 |
|
if (min_address != max_address && io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) goto out; |
964 |
|
} |
965 |
|
break; |
966 |
|
case IP_RECORD_TYPE_IPv6: |
967 |
|
{ |
968 |
|
char buf[64]; |
969 |
|
const struct in6_addr *min_address = ptr->u.ipv6.min, *max_address = ptr->u.ipv6.max; |
970 |
|
print_ipv6(buf, sizeof(buf), min_address); |
971 |
|
if (io_printf(head, "%s", buf)) goto out; |
972 |
|
if (min_address != max_address) { |
973 |
|
print_ipv6(buf, sizeof(buf), max_address); |
974 |
|
if (io_printf(head, "-%s", buf)) goto out; |
975 |
|
} |
976 |
|
} |
977 |
|
break; |
978 |
|
} |
979 |
|
{ |
980 |
|
const u16 min_port = ptr->min_port, max_port = ptr->max_port; |
981 |
|
if (io_printf(head, " %u", min_port)) goto out; |
982 |
|
if (min_port != max_port && io_printf(head, "-%u", max_port)) goto out; |
983 |
|
} |
984 |
|
if (DumpCondition(head, cond)) goto out; |
985 |
|
return 1; |
986 |
|
out: |
987 |
|
head->read_avail = pos; |
988 |
|
return 0; |
989 |
|
} |
990 |
|
|
991 |
|
static bool print_signal_acl(struct io_buffer *head, struct signal_acl_record *ptr, const struct condition_list *cond) |
992 |
|
{ |
993 |
|
int pos = head->read_avail; |
994 |
|
if (io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", ptr->sig, ptr->domainname->name)) goto out; |
995 |
|
if (DumpCondition(head, cond)) goto out; |
996 |
|
return 1; |
997 |
|
out: |
998 |
|
head->read_avail = pos; |
999 |
|
return 0; |
1000 |
|
} |
1001 |
|
|
1002 |
static int ReadDomainPolicy(struct io_buffer *head) |
static int ReadDomainPolicy(struct io_buffer *head) |
1003 |
{ |
{ |
1004 |
struct list1_head *dpos; |
struct list1_head *dpos; |
1005 |
struct list1_head *apos; |
struct list1_head *apos; |
1006 |
if (head->read_eof) return 0; |
if (head->read_eof) return 0; |
1007 |
if (head->read_step == 0) { |
if (head->read_step == 0) { |
1008 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1009 |
head->read_step = 1; |
head->read_step = 1; |
1010 |
} |
} |
1011 |
list1_for_each_cookie(dpos, head->read_var1, &domain_list) { |
list1_for_each_cookie(dpos, head->read_var1, &domain_list) { |
1019 |
if (head->read_step == 3) goto tail_mark; |
if (head->read_step == 3) goto tail_mark; |
1020 |
list1_for_each_cookie(apos, head->read_var2, &domain->acl_info_list) { |
list1_for_each_cookie(apos, head->read_var2, &domain->acl_info_list) { |
1021 |
struct acl_info *ptr; |
struct acl_info *ptr; |
|
int pos; |
|
1022 |
u8 acl_type; |
u8 acl_type; |
1023 |
|
const struct condition_list *cond; |
1024 |
ptr = list1_entry(apos, struct acl_info, list); |
ptr = list1_entry(apos, struct acl_info, list); |
1025 |
if (ptr->is_deleted) continue; |
cond = GetConditionPart(ptr); |
1026 |
pos = head->read_avail; |
acl_type = ptr->type & ~ACL_WITH_CONDITION; |
1027 |
acl_type = ptr->type; |
if (acl_type & ACL_DELETED) { |
1028 |
if (acl_type == TYPE_SINGLE_PATH_ACL) { |
/* Deleted entry. */ |
1029 |
struct single_acl_record *ptr2 = container_of(ptr, struct single_acl_record, head); |
} else if (acl_type == TYPE_SINGLE_PATH_ACL) { |
1030 |
const bool b = ptr2->u_is_group; |
if (!print_single_path_acl(head, container_of(ptr, struct single_path_acl_record, head), cond)) return 0; |
|
const u16 perm = ptr2->perm; |
|
|
u8 bit = head->read_bit; |
|
|
while (bit < MAX_SINGLE_PATH_OPERATION) { |
|
|
if (perm & (1 << bit)) { |
|
|
pos = head->read_avail; |
|
|
if (io_printf(head, "allow_%s %s%s ", sp_operation2keyword(bit), |
|
|
b ? "@" : "", b ? ptr2->u.group->group_name->name : ptr2->u.filename->name) |
|
|
|| DumpCondition(head, ptr->cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
bit++; |
|
|
} |
|
|
head->read_bit = 0; |
|
1031 |
} else if (acl_type == TYPE_DOUBLE_PATH_ACL) { |
} else if (acl_type == TYPE_DOUBLE_PATH_ACL) { |
1032 |
struct double_acl_record *ptr2 = container_of(ptr, struct double_acl_record, head); |
if (!print_double_path_acl(head, container_of(ptr, struct double_path_acl_record, head), cond)) return 0; |
|
const bool b0 = ptr2->u1_is_group, b1 = ptr2->u2_is_group; |
|
|
const u8 perm = ptr2->perm; |
|
|
u8 bit = head->read_bit; |
|
|
while (bit < MAX_DOUBLE_PATH_OPERATION) { |
|
|
if (perm & (1 << bit)) { |
|
|
pos = head->read_avail; |
|
|
if (io_printf(head, "allow_%s %s%s %s%s", dp_operation2keyword(bit), |
|
|
b0 ? "@" : "", b0 ? ptr2->u1.group1->group_name->name : ptr2->u1.filename1->name, |
|
|
b1 ? "@" : "", b1 ? ptr2->u2.group2->group_name->name : ptr2->u2.filename2->name) |
|
|
|| DumpCondition(head, ptr->cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
bit++; |
|
|
} |
|
|
head->read_bit = 0; |
|
1033 |
} else if (acl_type == TYPE_ARGV0_ACL) { |
} else if (acl_type == TYPE_ARGV0_ACL) { |
1034 |
struct argv0_acl_record *ptr2 = container_of(ptr, struct argv0_acl_record, head); |
if (!print_argv0_acl(head, container_of(ptr, struct argv0_acl_record, head), cond)) return 0; |
|
if (io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
|
|
ptr2->filename->name, ptr2->argv0->name)) goto print_acl_rollback; |
|
1035 |
} else if (acl_type == TYPE_ENV_ACL) { |
} else if (acl_type == TYPE_ENV_ACL) { |
1036 |
struct env_acl_record *ptr2 = container_of(ptr, struct env_acl_record, head); |
if (!print_env_acl(head, container_of(ptr, struct env_acl_record, head), cond)) return 0; |
|
if (io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr2->env->name)) goto print_acl_rollback; |
|
1037 |
} else if (acl_type == TYPE_CAPABILITY_ACL) { |
} else if (acl_type == TYPE_CAPABILITY_ACL) { |
1038 |
struct capability_acl_record *ptr2 = container_of(ptr, struct capability_acl_record, head); |
if (!print_capability_acl(head, container_of(ptr, struct capability_acl_record, head), cond)) return 0; |
|
const u32 capability = ptr2->capability; |
|
|
u8 bit = head->read_bit; |
|
|
while (bit < TOMOYO_MAX_CAPABILITY_INDEX) { |
|
|
if (capability & (1 << bit)) { |
|
|
pos = head->read_avail; |
|
|
if (io_printf(head, KEYWORD_ALLOW_CAPABILITY "%s", cap_operation2keyword(bit)) || |
|
|
DumpCondition(head, ptr->cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
bit++; |
|
|
} |
|
|
head->read_bit = 0; |
|
1039 |
} else if (acl_type == TYPE_IP_NETWORK_ACL) { |
} else if (acl_type == TYPE_IP_NETWORK_ACL) { |
1040 |
struct ip_network_acl_record *ptr2 = container_of(ptr, struct ip_network_acl_record, head); |
if (!print_network_acl(head, container_of(ptr, struct ip_network_acl_record, head), cond)) return 0; |
|
if (io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", net_operation2keyword(ptr2->operation_type))) goto print_acl_rollback; |
|
|
switch (ptr2->record_type) { |
|
|
case IP_RECORD_TYPE_ADDRESS_GROUP: |
|
|
if (io_printf(head, "@%s", ptr2->u.group->group_name->name)) goto print_acl_rollback; |
|
|
break; |
|
|
case IP_RECORD_TYPE_IPv4: |
|
|
{ |
|
|
const u32 min_address = ptr2->u.ipv4.min, max_address = ptr2->u.ipv4.max; |
|
|
if (io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) goto print_acl_rollback; |
|
|
if (min_address != max_address && io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) goto print_acl_rollback; |
|
|
} |
|
|
break; |
|
|
case IP_RECORD_TYPE_IPv6: |
|
|
{ |
|
|
char buf[64]; |
|
|
const struct in6_addr *min_address = ptr2->u.ipv6.min, *max_address = ptr2->u.ipv6.max; |
|
|
print_ipv6(buf, sizeof(buf), min_address); |
|
|
if (io_printf(head, "%s", buf)) goto print_acl_rollback; |
|
|
if (min_address != max_address) { |
|
|
print_ipv6(buf, sizeof(buf), max_address); |
|
|
if (io_printf(head, "-%s", buf)) goto print_acl_rollback; |
|
|
} |
|
|
} |
|
|
break; |
|
|
} |
|
|
{ |
|
|
const u16 min_port = ptr2->min_port, max_port = ptr2->max_port; |
|
|
if (io_printf(head, " %u", min_port)) goto print_acl_rollback; |
|
|
if (min_port != max_port && io_printf(head, "-%u", max_port)) goto print_acl_rollback; |
|
|
} |
|
1041 |
} else if (acl_type == TYPE_SIGNAL_ACL) { |
} else if (acl_type == TYPE_SIGNAL_ACL) { |
1042 |
struct signal_acl_record *ptr2 = container_of(ptr, struct signal_acl_record, head); |
if (!print_signal_acl(head, container_of(ptr, struct signal_acl_record, head), cond)) return 0; |
|
if (io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", ptr2->sig, ptr2->domainname->name)) goto print_acl_rollback; |
|
1043 |
} else { |
} else { |
1044 |
BUG(); |
BUG(); |
1045 |
} |
} |
|
if (acl_type != TYPE_SINGLE_PATH_ACL && acl_type != TYPE_DOUBLE_PATH_ACL && acl_type != TYPE_CAPABILITY_ACL && DumpCondition(head, ptr->cond)) { |
|
|
print_acl_rollback: ; |
|
|
head->read_avail = pos; |
|
|
return 0; |
|
|
} |
|
1046 |
} |
} |
1047 |
head->read_step = 3; |
head->read_step = 3; |
1048 |
tail_mark: ; |
tail_mark: ; |
1061 |
char *cp = strchr(data, ' '); |
char *cp = strchr(data, ' '); |
1062 |
struct domain_info *domain; |
struct domain_info *domain; |
1063 |
unsigned int profile; |
unsigned int profile; |
1064 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1065 |
if (!cp) return -EINVAL; |
if (!cp) return -EINVAL; |
1066 |
*cp = '\0'; |
*cp = '\0'; |
1067 |
domain = FindDomain(cp + 1); |
domain = FindDomain(cp + 1); |
1075 |
{ |
{ |
1076 |
struct list1_head *pos; |
struct list1_head *pos; |
1077 |
if (head->read_eof) return 0; |
if (head->read_eof) return 0; |
1078 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1079 |
list1_for_each_cookie(pos, head->read_var1, &domain_list) { |
list1_for_each_cookie(pos, head->read_var1, &domain_list) { |
1080 |
struct domain_info *domain; |
struct domain_info *domain; |
1081 |
domain = list1_entry(pos, struct domain_info, list); |
domain = list1_entry(pos, struct domain_info, list); |
1119 |
{ |
{ |
1120 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1121 |
bool is_delete = 0; |
bool is_delete = 0; |
1122 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1123 |
UpdateCounter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY); |
UpdateCounter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY); |
1124 |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
1125 |
data += KEYWORD_DELETE_LEN; |
data += KEYWORD_DELETE_LEN; |
1158 |
if (!head->read_eof) { |
if (!head->read_eof) { |
1159 |
switch (head->read_step) { |
switch (head->read_step) { |
1160 |
case 0: |
case 0: |
1161 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1162 |
head->read_var2 = NULL; head->read_step = 1; |
head->read_var2 = NULL; head->read_step = 1; |
1163 |
case 1: |
case 1: |
1164 |
if (ReadDomainKeeperPolicy(head)) break; |
if (ReadDomainKeeperPolicy(head)) break; |
1208 |
{ |
{ |
1209 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1210 |
bool is_delete = 0; |
bool is_delete = 0; |
1211 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1212 |
UpdateCounter(CCS_UPDATES_COUNTER_SYSTEM_POLICY); |
UpdateCounter(CCS_UPDATES_COUNTER_SYSTEM_POLICY); |
1213 |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
1214 |
data += KEYWORD_DELETE_LEN; |
data += KEYWORD_DELETE_LEN; |
1232 |
if (!head->read_eof) { |
if (!head->read_eof) { |
1233 |
switch (head->read_step) { |
switch (head->read_step) { |
1234 |
case 0: |
case 0: |
1235 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1236 |
head->read_var2 = NULL; head->read_step = 1; |
head->read_var2 = NULL; head->read_step = 1; |
1237 |
case 1: |
case 1: |
1238 |
if (ReadMountPolicy(head)) break; |
if (ReadMountPolicy(head)) break; |
1317 |
} |
} |
1318 |
} |
} |
1319 |
#ifdef CONFIG_SAKURA |
#ifdef CONFIG_SAKURA |
1320 |
printk("SAKURA: 1.5.3-pre 2008/01/02\n"); |
printk("SAKURA: 1.6.0-pre 2008/02/05\n"); |
1321 |
#endif |
#endif |
1322 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
1323 |
printk("TOMOYO: 1.5.3-pre 2008/01/02\n"); |
printk("TOMOYO: 1.6.0-pre 2008/02/05\n"); |
1324 |
#endif |
#endif |
|
//if (!profile_loaded) panic("No profiles loaded. Run policy loader using 'init=' option.\n"); |
|
1325 |
printk("Mandatory Access Control activated.\n"); |
printk("Mandatory Access Control activated.\n"); |
1326 |
sbin_init_started = 1; |
sbin_init_started = 1; |
1327 |
ccs_log_level = KERN_WARNING; |
ccs_log_level = KERN_WARNING; |
1571 |
static int ReadVersion(struct io_buffer *head) |
static int ReadVersion(struct io_buffer *head) |
1572 |
{ |
{ |
1573 |
if (!head->read_eof) { |
if (!head->read_eof) { |
1574 |
if (io_printf(head, "1.5.3-pre") == 0) head->read_eof = 1; |
if (io_printf(head, "1.6.0-pre") == 0) head->read_eof = 1; |
1575 |
} |
} |
1576 |
return 0; |
return 0; |
1577 |
} |
} |
1676 |
return -ENOMEM; |
return -ENOMEM; |
1677 |
} |
} |
1678 |
} |
} |
1679 |
|
{ /* Set owner of this entry. */ |
1680 |
|
struct inode *inode = file->f_dentry->d_inode; |
1681 |
|
head->uid = inode ? inode->i_uid : 0; |
1682 |
|
head->gid = inode ? inode->i_gid : 0; |
1683 |
|
} |
1684 |
file->private_data = head; |
file->private_data = head; |
1685 |
if (type == CCS_SELFDOMAIN) CCS_ReadControl(file, NULL, 0); |
if (type == CCS_SELFDOMAIN) CCS_ReadControl(file, NULL, 0); |
1686 |
else if (head->write == WriteAnswer) atomic_inc(&queryd_watcher); |
else if (head->write == WriteAnswer) atomic_inc(&queryd_watcher); |
1728 |
char *cp0 = head->write_buf; |
char *cp0 = head->write_buf; |
1729 |
if (!head->write) return -ENOSYS; |
if (!head->write) return -ENOSYS; |
1730 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) return -EFAULT; |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) return -EFAULT; |
1731 |
if (!isRoot()) return -EPERM; |
if (!isRoot(head)) return -EPERM; |
1732 |
if (head->write != WritePID && !IsPolicyManager()) { |
if (head->write != WritePID && !IsPolicyManager()) { |
1733 |
return -EPERM; /* Forbid updating policies for non manager programs. */ |
return -EPERM; /* Forbid updating policies for non manager programs. */ |
1734 |
} |
} |
1766 |
file->private_data = NULL; |
file->private_data = NULL; |
1767 |
return 0; |
return 0; |
1768 |
} |
} |
1769 |
|
|
1770 |
|
void *alloc_acl_element(const u8 acl_type, const struct condition_list *condition) |
1771 |
|
{ |
1772 |
|
int len; |
1773 |
|
struct acl_info *ptr; |
1774 |
|
switch (acl_type) { |
1775 |
|
case TYPE_SINGLE_PATH_ACL: |
1776 |
|
len = sizeof(struct single_path_acl_record); |
1777 |
|
break; |
1778 |
|
case TYPE_DOUBLE_PATH_ACL: |
1779 |
|
len = sizeof(struct double_path_acl_record); |
1780 |
|
break; |
1781 |
|
case TYPE_ARGV0_ACL: |
1782 |
|
len = sizeof(struct argv0_acl_record); |
1783 |
|
break; |
1784 |
|
case TYPE_ENV_ACL: |
1785 |
|
len = sizeof(struct env_acl_record); |
1786 |
|
break; |
1787 |
|
case TYPE_CAPABILITY_ACL: |
1788 |
|
len = sizeof(struct capability_acl_record); |
1789 |
|
break; |
1790 |
|
case TYPE_IP_NETWORK_ACL: |
1791 |
|
len = sizeof(struct ip_network_acl_record); |
1792 |
|
break; |
1793 |
|
case TYPE_SIGNAL_ACL: |
1794 |
|
len = sizeof(struct signal_acl_record); |
1795 |
|
break; |
1796 |
|
default: |
1797 |
|
return NULL; |
1798 |
|
} |
1799 |
|
if (!condition) len -= sizeof(ptr->cond); |
1800 |
|
ptr = alloc_element(len); |
1801 |
|
if (!ptr) return NULL; |
1802 |
|
if (condition) { |
1803 |
|
ptr->cond = condition; |
1804 |
|
ptr->type = acl_type | ACL_WITH_CONDITION; |
1805 |
|
return ptr; |
1806 |
|
} |
1807 |
|
ptr = (void *) (((u8 *) ptr) - sizeof(ptr->cond)); |
1808 |
|
ptr->type = acl_type; |
1809 |
|
return ptr; |
1810 |
|
} |
1811 |
|
|
1812 |
|
const struct condition_list *GetConditionPart(const struct acl_info *acl) |
1813 |
|
{ |
1814 |
|
return (acl->type & ACL_WITH_CONDITION) ? acl->cond : NULL; |
1815 |
|
} |