diff options
-rw-r--r-- | include/net/netlabel.h | 47 | ||||
-rw-r--r-- | net/ipv4/cipso_ipv4.c | 4 | ||||
-rw-r--r-- | net/netlabel/netlabel_cipso_v4.c | 2 | ||||
-rw-r--r-- | net/netlabel/netlabel_cipso_v4.h | 3 | ||||
-rw-r--r-- | net/netlabel/netlabel_domainhash.h | 1 | ||||
-rw-r--r-- | net/netlabel/netlabel_kapi.c | 177 |
6 files changed, 225 insertions, 9 deletions
diff --git a/include/net/netlabel.h b/include/net/netlabel.h index b3213c7c5309..0ca67d73c7ad 100644 --- a/include/net/netlabel.h +++ b/include/net/netlabel.h | |||
@@ -36,6 +36,8 @@ | |||
36 | #include <net/netlink.h> | 36 | #include <net/netlink.h> |
37 | #include <asm/atomic.h> | 37 | #include <asm/atomic.h> |
38 | 38 | ||
39 | struct cipso_v4_doi; | ||
40 | |||
39 | /* | 41 | /* |
40 | * NetLabel - A management interface for maintaining network packet label | 42 | * NetLabel - A management interface for maintaining network packet label |
41 | * mapping tables for explicit packet labling protocols. | 43 | * mapping tables for explicit packet labling protocols. |
@@ -103,12 +105,6 @@ struct netlbl_audit { | |||
103 | uid_t loginuid; | 105 | uid_t loginuid; |
104 | }; | 106 | }; |
105 | 107 | ||
106 | /* Domain mapping definition struct */ | ||
107 | struct netlbl_dom_map; | ||
108 | |||
109 | /* Domain mapping operations */ | ||
110 | int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info); | ||
111 | |||
112 | /* | 108 | /* |
113 | * LSM security attributes | 109 | * LSM security attributes |
114 | */ | 110 | */ |
@@ -344,6 +340,19 @@ static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr) | |||
344 | 340 | ||
345 | #ifdef CONFIG_NETLABEL | 341 | #ifdef CONFIG_NETLABEL |
346 | /* | 342 | /* |
343 | * LSM configuration operations | ||
344 | */ | ||
345 | int netlbl_cfg_map_del(const char *domain, struct netlbl_audit *audit_info); | ||
346 | int netlbl_cfg_unlbl_add_map(const char *domain, | ||
347 | struct netlbl_audit *audit_info); | ||
348 | int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, | ||
349 | struct netlbl_audit *audit_info); | ||
350 | int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def, | ||
351 | const char *domain, | ||
352 | struct netlbl_audit *audit_info); | ||
353 | int netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info); | ||
354 | |||
355 | /* | ||
347 | * LSM security attribute operations | 356 | * LSM security attribute operations |
348 | */ | 357 | */ |
349 | int netlbl_secattr_catmap_walk(struct netlbl_lsm_secattr_catmap *catmap, | 358 | int netlbl_secattr_catmap_walk(struct netlbl_lsm_secattr_catmap *catmap, |
@@ -378,6 +387,32 @@ void netlbl_cache_invalidate(void); | |||
378 | int netlbl_cache_add(const struct sk_buff *skb, | 387 | int netlbl_cache_add(const struct sk_buff *skb, |
379 | const struct netlbl_lsm_secattr *secattr); | 388 | const struct netlbl_lsm_secattr *secattr); |
380 | #else | 389 | #else |
390 | static inline int netlbl_cfg_map_del(const char *domain, | ||
391 | struct netlbl_audit *audit_info) | ||
392 | { | ||
393 | return -ENOSYS; | ||
394 | } | ||
395 | static inline int netlbl_cfg_unlbl_add_map(const char *domain, | ||
396 | struct netlbl_audit *audit_info) | ||
397 | { | ||
398 | return -ENOSYS; | ||
399 | } | ||
400 | static inline int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, | ||
401 | struct netlbl_audit *audit_info) | ||
402 | { | ||
403 | return -ENOSYS; | ||
404 | } | ||
405 | static inline int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def, | ||
406 | const char *domain, | ||
407 | struct netlbl_audit *audit_info) | ||
408 | { | ||
409 | return -ENOSYS; | ||
410 | } | ||
411 | static inline int netlbl_cfg_cipsov4_del(u32 doi, | ||
412 | struct netlbl_audit *audit_info) | ||
413 | { | ||
414 | return -ENOSYS; | ||
415 | } | ||
381 | static inline int netlbl_secattr_catmap_walk( | 416 | static inline int netlbl_secattr_catmap_walk( |
382 | struct netlbl_lsm_secattr_catmap *catmap, | 417 | struct netlbl_lsm_secattr_catmap *catmap, |
383 | u32 offset) | 418 | u32 offset) |
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index a2241060113b..8cd357f41283 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c | |||
@@ -547,8 +547,8 @@ int cipso_v4_doi_remove(u32 doi, | |||
547 | rcu_read_lock(); | 547 | rcu_read_lock(); |
548 | list_for_each_entry_rcu(dom_iter, &doi_def->dom_list, list) | 548 | list_for_each_entry_rcu(dom_iter, &doi_def->dom_list, list) |
549 | if (dom_iter->valid) | 549 | if (dom_iter->valid) |
550 | netlbl_domhsh_remove(dom_iter->domain, | 550 | netlbl_cfg_map_del(dom_iter->domain, |
551 | audit_info); | 551 | audit_info); |
552 | rcu_read_unlock(); | 552 | rcu_read_unlock(); |
553 | cipso_v4_cache_invalidate(); | 553 | cipso_v4_cache_invalidate(); |
554 | call_rcu(&doi_def->rcu, callback); | 554 | call_rcu(&doi_def->rcu, callback); |
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index becf91a952ae..c7ad64d664ad 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c | |||
@@ -90,7 +90,7 @@ static const struct nla_policy netlbl_cipsov4_genl_policy[NLBL_CIPSOV4_A_MAX + 1 | |||
90 | * safely. | 90 | * safely. |
91 | * | 91 | * |
92 | */ | 92 | */ |
93 | static void netlbl_cipsov4_doi_free(struct rcu_head *entry) | 93 | void netlbl_cipsov4_doi_free(struct rcu_head *entry) |
94 | { | 94 | { |
95 | struct cipso_v4_doi *ptr; | 95 | struct cipso_v4_doi *ptr; |
96 | 96 | ||
diff --git a/net/netlabel/netlabel_cipso_v4.h b/net/netlabel/netlabel_cipso_v4.h index f03cf9b78286..220cb9d06b49 100644 --- a/net/netlabel/netlabel_cipso_v4.h +++ b/net/netlabel/netlabel_cipso_v4.h | |||
@@ -163,4 +163,7 @@ enum { | |||
163 | /* NetLabel protocol functions */ | 163 | /* NetLabel protocol functions */ |
164 | int netlbl_cipsov4_genl_init(void); | 164 | int netlbl_cipsov4_genl_init(void); |
165 | 165 | ||
166 | /* Free the memory associated with a CIPSOv4 DOI definition */ | ||
167 | void netlbl_cipsov4_doi_free(struct rcu_head *entry); | ||
168 | |||
166 | #endif | 169 | #endif |
diff --git a/net/netlabel/netlabel_domainhash.h b/net/netlabel/netlabel_domainhash.h index 3689956c3436..8220990ceb96 100644 --- a/net/netlabel/netlabel_domainhash.h +++ b/net/netlabel/netlabel_domainhash.h | |||
@@ -61,6 +61,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry, | |||
61 | struct netlbl_audit *audit_info); | 61 | struct netlbl_audit *audit_info); |
62 | int netlbl_domhsh_add_default(struct netlbl_dom_map *entry, | 62 | int netlbl_domhsh_add_default(struct netlbl_dom_map *entry, |
63 | struct netlbl_audit *audit_info); | 63 | struct netlbl_audit *audit_info); |
64 | int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info); | ||
64 | int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info); | 65 | int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info); |
65 | struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain); | 66 | struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain); |
66 | int netlbl_domhsh_walk(u32 *skip_bkt, | 67 | int netlbl_domhsh_walk(u32 *skip_bkt, |
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index c69e3e1f05c3..39793a1a93aa 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c | |||
@@ -30,6 +30,7 @@ | |||
30 | 30 | ||
31 | #include <linux/init.h> | 31 | #include <linux/init.h> |
32 | #include <linux/types.h> | 32 | #include <linux/types.h> |
33 | #include <linux/audit.h> | ||
33 | #include <net/ip.h> | 34 | #include <net/ip.h> |
34 | #include <net/netlabel.h> | 35 | #include <net/netlabel.h> |
35 | #include <net/cipso_ipv4.h> | 36 | #include <net/cipso_ipv4.h> |
@@ -38,10 +39,186 @@ | |||
38 | 39 | ||
39 | #include "netlabel_domainhash.h" | 40 | #include "netlabel_domainhash.h" |
40 | #include "netlabel_unlabeled.h" | 41 | #include "netlabel_unlabeled.h" |
42 | #include "netlabel_cipso_v4.h" | ||
41 | #include "netlabel_user.h" | 43 | #include "netlabel_user.h" |
42 | #include "netlabel_mgmt.h" | 44 | #include "netlabel_mgmt.h" |
43 | 45 | ||
44 | /* | 46 | /* |
47 | * Configuration Functions | ||
48 | */ | ||
49 | |||
50 | /** | ||
51 | * netlbl_cfg_map_del - Remove a NetLabel/LSM domain mapping | ||
52 | * @domain: the domain mapping to remove | ||
53 | * @audit_info: NetLabel audit information | ||
54 | * | ||
55 | * Description: | ||
56 | * Removes a NetLabel/LSM domain mapping. A @domain value of NULL causes the | ||
57 | * default domain mapping to be removed. Returns zero on success, negative | ||
58 | * values on failure. | ||
59 | * | ||
60 | */ | ||
61 | int netlbl_cfg_map_del(const char *domain, struct netlbl_audit *audit_info) | ||
62 | { | ||
63 | return netlbl_domhsh_remove(domain, audit_info); | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * netlbl_cfg_unlbl_add_map - Add an unlabeled NetLabel/LSM domain mapping | ||
68 | * @domain: the domain mapping to add | ||
69 | * @audit_info: NetLabel audit information | ||
70 | * | ||
71 | * Description: | ||
72 | * Adds a new unlabeled NetLabel/LSM domain mapping. A @domain value of NULL | ||
73 | * causes a new default domain mapping to be added. Returns zero on success, | ||
74 | * negative values on failure. | ||
75 | * | ||
76 | */ | ||
77 | int netlbl_cfg_unlbl_add_map(const char *domain, | ||
78 | struct netlbl_audit *audit_info) | ||
79 | { | ||
80 | int ret_val = -ENOMEM; | ||
81 | struct netlbl_dom_map *entry; | ||
82 | |||
83 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); | ||
84 | if (entry == NULL) | ||
85 | goto cfg_unlbl_add_map_failure; | ||
86 | if (domain != NULL) { | ||
87 | entry->domain = kstrdup(domain, GFP_ATOMIC); | ||
88 | if (entry->domain == NULL) | ||
89 | goto cfg_unlbl_add_map_failure; | ||
90 | } | ||
91 | entry->type = NETLBL_NLTYPE_UNLABELED; | ||
92 | |||
93 | ret_val = netlbl_domhsh_add(entry, audit_info); | ||
94 | if (ret_val != 0) | ||
95 | goto cfg_unlbl_add_map_failure; | ||
96 | |||
97 | return 0; | ||
98 | |||
99 | cfg_unlbl_add_map_failure: | ||
100 | if (entry != NULL) | ||
101 | kfree(entry->domain); | ||
102 | kfree(entry); | ||
103 | return ret_val; | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * netlbl_cfg_cipsov4_add - Add a new CIPSOv4 DOI definition | ||
108 | * @doi_def: the DOI definition | ||
109 | * @audit_info: NetLabel audit information | ||
110 | * | ||
111 | * Description: | ||
112 | * Add a new CIPSOv4 DOI definition to the NetLabel subsystem. Returns zero on | ||
113 | * success, negative values on failure. | ||
114 | * | ||
115 | */ | ||
116 | int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, | ||
117 | struct netlbl_audit *audit_info) | ||
118 | { | ||
119 | int ret_val; | ||
120 | const char *type_str; | ||
121 | struct audit_buffer *audit_buf; | ||
122 | |||
123 | ret_val = cipso_v4_doi_add(doi_def); | ||
124 | |||
125 | audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_ADD, | ||
126 | audit_info); | ||
127 | if (audit_buf != NULL) { | ||
128 | switch (doi_def->type) { | ||
129 | case CIPSO_V4_MAP_STD: | ||
130 | type_str = "std"; | ||
131 | break; | ||
132 | case CIPSO_V4_MAP_PASS: | ||
133 | type_str = "pass"; | ||
134 | break; | ||
135 | default: | ||
136 | type_str = "(unknown)"; | ||
137 | } | ||
138 | audit_log_format(audit_buf, | ||
139 | " cipso_doi=%u cipso_type=%s res=%u", | ||
140 | doi_def->doi, | ||
141 | type_str, | ||
142 | ret_val == 0 ? 1 : 0); | ||
143 | audit_log_end(audit_buf); | ||
144 | } | ||
145 | |||
146 | return ret_val; | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * netlbl_cfg_cipsov4_add_map - Add a new CIPSOv4 DOI definition and mapping | ||
151 | * @doi_def: the DOI definition | ||
152 | * @domain: the domain mapping to add | ||
153 | * @audit_info: NetLabel audit information | ||
154 | * | ||
155 | * Description: | ||
156 | * Add a new CIPSOv4 DOI definition and NetLabel/LSM domain mapping for this | ||
157 | * new DOI definition to the NetLabel subsystem. A @domain value of NULL adds | ||
158 | * a new default domain mapping. Returns zero on success, negative values on | ||
159 | * failure. | ||
160 | * | ||
161 | */ | ||
162 | int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def, | ||
163 | const char *domain, | ||
164 | struct netlbl_audit *audit_info) | ||
165 | { | ||
166 | int ret_val = -ENOMEM; | ||
167 | struct netlbl_dom_map *entry; | ||
168 | |||
169 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); | ||
170 | if (entry == NULL) | ||
171 | goto cfg_cipsov4_add_map_failure; | ||
172 | if (domain != NULL) { | ||
173 | entry->domain = kstrdup(domain, GFP_ATOMIC); | ||
174 | if (entry->domain == NULL) | ||
175 | goto cfg_cipsov4_add_map_failure; | ||
176 | } | ||
177 | entry->type = NETLBL_NLTYPE_CIPSOV4; | ||
178 | entry->type_def.cipsov4 = doi_def; | ||
179 | |||
180 | /* Grab a RCU read lock here so nothing happens to the doi_def variable | ||
181 | * between adding it to the CIPSOv4 protocol engine and adding a | ||
182 | * domain mapping for it. */ | ||
183 | |||
184 | rcu_read_lock(); | ||
185 | ret_val = netlbl_cfg_cipsov4_add(doi_def, audit_info); | ||
186 | if (ret_val != 0) | ||
187 | goto cfg_cipsov4_add_map_failure_unlock; | ||
188 | ret_val = netlbl_domhsh_add(entry, audit_info); | ||
189 | if (ret_val != 0) | ||
190 | goto cfg_cipsov4_add_map_failure_remove_doi; | ||
191 | rcu_read_unlock(); | ||
192 | |||
193 | return 0; | ||
194 | |||
195 | cfg_cipsov4_add_map_failure_remove_doi: | ||
196 | cipso_v4_doi_remove(doi_def->doi, audit_info, netlbl_cipsov4_doi_free); | ||
197 | cfg_cipsov4_add_map_failure_unlock: | ||
198 | rcu_read_unlock(); | ||
199 | cfg_cipsov4_add_map_failure: | ||
200 | if (entry != NULL) | ||
201 | kfree(entry->domain); | ||
202 | kfree(entry); | ||
203 | return ret_val; | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * netlbl_cfg_cipsov4_del - Removean existing CIPSOv4 DOI definition | ||
208 | * @doi: the CIPSO DOI value | ||
209 | * @audit_info: NetLabel audit information | ||
210 | * | ||
211 | * Description: | ||
212 | * Removes an existing CIPSOv4 DOI definition from the NetLabel subsystem. | ||
213 | * Returns zero on success, negative values on failure. | ||
214 | * | ||
215 | */ | ||
216 | int netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info) | ||
217 | { | ||
218 | return cipso_v4_doi_remove(doi, audit_info, netlbl_cipsov4_doi_free); | ||
219 | } | ||
220 | |||
221 | /* | ||
45 | * Security Attribute Functions | 222 | * Security Attribute Functions |
46 | */ | 223 | */ |
47 | 224 | ||