diff options
Diffstat (limited to 'net/netlabel/netlabel_cipso_v4.c')
-rw-r--r-- | net/netlabel/netlabel_cipso_v4.c | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index aaf50032b3ac..5c4f60bbc82d 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include "netlabel_user.h" | 43 | #include "netlabel_user.h" |
44 | #include "netlabel_cipso_v4.h" | 44 | #include "netlabel_cipso_v4.h" |
45 | #include "netlabel_mgmt.h" | 45 | #include "netlabel_mgmt.h" |
46 | #include "netlabel_domainhash.h" | ||
46 | 47 | ||
47 | /* Argument struct for cipso_v4_doi_walk() */ | 48 | /* Argument struct for cipso_v4_doi_walk() */ |
48 | struct netlbl_cipsov4_doiwalk_arg { | 49 | struct netlbl_cipsov4_doiwalk_arg { |
@@ -51,6 +52,12 @@ struct netlbl_cipsov4_doiwalk_arg { | |||
51 | u32 seq; | 52 | u32 seq; |
52 | }; | 53 | }; |
53 | 54 | ||
55 | /* Argument struct for netlbl_domhsh_walk() */ | ||
56 | struct netlbl_domhsh_walk_arg { | ||
57 | struct netlbl_audit *audit_info; | ||
58 | u32 doi; | ||
59 | }; | ||
60 | |||
54 | /* NetLabel Generic NETLINK CIPSOv4 family */ | 61 | /* NetLabel Generic NETLINK CIPSOv4 family */ |
55 | static struct genl_family netlbl_cipsov4_gnl_family = { | 62 | static struct genl_family netlbl_cipsov4_gnl_family = { |
56 | .id = GENL_ID_GENERATE, | 63 | .id = GENL_ID_GENERATE, |
@@ -81,32 +88,6 @@ static const struct nla_policy netlbl_cipsov4_genl_policy[NLBL_CIPSOV4_A_MAX + 1 | |||
81 | */ | 88 | */ |
82 | 89 | ||
83 | /** | 90 | /** |
84 | * netlbl_cipsov4_doi_free - Frees a CIPSO V4 DOI definition | ||
85 | * @entry: the entry's RCU field | ||
86 | * | ||
87 | * Description: | ||
88 | * This function is designed to be used as a callback to the call_rcu() | ||
89 | * function so that the memory allocated to the DOI definition can be released | ||
90 | * safely. | ||
91 | * | ||
92 | */ | ||
93 | void netlbl_cipsov4_doi_free(struct rcu_head *entry) | ||
94 | { | ||
95 | struct cipso_v4_doi *ptr; | ||
96 | |||
97 | ptr = container_of(entry, struct cipso_v4_doi, rcu); | ||
98 | switch (ptr->type) { | ||
99 | case CIPSO_V4_MAP_STD: | ||
100 | kfree(ptr->map.std->lvl.cipso); | ||
101 | kfree(ptr->map.std->lvl.local); | ||
102 | kfree(ptr->map.std->cat.cipso); | ||
103 | kfree(ptr->map.std->cat.local); | ||
104 | break; | ||
105 | } | ||
106 | kfree(ptr); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * netlbl_cipsov4_add_common - Parse the common sections of a ADD message | 91 | * netlbl_cipsov4_add_common - Parse the common sections of a ADD message |
111 | * @info: the Generic NETLINK info block | 92 | * @info: the Generic NETLINK info block |
112 | * @doi_def: the CIPSO V4 DOI definition | 93 | * @doi_def: the CIPSO V4 DOI definition |
@@ -342,7 +323,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info) | |||
342 | 323 | ||
343 | add_std_failure: | 324 | add_std_failure: |
344 | if (doi_def) | 325 | if (doi_def) |
345 | netlbl_cipsov4_doi_free(&doi_def->rcu); | 326 | cipso_v4_doi_free(doi_def); |
346 | return ret_val; | 327 | return ret_val; |
347 | } | 328 | } |
348 | 329 | ||
@@ -379,7 +360,7 @@ static int netlbl_cipsov4_add_pass(struct genl_info *info) | |||
379 | return 0; | 360 | return 0; |
380 | 361 | ||
381 | add_pass_failure: | 362 | add_pass_failure: |
382 | netlbl_cipsov4_doi_free(&doi_def->rcu); | 363 | cipso_v4_doi_free(doi_def); |
383 | return ret_val; | 364 | return ret_val; |
384 | } | 365 | } |
385 | 366 | ||
@@ -668,6 +649,29 @@ static int netlbl_cipsov4_listall(struct sk_buff *skb, | |||
668 | } | 649 | } |
669 | 650 | ||
670 | /** | 651 | /** |
652 | * netlbl_cipsov4_remove_cb - netlbl_cipsov4_remove() callback for REMOVE | ||
653 | * @entry: LSM domain mapping entry | ||
654 | * @arg: the netlbl_domhsh_walk_arg structure | ||
655 | * | ||
656 | * Description: | ||
657 | * This function is intended for use by netlbl_cipsov4_remove() as the callback | ||
658 | * for the netlbl_domhsh_walk() function; it removes LSM domain map entries | ||
659 | * which are associated with the CIPSO DOI specified in @arg. Returns zero on | ||
660 | * success, negative values on failure. | ||
661 | * | ||
662 | */ | ||
663 | static int netlbl_cipsov4_remove_cb(struct netlbl_dom_map *entry, void *arg) | ||
664 | { | ||
665 | struct netlbl_domhsh_walk_arg *cb_arg = arg; | ||
666 | |||
667 | if (entry->type == NETLBL_NLTYPE_CIPSOV4 && | ||
668 | entry->type_def.cipsov4->doi == cb_arg->doi) | ||
669 | return netlbl_domhsh_remove_entry(entry, cb_arg->audit_info); | ||
670 | |||
671 | return 0; | ||
672 | } | ||
673 | |||
674 | /** | ||
671 | * netlbl_cipsov4_remove - Handle a REMOVE message | 675 | * netlbl_cipsov4_remove - Handle a REMOVE message |
672 | * @skb: the NETLINK buffer | 676 | * @skb: the NETLINK buffer |
673 | * @info: the Generic NETLINK info block | 677 | * @info: the Generic NETLINK info block |
@@ -681,8 +685,11 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info) | |||
681 | { | 685 | { |
682 | int ret_val = -EINVAL; | 686 | int ret_val = -EINVAL; |
683 | u32 doi = 0; | 687 | u32 doi = 0; |
688 | struct netlbl_domhsh_walk_arg cb_arg; | ||
684 | struct audit_buffer *audit_buf; | 689 | struct audit_buffer *audit_buf; |
685 | struct netlbl_audit audit_info; | 690 | struct netlbl_audit audit_info; |
691 | u32 skip_bkt = 0; | ||
692 | u32 skip_chain = 0; | ||
686 | 693 | ||
687 | if (!info->attrs[NLBL_CIPSOV4_A_DOI]) | 694 | if (!info->attrs[NLBL_CIPSOV4_A_DOI]) |
688 | return -EINVAL; | 695 | return -EINVAL; |
@@ -690,11 +697,15 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info) | |||
690 | doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]); | 697 | doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]); |
691 | netlbl_netlink_auditinfo(skb, &audit_info); | 698 | netlbl_netlink_auditinfo(skb, &audit_info); |
692 | 699 | ||
693 | ret_val = cipso_v4_doi_remove(doi, | 700 | cb_arg.doi = doi; |
694 | &audit_info, | 701 | cb_arg.audit_info = &audit_info; |
695 | netlbl_cipsov4_doi_free); | 702 | ret_val = netlbl_domhsh_walk(&skip_bkt, &skip_chain, |
696 | if (ret_val == 0) | 703 | netlbl_cipsov4_remove_cb, &cb_arg); |
697 | atomic_dec(&netlabel_mgmt_protocount); | 704 | if (ret_val == 0 || ret_val == -ENOENT) { |
705 | ret_val = cipso_v4_doi_remove(doi, &audit_info); | ||
706 | if (ret_val == 0) | ||
707 | atomic_dec(&netlabel_mgmt_protocount); | ||
708 | } | ||
698 | 709 | ||
699 | audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_DEL, | 710 | audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_DEL, |
700 | &audit_info); | 711 | &audit_info); |