1 // SPDX-License-Identifier: GPL-2.0 1 2 /* 3 * security/tomoyo/group.c 4 * 5 * Copyright (C) 2005-2011 NTT DATA CORPORATI 6 */ 7 8 #include <linux/slab.h> 9 #include <linux/rculist.h> 10 11 #include "common.h" 12 13 /** 14 * tomoyo_same_path_group - Check for duplicat 15 * 16 * @a: Pointer to "struct tomoyo_acl_head". 17 * @b: Pointer to "struct tomoyo_acl_head". 18 * 19 * Returns true if @a == @b, false otherwise. 20 */ 21 static bool tomoyo_same_path_group(const struc 22 const struc 23 { 24 return container_of(a, struct tomoyo_p 25 container_of(b, struct tomoyo_ 26 } 27 28 /** 29 * tomoyo_same_number_group - Check for duplic 30 * 31 * @a: Pointer to "struct tomoyo_acl_head". 32 * @b: Pointer to "struct tomoyo_acl_head". 33 * 34 * Returns true if @a == @b, false otherwise. 35 */ 36 static bool tomoyo_same_number_group(const str 37 const str 38 { 39 return !memcmp(&container_of(a, struct 40 ->number, 41 &container_of(b, struct 42 ->number, 43 sizeof(container_of(a, 44 ->number)); 45 } 46 47 /** 48 * tomoyo_same_address_group - Check for dupli 49 * 50 * @a: Pointer to "struct tomoyo_acl_head". 51 * @b: Pointer to "struct tomoyo_acl_head". 52 * 53 * Returns true if @a == @b, false otherwise. 54 */ 55 static bool tomoyo_same_address_group(const st 56 const st 57 { 58 const struct tomoyo_address_group *p1 59 60 const struct tomoyo_address_group *p2 61 62 63 return tomoyo_same_ipaddr_union(&p1->a 64 } 65 66 /** 67 * tomoyo_write_group - Write "struct tomoyo_p 68 * 69 * @param: Pointer to "struct tomoyo_acl_param 70 * @type: Type of this group. 71 * 72 * Returns 0 on success, negative value otherw 73 */ 74 int tomoyo_write_group(struct tomoyo_acl_param 75 { 76 struct tomoyo_group *group = tomoyo_ge 77 int error = -EINVAL; 78 79 if (!group) 80 return -ENOMEM; 81 param->list = &group->member_list; 82 if (type == TOMOYO_PATH_GROUP) { 83 struct tomoyo_path_group e = { 84 85 e.member_name = tomoyo_get_nam 86 if (!e.member_name) { 87 error = -ENOMEM; 88 goto out; 89 } 90 error = tomoyo_update_policy(& 91 tomo 92 tomoyo_put_name(e.member_name) 93 } else if (type == TOMOYO_NUMBER_GROUP 94 struct tomoyo_number_group e = 95 96 if (param->data[0] == '@' || 97 !tomoyo_parse_number_union 98 goto out; 99 error = tomoyo_update_policy(& 100 tomo 101 /* 102 * tomoyo_put_number_union() i 103 * param->data[0] != '@'. 104 */ 105 } else { 106 struct tomoyo_address_group e 107 108 if (param->data[0] == '@' || 109 !tomoyo_parse_ipaddr_union 110 goto out; 111 error = tomoyo_update_policy(& 112 t 113 } 114 out: 115 tomoyo_put_group(group); 116 return error; 117 } 118 119 /** 120 * tomoyo_path_matches_group - Check whether t 121 * 122 * @pathname: The name of pathname. 123 * @group: Pointer to "struct tomoyo_path_g 124 * 125 * Returns matched member's pathname if @pathn 126 * NULL otherwise. 127 * 128 * Caller holds tomoyo_read_lock(). 129 */ 130 const struct tomoyo_path_info * 131 tomoyo_path_matches_group(const struct tomoyo_ 132 const struct tomoyo_ 133 { 134 struct tomoyo_path_group *member; 135 136 list_for_each_entry_rcu(member, &group 137 srcu_read_lock 138 if (member->head.is_deleted) 139 continue; 140 if (!tomoyo_path_matches_patte 141 continue; 142 return member->member_name; 143 } 144 return NULL; 145 } 146 147 /** 148 * tomoyo_number_matches_group - Check whether 149 * 150 * @min: Min number. 151 * @max: Max number. 152 * @group: Pointer to "struct tomoyo_number_gr 153 * 154 * Returns true if @min and @max partially ove 155 * 156 * Caller holds tomoyo_read_lock(). 157 */ 158 bool tomoyo_number_matches_group(const unsigne 159 const unsigne 160 const struct 161 { 162 struct tomoyo_number_group *member; 163 bool matched = false; 164 165 list_for_each_entry_rcu(member, &group 166 srcu_read_lock 167 if (member->head.is_deleted) 168 continue; 169 if (min > member->number.value 170 max < member->number.value 171 continue; 172 matched = true; 173 break; 174 } 175 return matched; 176 } 177 178 /** 179 * tomoyo_address_matches_group - Check whethe 180 * 181 * @is_ipv6: True if @address is an IPv6 addre 182 * @address: An IPv4 or IPv6 address. 183 * @group: Pointer to "struct tomoyo_address 184 * 185 * Returns true if @address matches addresses 186 * 187 * Caller holds tomoyo_read_lock(). 188 */ 189 bool tomoyo_address_matches_group(const bool i 190 const struct 191 { 192 struct tomoyo_address_group *member; 193 bool matched = false; 194 const u8 size = is_ipv6 ? 16 : 4; 195 196 list_for_each_entry_rcu(member, &group 197 srcu_read_lock 198 if (member->head.is_deleted) 199 continue; 200 if (member->address.is_ipv6 != 201 continue; 202 if (memcmp(&member->address.ip 203 memcmp(address, &member->a 204 continue; 205 matched = true; 206 break; 207 } 208 return matched; 209 } 210
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.