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.5.3-pre 2008/01/03 |
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. |
840 |
return -EINVAL; |
return -EINVAL; |
841 |
} |
} |
842 |
|
|
843 |
|
static bool print_single_path_acl(struct io_buffer *head, struct single_acl_record *ptr, const struct condition_list *cond) |
844 |
|
{ |
845 |
|
int pos; |
846 |
|
u8 bit; |
847 |
|
const bool b = ptr->u_is_group; |
848 |
|
const u16 perm = ptr->perm; |
849 |
|
for (bit = head->read_bit; bit < MAX_SINGLE_PATH_OPERATION; bit++) { |
850 |
|
const char *msg; |
851 |
|
if (!(perm & (1 << bit))) continue; |
852 |
|
/* Print "read/write" instead of "read" and "write". */ |
853 |
|
if ((bit == TYPE_READ_ACL || bit == TYPE_WRITE_ACL) && (perm & (1 << TYPE_READ_WRITE_ACL))) continue; |
854 |
|
msg = sp_operation2keyword(bit); |
855 |
|
pos = head->read_avail; |
856 |
|
if (b && io_printf(head, "allow_%s @%s ", msg, ptr->u.group->group_name->name)) goto out; |
857 |
|
if (!b && io_printf(head, "allow_%s %s ", msg, ptr->u.filename->name)) goto out; |
858 |
|
if (DumpCondition(head, cond)) goto out; |
859 |
|
} |
860 |
|
head->read_bit = 0; |
861 |
|
return 1; |
862 |
|
out: |
863 |
|
head->read_bit = bit; |
864 |
|
head->read_avail = pos; |
865 |
|
return 0; |
866 |
|
} |
867 |
|
|
868 |
|
static bool print_double_path_acl(struct io_buffer *head, struct double_acl_record *ptr, const struct condition_list *cond) |
869 |
|
{ |
870 |
|
int pos; |
871 |
|
const bool b0 = ptr->u1_is_group, b1 = ptr->u2_is_group; |
872 |
|
const u8 perm = ptr->perm; |
873 |
|
u8 bit; |
874 |
|
for (bit = head->read_bit; bit < MAX_DOUBLE_PATH_OPERATION; bit++) { |
875 |
|
const char *msg; |
876 |
|
if (!(perm & (1 << bit))) continue; |
877 |
|
msg = dp_operation2keyword(bit); |
878 |
|
pos = head->read_avail; |
879 |
|
if (io_printf(head, "allow_%s ", msg)) goto out; |
880 |
|
if (b0 && io_printf(head, "@%s", ptr->u1.group1->group_name->name)) goto out; |
881 |
|
if (!b0 && io_printf(head, "%s", ptr->u1.filename1->name)) goto out; |
882 |
|
if (b1 && io_printf(head, "@%s", ptr->u2.group2->group_name->name)) goto out; |
883 |
|
if (!b1 && io_printf(head, "%s", ptr->u2.filename2->name)) goto out; |
884 |
|
if (DumpCondition(head, cond)) goto out; |
885 |
|
} |
886 |
|
head->read_bit = 0; |
887 |
|
return 1; |
888 |
|
out: |
889 |
|
head->read_bit = bit; |
890 |
|
head->read_avail = pos; |
891 |
|
return 0; |
892 |
|
} |
893 |
|
|
894 |
|
static bool print_argv0_acl(struct io_buffer *head, struct argv0_acl_record *ptr, const struct condition_list *cond) |
895 |
|
{ |
896 |
|
int pos = head->read_avail; |
897 |
|
if (io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
898 |
|
ptr->filename->name, ptr->argv0->name)) goto out; |
899 |
|
if (DumpCondition(head, cond)) goto out; |
900 |
|
return 1; |
901 |
|
out: |
902 |
|
head->read_avail = pos; |
903 |
|
return 0; |
904 |
|
} |
905 |
|
|
906 |
|
static bool print_env_acl(struct io_buffer *head, struct env_acl_record *ptr, const struct condition_list *cond) |
907 |
|
{ |
908 |
|
int pos = head->read_avail; |
909 |
|
if (io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr->env->name)) goto out; |
910 |
|
if (DumpCondition(head, cond)) goto out; |
911 |
|
return 1; |
912 |
|
out: |
913 |
|
head->read_avail = pos; |
914 |
|
return 0; |
915 |
|
} |
916 |
|
|
917 |
|
static bool print_capability_acl(struct io_buffer *head, struct capability_acl_record *ptr, const struct condition_list *cond) |
918 |
|
{ |
919 |
|
int pos; |
920 |
|
const u32 capability = ptr->capability; |
921 |
|
u8 bit; |
922 |
|
for (bit = head->read_bit; bit < TOMOYO_MAX_CAPABILITY_INDEX; bit++) { |
923 |
|
if (!(capability & (1 << bit))) continue; |
924 |
|
pos = head->read_avail; |
925 |
|
if (io_printf(head, KEYWORD_ALLOW_CAPABILITY "%s", cap_operation2keyword(bit))) goto out; |
926 |
|
if (DumpCondition(head, cond)) goto out; |
927 |
|
} |
928 |
|
head->read_bit = 0; |
929 |
|
return 1; |
930 |
|
out: |
931 |
|
head->read_bit = bit; |
932 |
|
head->read_avail = pos; |
933 |
|
return 0; |
934 |
|
} |
935 |
|
|
936 |
|
static bool print_network_acl(struct io_buffer *head, struct ip_network_acl_record *ptr, const struct condition_list *cond) |
937 |
|
{ |
938 |
|
int pos = head->read_avail; |
939 |
|
if (io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", net_operation2keyword(ptr->operation_type))) goto out; |
940 |
|
switch (ptr->record_type) { |
941 |
|
case IP_RECORD_TYPE_ADDRESS_GROUP: |
942 |
|
if (io_printf(head, "@%s", ptr->u.group->group_name->name)) goto out; |
943 |
|
break; |
944 |
|
case IP_RECORD_TYPE_IPv4: |
945 |
|
{ |
946 |
|
const u32 min_address = ptr->u.ipv4.min, max_address = ptr->u.ipv4.max; |
947 |
|
if (io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) goto out; |
948 |
|
if (min_address != max_address && io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) goto out; |
949 |
|
} |
950 |
|
break; |
951 |
|
case IP_RECORD_TYPE_IPv6: |
952 |
|
{ |
953 |
|
char buf[64]; |
954 |
|
const struct in6_addr *min_address = ptr->u.ipv6.min, *max_address = ptr->u.ipv6.max; |
955 |
|
print_ipv6(buf, sizeof(buf), min_address); |
956 |
|
if (io_printf(head, "%s", buf)) goto out; |
957 |
|
if (min_address != max_address) { |
958 |
|
print_ipv6(buf, sizeof(buf), max_address); |
959 |
|
if (io_printf(head, "-%s", buf)) goto out; |
960 |
|
} |
961 |
|
} |
962 |
|
break; |
963 |
|
} |
964 |
|
{ |
965 |
|
const u16 min_port = ptr->min_port, max_port = ptr->max_port; |
966 |
|
if (io_printf(head, " %u", min_port)) goto out; |
967 |
|
if (min_port != max_port && io_printf(head, "-%u", max_port)) goto out; |
968 |
|
} |
969 |
|
if (DumpCondition(head, cond)) goto out; |
970 |
|
return 1; |
971 |
|
out: |
972 |
|
head->read_avail = pos; |
973 |
|
return 0; |
974 |
|
} |
975 |
|
|
976 |
|
static bool print_signal_acl(struct io_buffer *head, struct signal_acl_record *ptr, const struct condition_list *cond) |
977 |
|
{ |
978 |
|
int pos = head->read_avail; |
979 |
|
if (io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", ptr->sig, ptr->domainname->name)) goto out; |
980 |
|
if (DumpCondition(head, cond)) goto out; |
981 |
|
return 1; |
982 |
|
out: |
983 |
|
head->read_avail = pos; |
984 |
|
return 0; |
985 |
|
} |
986 |
|
|
987 |
static int ReadDomainPolicy(struct io_buffer *head) |
static int ReadDomainPolicy(struct io_buffer *head) |
988 |
{ |
{ |
989 |
struct list1_head *dpos; |
struct list1_head *dpos; |
1004 |
if (head->read_step == 3) goto tail_mark; |
if (head->read_step == 3) goto tail_mark; |
1005 |
list1_for_each_cookie(apos, head->read_var2, &domain->acl_info_list) { |
list1_for_each_cookie(apos, head->read_var2, &domain->acl_info_list) { |
1006 |
struct acl_info *ptr; |
struct acl_info *ptr; |
|
int pos; |
|
1007 |
u8 acl_type; |
u8 acl_type; |
1008 |
ptr = list1_entry(apos, struct acl_info, list); |
ptr = list1_entry(apos, struct acl_info, list); |
1009 |
if (ptr->is_deleted) continue; |
if (ptr->is_deleted) continue; |
|
pos = head->read_avail; |
|
1010 |
acl_type = ptr->type; |
acl_type = ptr->type; |
1011 |
if (acl_type == TYPE_SINGLE_PATH_ACL) { |
if (acl_type == TYPE_SINGLE_PATH_ACL) { |
1012 |
struct single_acl_record *ptr2 = container_of(ptr, struct single_acl_record, head); |
if (!print_single_path_acl(head, container_of(ptr, struct single_acl_record, head), NULL)) return 0; |
1013 |
const bool b = ptr2->u_is_group; |
} else if (acl_type == TYPE_SINGLE_PATH_ACL_WITH_CONDITION) { |
1014 |
const u16 perm = ptr2->perm; |
struct single_acl_record_with_condition *p; |
1015 |
u8 bit = head->read_bit; |
p = container_of(ptr, struct single_acl_record_with_condition, record.head); |
1016 |
while (bit < MAX_SINGLE_PATH_OPERATION) { |
BUG_ON(!p->condition); |
1017 |
if (perm & (1 << bit)) { |
if (!print_single_path_acl(head, &p->record, p->condition)) return 0; |
|
/* Print "read/write" instead of "read" and "write". */ |
|
|
if ((bit == TYPE_READ_ACL || bit == TYPE_WRITE_ACL) && (perm & (1 << TYPE_READ_WRITE_ACL))) { |
|
|
bit++; |
|
|
continue; |
|
|
} |
|
|
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; |
|
1018 |
} else if (acl_type == TYPE_DOUBLE_PATH_ACL) { |
} else if (acl_type == TYPE_DOUBLE_PATH_ACL) { |
1019 |
struct double_acl_record *ptr2 = container_of(ptr, struct double_acl_record, head); |
if (!print_double_path_acl(head, container_of(ptr, struct double_acl_record, head), NULL)) return 0; |
1020 |
const bool b0 = ptr2->u1_is_group, b1 = ptr2->u2_is_group; |
} else if (acl_type == TYPE_DOUBLE_PATH_ACL_WITH_CONDITION) { |
1021 |
const u8 perm = ptr2->perm; |
struct double_acl_record_with_condition *p; |
1022 |
u8 bit = head->read_bit; |
p = container_of(ptr, struct double_acl_record_with_condition, record.head); |
1023 |
while (bit < MAX_DOUBLE_PATH_OPERATION) { |
BUG_ON(!p->condition); |
1024 |
if (perm & (1 << bit)) { |
if (!print_double_path_acl(head, &p->record, p->condition)) return 0; |
|
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; |
|
1025 |
} else if (acl_type == TYPE_ARGV0_ACL) { |
} else if (acl_type == TYPE_ARGV0_ACL) { |
1026 |
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), NULL)) return 0; |
1027 |
if (io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
} else if (acl_type == TYPE_ARGV0_ACL_WITH_CONDITION) { |
1028 |
ptr2->filename->name, ptr2->argv0->name)) goto print_acl_rollback; |
struct argv0_acl_record_with_condition *p; |
1029 |
|
p = container_of(ptr, struct argv0_acl_record_with_condition, record.head); |
1030 |
|
BUG_ON(!p->condition); |
1031 |
|
if (!print_argv0_acl(head, &p->record, p->condition)) return 0; |
1032 |
} else if (acl_type == TYPE_ENV_ACL) { |
} else if (acl_type == TYPE_ENV_ACL) { |
1033 |
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), NULL)) return 0; |
1034 |
if (io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr2->env->name)) goto print_acl_rollback; |
} else if (acl_type == TYPE_ENV_ACL_WITH_CONDITION) { |
1035 |
|
struct env_acl_record_with_condition *p; |
1036 |
|
p = container_of(ptr, struct env_acl_record_with_condition, record.head); |
1037 |
|
BUG_ON(!p->condition); |
1038 |
|
if (!print_env_acl(head, &p->record, p->condition)) return 0; |
1039 |
} else if (acl_type == TYPE_CAPABILITY_ACL) { |
} else if (acl_type == TYPE_CAPABILITY_ACL) { |
1040 |
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), NULL)) return 0; |
1041 |
const u32 capability = ptr2->capability; |
} else if (acl_type == TYPE_CAPABILITY_ACL_WITH_CONDITION) { |
1042 |
u8 bit = head->read_bit; |
struct capability_acl_record_with_condition *p; |
1043 |
while (bit < TOMOYO_MAX_CAPABILITY_INDEX) { |
p = container_of(ptr, struct capability_acl_record_with_condition, record.head); |
1044 |
if (capability & (1 << bit)) { |
BUG_ON(!p->condition); |
1045 |
pos = head->read_avail; |
if (!print_capability_acl(head, &p->record, p->condition)) return 0; |
|
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; |
|
1046 |
} else if (acl_type == TYPE_IP_NETWORK_ACL) { |
} else if (acl_type == TYPE_IP_NETWORK_ACL) { |
1047 |
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), NULL)) return 0; |
1048 |
if (io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", net_operation2keyword(ptr2->operation_type))) goto print_acl_rollback; |
} else if (acl_type == TYPE_IP_NETWORK_ACL_WITH_CONDITION) { |
1049 |
switch (ptr2->record_type) { |
struct ip_network_acl_record_with_condition *p; |
1050 |
case IP_RECORD_TYPE_ADDRESS_GROUP: |
p = container_of(ptr, struct ip_network_acl_record_with_condition, record.head); |
1051 |
if (io_printf(head, "@%s", ptr2->u.group->group_name->name)) goto print_acl_rollback; |
BUG_ON(!p->condition); |
1052 |
break; |
if (!print_network_acl(head, &p->record, p->condition)) return 0; |
|
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; |
|
|
} |
|
1053 |
} else if (acl_type == TYPE_SIGNAL_ACL) { |
} else if (acl_type == TYPE_SIGNAL_ACL) { |
1054 |
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), NULL)) return 0; |
1055 |
if (io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", ptr2->sig, ptr2->domainname->name)) goto print_acl_rollback; |
} else if (acl_type == TYPE_SIGNAL_ACL_WITH_CONDITION) { |
1056 |
|
struct signal_acl_record_with_condition *p; |
1057 |
|
p = container_of(ptr, struct signal_acl_record_with_condition, record.head); |
1058 |
|
BUG_ON(!p->condition); |
1059 |
|
if (!print_signal_acl(head, &p->record, p->condition)) return 0; |
1060 |
} else { |
} else { |
1061 |
BUG(); |
BUG(); |
1062 |
} |
} |
|
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; |
|
|
} |
|
1063 |
} |
} |
1064 |
head->read_step = 3; |
head->read_step = 3; |
1065 |
tail_mark: ; |
tail_mark: ; |
1334 |
} |
} |
1335 |
} |
} |
1336 |
#ifdef CONFIG_SAKURA |
#ifdef CONFIG_SAKURA |
1337 |
printk("SAKURA: 1.5.3-pre 2008/01/02\n"); |
printk("SAKURA: 1.5.3-pre 2008/01/03\n"); |
1338 |
#endif |
#endif |
1339 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
1340 |
printk("TOMOYO: 1.5.3-pre 2008/01/02\n"); |
printk("TOMOYO: 1.5.3-pre 2008/01/03\n"); |
1341 |
#endif |
#endif |
1342 |
//if (!profile_loaded) panic("No profiles loaded. Run policy loader using 'init=' option.\n"); |
//if (!profile_loaded) panic("No profiles loaded. Run policy loader using 'init=' option.\n"); |
1343 |
printk("Mandatory Access Control activated.\n"); |
printk("Mandatory Access Control activated.\n"); |