Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 2 | /* |
| 3 | * NetLabel Domain Hash Table |
| 4 | * |
| 5 | * This file manages the domain hash table that NetLabel uses to determine |
| 6 | * which network labeling protocol to use for a given domain. The NetLabel |
| 7 | * system manages static and dynamic label mappings for network protocols such |
| 8 | * as CIPSO and RIPSO. |
| 9 | * |
Paul Moore | 82c21bf | 2011-08-01 11:10:33 +0000 | [diff] [blame] | 10 | * Author: Paul Moore <paul@paul-moore.com> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 14 | * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008 |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/types.h> |
Franck Bui-Huu | 8252474 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 18 | #include <linux/rculist.h> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 19 | #include <linux/skbuff.h> |
| 20 | #include <linux/spinlock.h> |
| 21 | #include <linux/string.h> |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 22 | #include <linux/audit.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 24 | #include <net/netlabel.h> |
| 25 | #include <net/cipso_ipv4.h> |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 26 | #include <net/calipso.h> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 27 | #include <asm/bug.h> |
| 28 | |
| 29 | #include "netlabel_mgmt.h" |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 30 | #include "netlabel_addrlist.h" |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 31 | #include "netlabel_calipso.h" |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 32 | #include "netlabel_domainhash.h" |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 33 | #include "netlabel_user.h" |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 34 | |
| 35 | struct netlbl_domhsh_tbl { |
| 36 | struct list_head *tbl; |
| 37 | u32 size; |
| 38 | }; |
| 39 | |
| 40 | /* Domain hash table */ |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 41 | /* updates should be so rare that having one spinlock for the entire hash table |
| 42 | * should be okay */ |
Adrian Bunk | 8ce11e6 | 2006-08-07 21:50:48 -0700 | [diff] [blame] | 43 | static DEFINE_SPINLOCK(netlbl_domhsh_lock); |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 44 | #define netlbl_domhsh_rcu_deref(p) \ |
Michal Hocko | d8bf4ca | 2011-07-08 14:39:41 +0200 | [diff] [blame] | 45 | rcu_dereference_check(p, lockdep_is_held(&netlbl_domhsh_lock)) |
Huw Davies | 96a8f7f | 2016-06-27 15:02:45 -0400 | [diff] [blame] | 46 | static struct netlbl_domhsh_tbl __rcu *netlbl_domhsh; |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 47 | static struct netlbl_dom_map __rcu *netlbl_domhsh_def_ipv4; |
| 48 | static struct netlbl_dom_map __rcu *netlbl_domhsh_def_ipv6; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Domain Hash Table Helper Functions |
| 52 | */ |
| 53 | |
| 54 | /** |
| 55 | * netlbl_domhsh_free_entry - Frees a domain hash table entry |
| 56 | * @entry: the entry's RCU field |
| 57 | * |
| 58 | * Description: |
| 59 | * This function is designed to be used as a callback to the call_rcu() |
| 60 | * function so that the memory allocated to a hash table entry can be released |
| 61 | * safely. |
| 62 | * |
| 63 | */ |
| 64 | static void netlbl_domhsh_free_entry(struct rcu_head *entry) |
| 65 | { |
| 66 | struct netlbl_dom_map *ptr; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 67 | struct netlbl_af4list *iter4; |
| 68 | struct netlbl_af4list *tmp4; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 69 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 70 | struct netlbl_af6list *iter6; |
| 71 | struct netlbl_af6list *tmp6; |
| 72 | #endif /* IPv6 */ |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 73 | |
| 74 | ptr = container_of(entry, struct netlbl_dom_map, rcu); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 75 | if (ptr->def.type == NETLBL_NLTYPE_ADDRSELECT) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 76 | netlbl_af4list_foreach_safe(iter4, tmp4, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 77 | &ptr->def.addrsel->list4) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 78 | netlbl_af4list_remove_entry(iter4); |
| 79 | kfree(netlbl_domhsh_addr4_entry(iter4)); |
| 80 | } |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 81 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 82 | netlbl_af6list_foreach_safe(iter6, tmp6, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 83 | &ptr->def.addrsel->list6) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 84 | netlbl_af6list_remove_entry(iter6); |
| 85 | kfree(netlbl_domhsh_addr6_entry(iter6)); |
| 86 | } |
| 87 | #endif /* IPv6 */ |
| 88 | } |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 89 | kfree(ptr->domain); |
| 90 | kfree(ptr); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * netlbl_domhsh_hash - Hashing function for the domain hash table |
| 95 | * @domain: the domain name to hash |
| 96 | * |
| 97 | * Description: |
| 98 | * This is the hashing function for the domain hash table, it returns the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 99 | * correct bucket number for the domain. The caller is responsible for |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 100 | * ensuring that the hash table is protected with either a RCU read lock or the |
| 101 | * hash table lock. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 102 | * |
| 103 | */ |
| 104 | static u32 netlbl_domhsh_hash(const char *key) |
| 105 | { |
| 106 | u32 iter; |
| 107 | u32 val; |
| 108 | u32 len; |
| 109 | |
| 110 | /* This is taken (with slight modification) from |
| 111 | * security/selinux/ss/symtab.c:symhash() */ |
| 112 | |
| 113 | for (iter = 0, val = 0, len = strlen(key); iter < len; iter++) |
| 114 | val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter]; |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 115 | return val & (netlbl_domhsh_rcu_deref(netlbl_domhsh)->size - 1); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 118 | static bool netlbl_family_match(u16 f1, u16 f2) |
| 119 | { |
| 120 | return (f1 == f2) || (f1 == AF_UNSPEC) || (f2 == AF_UNSPEC); |
| 121 | } |
| 122 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 123 | /** |
| 124 | * netlbl_domhsh_search - Search for a domain entry |
| 125 | * @domain: the domain |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 126 | * @family: the address family |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 127 | * |
| 128 | * Description: |
| 129 | * Searches the domain hash table and returns a pointer to the hash table |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 130 | * entry if found, otherwise NULL is returned. @family may be %AF_UNSPEC |
| 131 | * which matches any address family entries. The caller is responsible for |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 132 | * ensuring that the hash table is protected with either a RCU read lock or the |
| 133 | * hash table lock. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 134 | * |
| 135 | */ |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 136 | static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, |
| 137 | u16 family) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 138 | { |
| 139 | u32 bkt; |
Paul Moore | 5619670 | 2008-10-10 10:16:29 -0400 | [diff] [blame] | 140 | struct list_head *bkt_list; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 141 | struct netlbl_dom_map *iter; |
| 142 | |
| 143 | if (domain != NULL) { |
| 144 | bkt = netlbl_domhsh_hash(domain); |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 145 | bkt_list = &netlbl_domhsh_rcu_deref(netlbl_domhsh)->tbl[bkt]; |
Madhuparna Bhowmik | 9facfdb | 2020-02-19 00:11:32 +0530 | [diff] [blame] | 146 | list_for_each_entry_rcu(iter, bkt_list, list, |
| 147 | lockdep_is_held(&netlbl_domhsh_lock)) |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 148 | if (iter->valid && |
| 149 | netlbl_family_match(iter->family, family) && |
| 150 | strcmp(iter->domain, domain) == 0) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 151 | return iter; |
| 152 | } |
| 153 | |
Paul Moore | b64397e | 2008-01-29 08:37:54 -0500 | [diff] [blame] | 154 | return NULL; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * netlbl_domhsh_search_def - Search for a domain entry |
| 159 | * @domain: the domain |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 160 | * @family: the address family |
Paul Moore | b64397e | 2008-01-29 08:37:54 -0500 | [diff] [blame] | 161 | * |
| 162 | * Description: |
| 163 | * Searches the domain hash table and returns a pointer to the hash table |
| 164 | * entry if an exact match is found, if an exact match is not present in the |
| 165 | * hash table then the default entry is returned if valid otherwise NULL is |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 166 | * returned. @family may be %AF_UNSPEC which matches any address family |
| 167 | * entries. The caller is responsible ensuring that the hash table is |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 168 | * protected with either a RCU read lock or the hash table lock. |
Paul Moore | b64397e | 2008-01-29 08:37:54 -0500 | [diff] [blame] | 169 | * |
| 170 | */ |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 171 | static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain, |
| 172 | u16 family) |
Paul Moore | b64397e | 2008-01-29 08:37:54 -0500 | [diff] [blame] | 173 | { |
| 174 | struct netlbl_dom_map *entry; |
| 175 | |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 176 | entry = netlbl_domhsh_search(domain, family); |
| 177 | if (entry != NULL) |
| 178 | return entry; |
| 179 | if (family == AF_INET || family == AF_UNSPEC) { |
| 180 | entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def_ipv4); |
| 181 | if (entry != NULL && entry->valid) |
| 182 | return entry; |
| 183 | } |
| 184 | if (family == AF_INET6 || family == AF_UNSPEC) { |
| 185 | entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def_ipv6); |
| 186 | if (entry != NULL && entry->valid) |
| 187 | return entry; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 190 | return NULL; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 193 | /** |
| 194 | * netlbl_domhsh_audit_add - Generate an audit entry for an add event |
| 195 | * @entry: the entry being added |
| 196 | * @addr4: the IPv4 address information |
| 197 | * @addr6: the IPv6 address information |
| 198 | * @result: the result code |
| 199 | * @audit_info: NetLabel audit information |
| 200 | * |
| 201 | * Description: |
| 202 | * Generate an audit record for adding a new NetLabel/LSM mapping entry with |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 203 | * the given information. Caller is responsible for holding the necessary |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 204 | * locks. |
| 205 | * |
| 206 | */ |
| 207 | static void netlbl_domhsh_audit_add(struct netlbl_dom_map *entry, |
| 208 | struct netlbl_af4list *addr4, |
| 209 | struct netlbl_af6list *addr6, |
| 210 | int result, |
| 211 | struct netlbl_audit *audit_info) |
| 212 | { |
| 213 | struct audit_buffer *audit_buf; |
| 214 | struct cipso_v4_doi *cipsov4 = NULL; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 215 | struct calipso_doi *calipso = NULL; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 216 | u32 type; |
| 217 | |
| 218 | audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_ADD, audit_info); |
| 219 | if (audit_buf != NULL) { |
| 220 | audit_log_format(audit_buf, " nlbl_domain=%s", |
| 221 | entry->domain ? entry->domain : "(default)"); |
| 222 | if (addr4 != NULL) { |
| 223 | struct netlbl_domaddr4_map *map4; |
| 224 | map4 = netlbl_domhsh_addr4_entry(addr4); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 225 | type = map4->def.type; |
| 226 | cipsov4 = map4->def.cipso; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 227 | netlbl_af4list_audit_addr(audit_buf, 0, NULL, |
| 228 | addr4->addr, addr4->mask); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 229 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 230 | } else if (addr6 != NULL) { |
| 231 | struct netlbl_domaddr6_map *map6; |
| 232 | map6 = netlbl_domhsh_addr6_entry(addr6); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 233 | type = map6->def.type; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 234 | calipso = map6->def.calipso; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 235 | netlbl_af6list_audit_addr(audit_buf, 0, NULL, |
| 236 | &addr6->addr, &addr6->mask); |
| 237 | #endif /* IPv6 */ |
| 238 | } else { |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 239 | type = entry->def.type; |
| 240 | cipsov4 = entry->def.cipso; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 241 | calipso = entry->def.calipso; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 242 | } |
| 243 | switch (type) { |
| 244 | case NETLBL_NLTYPE_UNLABELED: |
| 245 | audit_log_format(audit_buf, " nlbl_protocol=unlbl"); |
| 246 | break; |
| 247 | case NETLBL_NLTYPE_CIPSOV4: |
| 248 | BUG_ON(cipsov4 == NULL); |
| 249 | audit_log_format(audit_buf, |
| 250 | " nlbl_protocol=cipsov4 cipso_doi=%u", |
| 251 | cipsov4->doi); |
| 252 | break; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 253 | case NETLBL_NLTYPE_CALIPSO: |
| 254 | BUG_ON(calipso == NULL); |
| 255 | audit_log_format(audit_buf, |
| 256 | " nlbl_protocol=calipso calipso_doi=%u", |
| 257 | calipso->doi); |
| 258 | break; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 259 | } |
| 260 | audit_log_format(audit_buf, " res=%u", result == 0 ? 1 : 0); |
| 261 | audit_log_end(audit_buf); |
| 262 | } |
| 263 | } |
| 264 | |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 265 | /** |
| 266 | * netlbl_domhsh_validate - Validate a new domain mapping entry |
| 267 | * @entry: the entry to validate |
| 268 | * |
| 269 | * This function validates the new domain mapping entry to ensure that it is |
| 270 | * a valid entry. Returns zero on success, negative values on failure. |
| 271 | * |
| 272 | */ |
| 273 | static int netlbl_domhsh_validate(const struct netlbl_dom_map *entry) |
| 274 | { |
| 275 | struct netlbl_af4list *iter4; |
| 276 | struct netlbl_domaddr4_map *map4; |
| 277 | #if IS_ENABLED(CONFIG_IPV6) |
| 278 | struct netlbl_af6list *iter6; |
| 279 | struct netlbl_domaddr6_map *map6; |
| 280 | #endif /* IPv6 */ |
| 281 | |
| 282 | if (entry == NULL) |
| 283 | return -EINVAL; |
| 284 | |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 285 | if (entry->family != AF_INET && entry->family != AF_INET6 && |
| 286 | (entry->family != AF_UNSPEC || |
| 287 | entry->def.type != NETLBL_NLTYPE_UNLABELED)) |
| 288 | return -EINVAL; |
| 289 | |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 290 | switch (entry->def.type) { |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 291 | case NETLBL_NLTYPE_UNLABELED: |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 292 | if (entry->def.cipso != NULL || entry->def.calipso != NULL || |
| 293 | entry->def.addrsel != NULL) |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 294 | return -EINVAL; |
| 295 | break; |
| 296 | case NETLBL_NLTYPE_CIPSOV4: |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 297 | if (entry->family != AF_INET || |
| 298 | entry->def.cipso == NULL) |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 299 | return -EINVAL; |
| 300 | break; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 301 | case NETLBL_NLTYPE_CALIPSO: |
| 302 | if (entry->family != AF_INET6 || |
| 303 | entry->def.calipso == NULL) |
| 304 | return -EINVAL; |
| 305 | break; |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 306 | case NETLBL_NLTYPE_ADDRSELECT: |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 307 | netlbl_af4list_foreach(iter4, &entry->def.addrsel->list4) { |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 308 | map4 = netlbl_domhsh_addr4_entry(iter4); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 309 | switch (map4->def.type) { |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 310 | case NETLBL_NLTYPE_UNLABELED: |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 311 | if (map4->def.cipso != NULL) |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 312 | return -EINVAL; |
| 313 | break; |
| 314 | case NETLBL_NLTYPE_CIPSOV4: |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 315 | if (map4->def.cipso == NULL) |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 316 | return -EINVAL; |
| 317 | break; |
| 318 | default: |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | } |
| 322 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 323 | netlbl_af6list_foreach(iter6, &entry->def.addrsel->list6) { |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 324 | map6 = netlbl_domhsh_addr6_entry(iter6); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 325 | switch (map6->def.type) { |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 326 | case NETLBL_NLTYPE_UNLABELED: |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 327 | if (map6->def.calipso != NULL) |
| 328 | return -EINVAL; |
| 329 | break; |
| 330 | case NETLBL_NLTYPE_CALIPSO: |
| 331 | if (map6->def.calipso == NULL) |
| 332 | return -EINVAL; |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 333 | break; |
| 334 | default: |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | } |
| 338 | #endif /* IPv6 */ |
| 339 | break; |
| 340 | default: |
| 341 | return -EINVAL; |
| 342 | } |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 347 | /* |
| 348 | * Domain Hash Table Functions |
| 349 | */ |
| 350 | |
| 351 | /** |
| 352 | * netlbl_domhsh_init - Init for the domain hash |
| 353 | * @size: the number of bits to use for the hash buckets |
| 354 | * |
| 355 | * Description: |
| 356 | * Initializes the domain hash table, should be called only by |
| 357 | * netlbl_user_init() during initialization. Returns zero on success, non-zero |
| 358 | * values on error. |
| 359 | * |
| 360 | */ |
Pavel Emelyanov | 05705e4 | 2008-02-17 22:33:57 -0800 | [diff] [blame] | 361 | int __init netlbl_domhsh_init(u32 size) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 362 | { |
| 363 | u32 iter; |
| 364 | struct netlbl_domhsh_tbl *hsh_tbl; |
| 365 | |
| 366 | if (size == 0) |
| 367 | return -EINVAL; |
| 368 | |
| 369 | hsh_tbl = kmalloc(sizeof(*hsh_tbl), GFP_KERNEL); |
| 370 | if (hsh_tbl == NULL) |
| 371 | return -ENOMEM; |
| 372 | hsh_tbl->size = 1 << size; |
| 373 | hsh_tbl->tbl = kcalloc(hsh_tbl->size, |
| 374 | sizeof(struct list_head), |
| 375 | GFP_KERNEL); |
| 376 | if (hsh_tbl->tbl == NULL) { |
| 377 | kfree(hsh_tbl); |
| 378 | return -ENOMEM; |
| 379 | } |
| 380 | for (iter = 0; iter < hsh_tbl->size; iter++) |
| 381 | INIT_LIST_HEAD(&hsh_tbl->tbl[iter]); |
| 382 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 383 | spin_lock(&netlbl_domhsh_lock); |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 384 | rcu_assign_pointer(netlbl_domhsh, hsh_tbl); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 385 | spin_unlock(&netlbl_domhsh_lock); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * netlbl_domhsh_add - Adds a entry to the domain hash table |
| 392 | * @entry: the entry to add |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 393 | * @audit_info: NetLabel audit information |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 394 | * |
| 395 | * Description: |
| 396 | * Adds a new entry to the domain hash table and handles any updates to the |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 397 | * lower level protocol handler (i.e. CIPSO). @entry->family may be set to |
| 398 | * %AF_UNSPEC which will add an entry that matches all address families. This |
| 399 | * is only useful for the unlabelled type and will only succeed if there is no |
| 400 | * existing entry for any address family with the same domain. Returns zero |
| 401 | * on success, negative on failure. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 402 | * |
| 403 | */ |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 404 | int netlbl_domhsh_add(struct netlbl_dom_map *entry, |
| 405 | struct netlbl_audit *audit_info) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 406 | { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 407 | int ret_val = 0; |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 408 | struct netlbl_dom_map *entry_old, *entry_b; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 409 | struct netlbl_af4list *iter4; |
| 410 | struct netlbl_af4list *tmp4; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 411 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 412 | struct netlbl_af6list *iter6; |
| 413 | struct netlbl_af6list *tmp6; |
| 414 | #endif /* IPv6 */ |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 415 | |
Paul Moore | 6b21e1b | 2013-05-17 09:08:50 +0000 | [diff] [blame] | 416 | ret_val = netlbl_domhsh_validate(entry); |
| 417 | if (ret_val != 0) |
| 418 | return ret_val; |
| 419 | |
Paul Moore | b914f3a | 2010-04-01 10:43:57 +0000 | [diff] [blame] | 420 | /* XXX - we can remove this RCU read lock as the spinlock protects the |
| 421 | * entire function, but before we do we need to fixup the |
| 422 | * netlbl_af[4,6]list RCU functions to do "the right thing" with |
| 423 | * respect to rcu_dereference() when only a spinlock is held. */ |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 424 | rcu_read_lock(); |
Paul Moore | 1c3fad9 | 2008-01-29 08:37:57 -0500 | [diff] [blame] | 425 | spin_lock(&netlbl_domhsh_lock); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 426 | if (entry->domain != NULL) |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 427 | entry_old = netlbl_domhsh_search(entry->domain, entry->family); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 428 | else |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 429 | entry_old = netlbl_domhsh_search_def(entry->domain, |
| 430 | entry->family); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 431 | if (entry_old == NULL) { |
| 432 | entry->valid = 1; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 433 | |
| 434 | if (entry->domain != NULL) { |
| 435 | u32 bkt = netlbl_domhsh_hash(entry->domain); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 436 | list_add_tail_rcu(&entry->list, |
Paul Moore | 3482fd9 | 2007-08-07 17:53:10 -0700 | [diff] [blame] | 437 | &rcu_dereference(netlbl_domhsh)->tbl[bkt]); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 438 | } else { |
| 439 | INIT_LIST_HEAD(&entry->list); |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 440 | switch (entry->family) { |
| 441 | case AF_INET: |
| 442 | rcu_assign_pointer(netlbl_domhsh_def_ipv4, |
| 443 | entry); |
| 444 | break; |
| 445 | case AF_INET6: |
| 446 | rcu_assign_pointer(netlbl_domhsh_def_ipv6, |
| 447 | entry); |
| 448 | break; |
| 449 | case AF_UNSPEC: |
| 450 | if (entry->def.type != |
| 451 | NETLBL_NLTYPE_UNLABELED) { |
| 452 | ret_val = -EINVAL; |
| 453 | goto add_return; |
| 454 | } |
| 455 | entry_b = kzalloc(sizeof(*entry_b), GFP_ATOMIC); |
| 456 | if (entry_b == NULL) { |
| 457 | ret_val = -ENOMEM; |
| 458 | goto add_return; |
| 459 | } |
| 460 | entry_b->family = AF_INET6; |
| 461 | entry_b->def.type = NETLBL_NLTYPE_UNLABELED; |
| 462 | entry_b->valid = 1; |
| 463 | entry->family = AF_INET; |
| 464 | rcu_assign_pointer(netlbl_domhsh_def_ipv4, |
| 465 | entry); |
| 466 | rcu_assign_pointer(netlbl_domhsh_def_ipv6, |
| 467 | entry_b); |
| 468 | break; |
| 469 | default: |
| 470 | /* Already checked in |
| 471 | * netlbl_domhsh_validate(). */ |
| 472 | ret_val = -EINVAL; |
| 473 | goto add_return; |
| 474 | } |
Paul Moore | de64688 | 2006-11-17 17:38:55 -0500 | [diff] [blame] | 475 | } |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 476 | |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 477 | if (entry->def.type == NETLBL_NLTYPE_ADDRSELECT) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 478 | netlbl_af4list_foreach_rcu(iter4, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 479 | &entry->def.addrsel->list4) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 480 | netlbl_domhsh_audit_add(entry, iter4, NULL, |
| 481 | ret_val, audit_info); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 482 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 483 | netlbl_af6list_foreach_rcu(iter6, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 484 | &entry->def.addrsel->list6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 485 | netlbl_domhsh_audit_add(entry, NULL, iter6, |
| 486 | ret_val, audit_info); |
| 487 | #endif /* IPv6 */ |
| 488 | } else |
| 489 | netlbl_domhsh_audit_add(entry, NULL, NULL, |
| 490 | ret_val, audit_info); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 491 | } else if (entry_old->def.type == NETLBL_NLTYPE_ADDRSELECT && |
| 492 | entry->def.type == NETLBL_NLTYPE_ADDRSELECT) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 493 | struct list_head *old_list4; |
| 494 | struct list_head *old_list6; |
| 495 | |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 496 | old_list4 = &entry_old->def.addrsel->list4; |
| 497 | old_list6 = &entry_old->def.addrsel->list6; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 498 | |
| 499 | /* we only allow the addition of address selectors if all of |
| 500 | * the selectors do not exist in the existing domain map */ |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 501 | netlbl_af4list_foreach_rcu(iter4, &entry->def.addrsel->list4) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 502 | if (netlbl_af4list_search_exact(iter4->addr, |
| 503 | iter4->mask, |
| 504 | old_list4)) { |
| 505 | ret_val = -EEXIST; |
| 506 | goto add_return; |
| 507 | } |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 508 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 509 | netlbl_af6list_foreach_rcu(iter6, &entry->def.addrsel->list6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 510 | if (netlbl_af6list_search_exact(&iter6->addr, |
| 511 | &iter6->mask, |
| 512 | old_list6)) { |
| 513 | ret_val = -EEXIST; |
| 514 | goto add_return; |
| 515 | } |
| 516 | #endif /* IPv6 */ |
| 517 | |
| 518 | netlbl_af4list_foreach_safe(iter4, tmp4, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 519 | &entry->def.addrsel->list4) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 520 | netlbl_af4list_remove_entry(iter4); |
| 521 | iter4->valid = 1; |
| 522 | ret_val = netlbl_af4list_add(iter4, old_list4); |
| 523 | netlbl_domhsh_audit_add(entry_old, iter4, NULL, |
| 524 | ret_val, audit_info); |
| 525 | if (ret_val != 0) |
| 526 | goto add_return; |
| 527 | } |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 528 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 529 | netlbl_af6list_foreach_safe(iter6, tmp6, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 530 | &entry->def.addrsel->list6) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 531 | netlbl_af6list_remove_entry(iter6); |
| 532 | iter6->valid = 1; |
| 533 | ret_val = netlbl_af6list_add(iter6, old_list6); |
| 534 | netlbl_domhsh_audit_add(entry_old, NULL, iter6, |
| 535 | ret_val, audit_info); |
| 536 | if (ret_val != 0) |
| 537 | goto add_return; |
| 538 | } |
| 539 | #endif /* IPv6 */ |
| 540 | } else |
| 541 | ret_val = -EINVAL; |
| 542 | |
| 543 | add_return: |
| 544 | spin_unlock(&netlbl_domhsh_lock); |
| 545 | rcu_read_unlock(); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 546 | return ret_val; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * netlbl_domhsh_add_default - Adds the default entry to the domain hash table |
| 551 | * @entry: the entry to add |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 552 | * @audit_info: NetLabel audit information |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 553 | * |
| 554 | * Description: |
| 555 | * Adds a new default entry to the domain hash table and handles any updates |
| 556 | * to the lower level protocol handler (i.e. CIPSO). Returns zero on success, |
| 557 | * negative on failure. |
| 558 | * |
| 559 | */ |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 560 | int netlbl_domhsh_add_default(struct netlbl_dom_map *entry, |
| 561 | struct netlbl_audit *audit_info) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 562 | { |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 563 | return netlbl_domhsh_add(entry, audit_info); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 567 | * netlbl_domhsh_remove_entry - Removes a given entry from the domain table |
| 568 | * @entry: the entry to remove |
| 569 | * @audit_info: NetLabel audit information |
| 570 | * |
| 571 | * Description: |
| 572 | * Removes an entry from the domain hash table and handles any updates to the |
| 573 | * lower level protocol handler (i.e. CIPSO). Caller is responsible for |
| 574 | * ensuring that the RCU read lock is held. Returns zero on success, negative |
| 575 | * on failure. |
| 576 | * |
| 577 | */ |
| 578 | int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry, |
| 579 | struct netlbl_audit *audit_info) |
| 580 | { |
| 581 | int ret_val = 0; |
| 582 | struct audit_buffer *audit_buf; |
| 583 | |
| 584 | if (entry == NULL) |
| 585 | return -ENOENT; |
| 586 | |
| 587 | spin_lock(&netlbl_domhsh_lock); |
| 588 | if (entry->valid) { |
| 589 | entry->valid = 0; |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 590 | if (entry == rcu_dereference(netlbl_domhsh_def_ipv4)) |
| 591 | RCU_INIT_POINTER(netlbl_domhsh_def_ipv4, NULL); |
| 592 | else if (entry == rcu_dereference(netlbl_domhsh_def_ipv6)) |
| 593 | RCU_INIT_POINTER(netlbl_domhsh_def_ipv6, NULL); |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 594 | else |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 595 | list_del_rcu(&entry->list); |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 596 | } else |
| 597 | ret_val = -ENOENT; |
| 598 | spin_unlock(&netlbl_domhsh_lock); |
| 599 | |
| 600 | audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_DEL, audit_info); |
| 601 | if (audit_buf != NULL) { |
| 602 | audit_log_format(audit_buf, |
| 603 | " nlbl_domain=%s res=%u", |
| 604 | entry->domain ? entry->domain : "(default)", |
| 605 | ret_val == 0 ? 1 : 0); |
| 606 | audit_log_end(audit_buf); |
| 607 | } |
| 608 | |
| 609 | if (ret_val == 0) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 610 | struct netlbl_af4list *iter4; |
| 611 | struct netlbl_domaddr4_map *map4; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 612 | #if IS_ENABLED(CONFIG_IPV6) |
| 613 | struct netlbl_af6list *iter6; |
| 614 | struct netlbl_domaddr6_map *map6; |
| 615 | #endif /* IPv6 */ |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 616 | |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 617 | switch (entry->def.type) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 618 | case NETLBL_NLTYPE_ADDRSELECT: |
| 619 | netlbl_af4list_foreach_rcu(iter4, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 620 | &entry->def.addrsel->list4) { |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 621 | map4 = netlbl_domhsh_addr4_entry(iter4); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 622 | cipso_v4_doi_putdef(map4->def.cipso); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 623 | } |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 624 | #if IS_ENABLED(CONFIG_IPV6) |
| 625 | netlbl_af6list_foreach_rcu(iter6, |
| 626 | &entry->def.addrsel->list6) { |
| 627 | map6 = netlbl_domhsh_addr6_entry(iter6); |
| 628 | calipso_doi_putdef(map6->def.calipso); |
| 629 | } |
| 630 | #endif /* IPv6 */ |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 631 | break; |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 632 | case NETLBL_NLTYPE_CIPSOV4: |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 633 | cipso_v4_doi_putdef(entry->def.cipso); |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 634 | break; |
Huw Davies | dc7de73 | 2016-06-27 15:02:49 -0400 | [diff] [blame] | 635 | #if IS_ENABLED(CONFIG_IPV6) |
| 636 | case NETLBL_NLTYPE_CALIPSO: |
| 637 | calipso_doi_putdef(entry->def.calipso); |
| 638 | break; |
| 639 | #endif /* IPv6 */ |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 640 | } |
| 641 | call_rcu(&entry->rcu, netlbl_domhsh_free_entry); |
| 642 | } |
| 643 | |
| 644 | return ret_val; |
| 645 | } |
| 646 | |
| 647 | /** |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 648 | * netlbl_domhsh_remove_af4 - Removes an address selector entry |
| 649 | * @domain: the domain |
| 650 | * @addr: IPv4 address |
| 651 | * @mask: IPv4 address mask |
| 652 | * @audit_info: NetLabel audit information |
| 653 | * |
| 654 | * Description: |
| 655 | * Removes an individual address selector from a domain mapping and potentially |
| 656 | * the entire mapping if it is empty. Returns zero on success, negative values |
| 657 | * on failure. |
| 658 | * |
| 659 | */ |
| 660 | int netlbl_domhsh_remove_af4(const char *domain, |
| 661 | const struct in_addr *addr, |
| 662 | const struct in_addr *mask, |
| 663 | struct netlbl_audit *audit_info) |
| 664 | { |
| 665 | struct netlbl_dom_map *entry_map; |
| 666 | struct netlbl_af4list *entry_addr; |
| 667 | struct netlbl_af4list *iter4; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 668 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 669 | struct netlbl_af6list *iter6; |
| 670 | #endif /* IPv6 */ |
| 671 | struct netlbl_domaddr4_map *entry; |
| 672 | |
| 673 | rcu_read_lock(); |
| 674 | |
| 675 | if (domain) |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 676 | entry_map = netlbl_domhsh_search(domain, AF_INET); |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 677 | else |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 678 | entry_map = netlbl_domhsh_search_def(domain, AF_INET); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 679 | if (entry_map == NULL || |
| 680 | entry_map->def.type != NETLBL_NLTYPE_ADDRSELECT) |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 681 | goto remove_af4_failure; |
| 682 | |
| 683 | spin_lock(&netlbl_domhsh_lock); |
| 684 | entry_addr = netlbl_af4list_remove(addr->s_addr, mask->s_addr, |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 685 | &entry_map->def.addrsel->list4); |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 686 | spin_unlock(&netlbl_domhsh_lock); |
| 687 | |
| 688 | if (entry_addr == NULL) |
| 689 | goto remove_af4_failure; |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 690 | netlbl_af4list_foreach_rcu(iter4, &entry_map->def.addrsel->list4) |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 691 | goto remove_af4_single_addr; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 692 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 693 | netlbl_af6list_foreach_rcu(iter6, &entry_map->def.addrsel->list6) |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 694 | goto remove_af4_single_addr; |
| 695 | #endif /* IPv6 */ |
| 696 | /* the domain mapping is empty so remove it from the mapping table */ |
| 697 | netlbl_domhsh_remove_entry(entry_map, audit_info); |
| 698 | |
| 699 | remove_af4_single_addr: |
| 700 | rcu_read_unlock(); |
| 701 | /* yick, we can't use call_rcu here because we don't have a rcu head |
| 702 | * pointer but hopefully this should be a rare case so the pause |
| 703 | * shouldn't be a problem */ |
| 704 | synchronize_rcu(); |
| 705 | entry = netlbl_domhsh_addr4_entry(entry_addr); |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 706 | cipso_v4_doi_putdef(entry->def.cipso); |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 707 | kfree(entry); |
| 708 | return 0; |
| 709 | |
| 710 | remove_af4_failure: |
| 711 | rcu_read_unlock(); |
| 712 | return -ENOENT; |
| 713 | } |
| 714 | |
Huw Davies | 3f09354 | 2016-06-27 15:06:18 -0400 | [diff] [blame] | 715 | #if IS_ENABLED(CONFIG_IPV6) |
| 716 | /** |
| 717 | * netlbl_domhsh_remove_af6 - Removes an address selector entry |
| 718 | * @domain: the domain |
| 719 | * @addr: IPv6 address |
| 720 | * @mask: IPv6 address mask |
| 721 | * @audit_info: NetLabel audit information |
| 722 | * |
| 723 | * Description: |
| 724 | * Removes an individual address selector from a domain mapping and potentially |
| 725 | * the entire mapping if it is empty. Returns zero on success, negative values |
| 726 | * on failure. |
| 727 | * |
| 728 | */ |
| 729 | int netlbl_domhsh_remove_af6(const char *domain, |
| 730 | const struct in6_addr *addr, |
| 731 | const struct in6_addr *mask, |
| 732 | struct netlbl_audit *audit_info) |
| 733 | { |
| 734 | struct netlbl_dom_map *entry_map; |
| 735 | struct netlbl_af6list *entry_addr; |
| 736 | struct netlbl_af4list *iter4; |
| 737 | struct netlbl_af6list *iter6; |
| 738 | struct netlbl_domaddr6_map *entry; |
| 739 | |
| 740 | rcu_read_lock(); |
| 741 | |
| 742 | if (domain) |
| 743 | entry_map = netlbl_domhsh_search(domain, AF_INET6); |
| 744 | else |
| 745 | entry_map = netlbl_domhsh_search_def(domain, AF_INET6); |
| 746 | if (entry_map == NULL || |
| 747 | entry_map->def.type != NETLBL_NLTYPE_ADDRSELECT) |
| 748 | goto remove_af6_failure; |
| 749 | |
| 750 | spin_lock(&netlbl_domhsh_lock); |
| 751 | entry_addr = netlbl_af6list_remove(addr, mask, |
| 752 | &entry_map->def.addrsel->list6); |
| 753 | spin_unlock(&netlbl_domhsh_lock); |
| 754 | |
| 755 | if (entry_addr == NULL) |
| 756 | goto remove_af6_failure; |
| 757 | netlbl_af4list_foreach_rcu(iter4, &entry_map->def.addrsel->list4) |
| 758 | goto remove_af6_single_addr; |
| 759 | netlbl_af6list_foreach_rcu(iter6, &entry_map->def.addrsel->list6) |
| 760 | goto remove_af6_single_addr; |
| 761 | /* the domain mapping is empty so remove it from the mapping table */ |
| 762 | netlbl_domhsh_remove_entry(entry_map, audit_info); |
| 763 | |
| 764 | remove_af6_single_addr: |
| 765 | rcu_read_unlock(); |
| 766 | /* yick, we can't use call_rcu here because we don't have a rcu head |
| 767 | * pointer but hopefully this should be a rare case so the pause |
| 768 | * shouldn't be a problem */ |
| 769 | synchronize_rcu(); |
| 770 | entry = netlbl_domhsh_addr6_entry(entry_addr); |
| 771 | calipso_doi_putdef(entry->def.calipso); |
| 772 | kfree(entry); |
| 773 | return 0; |
| 774 | |
| 775 | remove_af6_failure: |
| 776 | rcu_read_unlock(); |
| 777 | return -ENOENT; |
| 778 | } |
| 779 | #endif /* IPv6 */ |
| 780 | |
Paul Moore | 6c2e8ac | 2008-12-31 12:54:11 -0500 | [diff] [blame] | 781 | /** |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 782 | * netlbl_domhsh_remove - Removes an entry from the domain hash table |
| 783 | * @domain: the domain to remove |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 784 | * @family: address family |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 785 | * @audit_info: NetLabel audit information |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 786 | * |
| 787 | * Description: |
| 788 | * Removes an entry from the domain hash table and handles any updates to the |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 789 | * lower level protocol handler (i.e. CIPSO). @family may be %AF_UNSPEC which |
| 790 | * removes all address family entries. Returns zero on success, negative on |
| 791 | * failure. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 792 | * |
| 793 | */ |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 794 | int netlbl_domhsh_remove(const char *domain, u16 family, |
| 795 | struct netlbl_audit *audit_info) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 796 | { |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 797 | int ret_val = -EINVAL; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 798 | struct netlbl_dom_map *entry; |
| 799 | |
| 800 | rcu_read_lock(); |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 801 | |
| 802 | if (family == AF_INET || family == AF_UNSPEC) { |
| 803 | if (domain) |
| 804 | entry = netlbl_domhsh_search(domain, AF_INET); |
| 805 | else |
| 806 | entry = netlbl_domhsh_search_def(domain, AF_INET); |
| 807 | ret_val = netlbl_domhsh_remove_entry(entry, audit_info); |
| 808 | if (ret_val && ret_val != -ENOENT) |
| 809 | goto done; |
| 810 | } |
| 811 | if (family == AF_INET6 || family == AF_UNSPEC) { |
| 812 | int ret_val2; |
| 813 | |
| 814 | if (domain) |
| 815 | entry = netlbl_domhsh_search(domain, AF_INET6); |
| 816 | else |
| 817 | entry = netlbl_domhsh_search_def(domain, AF_INET6); |
| 818 | ret_val2 = netlbl_domhsh_remove_entry(entry, audit_info); |
| 819 | if (ret_val2 != -ENOENT) |
| 820 | ret_val = ret_val2; |
| 821 | } |
| 822 | done: |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 823 | rcu_read_unlock(); |
Paul Moore | b1edeb1 | 2008-10-10 10:16:31 -0400 | [diff] [blame] | 824 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 825 | return ret_val; |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * netlbl_domhsh_remove_default - Removes the default entry from the table |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 830 | * @family: address family |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 831 | * @audit_info: NetLabel audit information |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 832 | * |
| 833 | * Description: |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 834 | * Removes/resets the default entry corresponding to @family from the domain |
| 835 | * hash table and handles any updates to the lower level protocol handler |
| 836 | * (i.e. CIPSO). @family may be %AF_UNSPEC which removes all address family |
| 837 | * entries. Returns zero on success, negative on failure. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 838 | * |
| 839 | */ |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 840 | int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 841 | { |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 842 | return netlbl_domhsh_remove(NULL, family, audit_info); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /** |
| 846 | * netlbl_domhsh_getentry - Get an entry from the domain hash table |
| 847 | * @domain: the domain name to search for |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 848 | * @family: address family |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 849 | * |
| 850 | * Description: |
| 851 | * Look through the domain hash table searching for an entry to match @domain, |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 852 | * with address family @family, return a pointer to a copy of the entry or |
| 853 | * NULL. The caller is responsible for ensuring that rcu_read_[un]lock() is |
| 854 | * called. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 855 | * |
| 856 | */ |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 857 | struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 858 | { |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 859 | if (family == AF_UNSPEC) |
| 860 | return NULL; |
| 861 | return netlbl_domhsh_search_def(domain, family); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /** |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 865 | * netlbl_domhsh_getentry_af4 - Get an entry from the domain hash table |
| 866 | * @domain: the domain name to search for |
| 867 | * @addr: the IP address to search for |
| 868 | * |
| 869 | * Description: |
| 870 | * Look through the domain hash table searching for an entry to match @domain |
| 871 | * and @addr, return a pointer to a copy of the entry or NULL. The caller is |
| 872 | * responsible for ensuring that rcu_read_[un]lock() is called. |
| 873 | * |
| 874 | */ |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 875 | struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain, |
| 876 | __be32 addr) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 877 | { |
| 878 | struct netlbl_dom_map *dom_iter; |
| 879 | struct netlbl_af4list *addr_iter; |
| 880 | |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 881 | dom_iter = netlbl_domhsh_search_def(domain, AF_INET); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 882 | if (dom_iter == NULL) |
| 883 | return NULL; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 884 | |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 885 | if (dom_iter->def.type != NETLBL_NLTYPE_ADDRSELECT) |
| 886 | return &dom_iter->def; |
| 887 | addr_iter = netlbl_af4list_search(addr, &dom_iter->def.addrsel->list4); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 888 | if (addr_iter == NULL) |
| 889 | return NULL; |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 890 | return &(netlbl_domhsh_addr4_entry(addr_iter)->def); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 891 | } |
| 892 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 893 | #if IS_ENABLED(CONFIG_IPV6) |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 894 | /** |
| 895 | * netlbl_domhsh_getentry_af6 - Get an entry from the domain hash table |
| 896 | * @domain: the domain name to search for |
| 897 | * @addr: the IP address to search for |
| 898 | * |
| 899 | * Description: |
| 900 | * Look through the domain hash table searching for an entry to match @domain |
| 901 | * and @addr, return a pointer to a copy of the entry or NULL. The caller is |
| 902 | * responsible for ensuring that rcu_read_[un]lock() is called. |
| 903 | * |
| 904 | */ |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 905 | struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain, |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 906 | const struct in6_addr *addr) |
| 907 | { |
| 908 | struct netlbl_dom_map *dom_iter; |
| 909 | struct netlbl_af6list *addr_iter; |
| 910 | |
Huw Davies | 8f18e67 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 911 | dom_iter = netlbl_domhsh_search_def(domain, AF_INET6); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 912 | if (dom_iter == NULL) |
| 913 | return NULL; |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 914 | |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 915 | if (dom_iter->def.type != NETLBL_NLTYPE_ADDRSELECT) |
| 916 | return &dom_iter->def; |
| 917 | addr_iter = netlbl_af6list_search(addr, &dom_iter->def.addrsel->list6); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 918 | if (addr_iter == NULL) |
| 919 | return NULL; |
Paul Moore | 6a8b7f0 | 2013-08-02 14:45:08 -0400 | [diff] [blame] | 920 | return &(netlbl_domhsh_addr6_entry(addr_iter)->def); |
Paul Moore | 63c4168 | 2008-10-10 10:16:32 -0400 | [diff] [blame] | 921 | } |
| 922 | #endif /* IPv6 */ |
| 923 | |
| 924 | /** |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 925 | * netlbl_domhsh_walk - Iterate through the domain mapping hash table |
| 926 | * @skip_bkt: the number of buckets to skip at the start |
| 927 | * @skip_chain: the number of entries to skip in the first iterated bucket |
| 928 | * @callback: callback for each entry |
| 929 | * @cb_arg: argument for the callback function |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 930 | * |
| 931 | * Description: |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 932 | * Interate over the domain mapping hash table, skipping the first @skip_bkt |
| 933 | * buckets and @skip_chain entries. For each entry in the table call |
| 934 | * @callback, if @callback returns a negative value stop 'walking' through the |
| 935 | * table and return. Updates the values in @skip_bkt and @skip_chain on |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 936 | * return. Returns zero on success, negative values on failure. |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 937 | * |
| 938 | */ |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 939 | int netlbl_domhsh_walk(u32 *skip_bkt, |
| 940 | u32 *skip_chain, |
| 941 | int (*callback) (struct netlbl_dom_map *entry, void *arg), |
| 942 | void *cb_arg) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 943 | { |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 944 | int ret_val = -ENOENT; |
| 945 | u32 iter_bkt; |
Paul Moore | 5619670 | 2008-10-10 10:16:29 -0400 | [diff] [blame] | 946 | struct list_head *iter_list; |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 947 | struct netlbl_dom_map *iter_entry; |
| 948 | u32 chain_cnt = 0; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 949 | |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 950 | rcu_read_lock(); |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 951 | for (iter_bkt = *skip_bkt; |
| 952 | iter_bkt < rcu_dereference(netlbl_domhsh)->size; |
| 953 | iter_bkt++, chain_cnt = 0) { |
Paul Moore | 5619670 | 2008-10-10 10:16:29 -0400 | [diff] [blame] | 954 | iter_list = &rcu_dereference(netlbl_domhsh)->tbl[iter_bkt]; |
| 955 | list_for_each_entry_rcu(iter_entry, iter_list, list) |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 956 | if (iter_entry->valid) { |
| 957 | if (chain_cnt++ < *skip_chain) |
| 958 | continue; |
| 959 | ret_val = callback(iter_entry, cb_arg); |
| 960 | if (ret_val < 0) { |
| 961 | chain_cnt--; |
| 962 | goto walk_return; |
| 963 | } |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 964 | } |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 965 | } |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 966 | |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 967 | walk_return: |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 968 | rcu_read_unlock(); |
Paul Moore | fcd4828 | 2006-09-25 15:56:09 -0700 | [diff] [blame] | 969 | *skip_bkt = iter_bkt; |
| 970 | *skip_chain = chain_cnt; |
| 971 | return ret_val; |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 972 | } |