Coding style cleanups
PATCH 1/1 Coding style cleanups
Clean up some of the coding style issues in ACM files.
--- xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c | 178 +++--- xen-unstable.hg/xen/acm/acm_policy.c | 296 ++++++---- xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c | 323 +++++++----- 3 files changed, 475 insertions(+), 322 deletions(-)
xen-unstable.hg/xen/acm/acm_policy.c +178 -118
@@ -37,9 +37,9 @@static int acm_check_deleted_ssidrefs (struct acm_sized_buffer *dels,struct acm_sized_buffer *errors);static void acm_doms_change_ssidref (ssidref_t (*translator) - (const struct acm_ssid_domain *, -const struct acm_sized_buffer *), -struct acm_sized_buffer *translation_map); + (const struct acm_ssid_domain *, +const struct acm_sized_buffer *), +struct acm_sized_buffer *translation_map);static void acm_doms_restore_ssidref (void );static ssidref_t oldssid_to_newssid (const struct acm_ssid_domain *,const struct acm_sized_buffer *map);
@@ -50,15 +50,15 @@ acm_set_policy(XEN_GUEST_HANDLE_64(void) {u8 *policy_buffer =NULL ;int ret = -EFAULT ; - -if (buf_size <sizeof (struct acm_policy_buffer )) + +if ( buf_size <sizeof (struct acm_policy_buffer ) )return -EFAULT ;/* copy buffer from guest domain */ -if ((policy_buffer =xmalloc_array (u8, buf_size)) ==NULL ) +if ( (policy_buffer =xmalloc_array (u8, buf_size)) ==NULL )return -ENOMEM ; -if (copy_from_guest (policy_buffer, buf, buf_size)) +if (copy_from_guest (policy_buffer, buf, buf_size) ) {printk ("%s: Error copying!\n" ,__func__); goto error_free;
@@ -93,9 +93,8 @@ _acm_update_policy(void *buf, u32 buf_siif ( require_update !=0 && ( deletions ==NULL || ssidchanges ==NULL ) ) - { goto error_lock_free; - } + require_update =1 ;/* first some tests to check compatibility of new policy with
@@ -103,15 +102,13 @@ _acm_update_policy(void *buf, u32 buf_si*/ /* if ssidrefs are to be deleted, make sure no domain is using them */ -if (deletions !=NULL ) { -if (acm_check_deleted_ssidrefs (deletions, errors)) +if ( deletions !=NULL ) +if (acm_check_deleted_ssidrefs (deletions, errors) ) goto error_lock_free; - } -if ((ssidchanges !=NULL ) && (ssidchanges->num_items >0 )) { +if ( (ssidchanges !=NULL ) && (ssidchanges->num_items >0 ) )/* assign all running domains new ssidrefs as requested */ acm_doms_change_ssidref (oldssid_to_newssid, ssidchanges); - }/* test primary policy data with the new ssidrefs */ offset =be32_to_cpu (pol->primary_buffer_offset);
@@ -129,9 +126,8 @@ _acm_update_policy(void *buf, u32 buf_siif ( (offset + length) > buf_size || acm_secondary_ops->test_binary_policy (buf + offset, length, is_bootpolicy, - errors)) { + errors)) goto error_lock_free; - }/* end of testing --- now real updates */
@@ -140,7 +136,7 @@ _acm_update_policy(void *buf, u32 buf_si/* set label reference name */ if ( (offset + length) > buf_size || -acm_set_policy_reference (buf + offset, length) ) +acm_set_policy_reference (buf + offset, length) ) goto error_lock_free;/* set primary policy data */
@@ -161,16 +157,16 @@ _acm_update_policy(void *buf, u32 buf_si sizeof(acm_bin_pol.xml_pol_version));if ( acm_primary_ops->is_default_policy () && - acm_secondary_ops->is_default_policy () ) { + acm_secondary_ops->is_default_policy () ) require_update =0 ; - }write_unlock (&acm_bin_pol_rwlock);return ACM_OK ; error_lock_free: -if ((ssidchanges !=NULL ) && (ssidchanges->num_items >0 )) { +if ( (ssidchanges !=NULL ) && (ssidchanges->num_items >0 ) ) + {acm_doms_restore_ssidref (); }do_chwall_init_state_curr (NULL );
@@ -189,18 +185,21 @@ do_acm_set_policy(void *buf, u32 buf_sizstruct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf;/* some sanity checking */ -if ((be32_to_cpu (pol->magic) !=ACM_MAGIC ) || - (buf_size !=be32_to_cpu (pol->len)) || - (be32_to_cpu (pol->policy_version) !=ACM_POLICY_VERSION )) +if ( (be32_to_cpu (pol->magic) !=ACM_MAGIC ) || + (buf_size !=be32_to_cpu (pol->len)) || + (be32_to_cpu (pol->policy_version) !=ACM_POLICY_VERSION ) ) {printk ("%s: ERROR in Magic, Version, or buf size.\n" , __func__); goto error_free; } -if (acm_active_security_policy ==ACM_POLICY_UNDEFINED ) { +if ( acm_active_security_policy ==ACM_POLICY_UNDEFINED ) + {/* setup the policy with the boot policy */ -if (acm_init_binary_policy ((be32_to_cpu (pol->secondary_policy_code) <<4 ) | -be32_to_cpu (pol->primary_policy_code))) { +if (acm_init_binary_policy ( + (be32_to_cpu (pol->secondary_policy_code) <<4 ) | +be32_to_cpu (pol->primary_policy_code)) ) + { goto error_free; } acm_active_security_policy = (acm_bin_pol.secondary_policy_code << 4) |
@@ -208,8 +207,10 @@ do_acm_set_policy(void *buf, u32 buf_siz }/* once acm_active_security_policy is set, it cannot be changed */ -if ((be32_to_cpu (pol->primary_policy_code) != acm_bin_pol.primary_policy_code) || - (be32_to_cpu (pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code)) +if ( (be32_to_cpu (pol->primary_policy_code) != + acm_bin_pol.primary_policy_code) || + (be32_to_cpu (pol->secondary_policy_code) != + acm_bin_pol.secondary_policy_code) ) {printkd ("%s: Wrong policy type in boot policy!\n" , __func__); goto error_free;
@@ -232,18 +233,20 @@ acm_get_policy(XEN_GUEST_HANDLE_64(void)int ret;struct acm_policy_buffer *bin_pol; -if (buf_size <sizeof (struct acm_policy_buffer )) +if ( buf_size <sizeof (struct acm_policy_buffer ) )return -EFAULT ; -if ((policy_buffer =xmalloc_array (u8, buf_size)) ==NULL ) +if ( (policy_buffer =xmalloc_array (u8, buf_size)) ==NULL )return -ENOMEM ;read_lock (&acm_bin_pol_rwlock); bin_pol = (struct acm_policy_buffer *)policy_buffer; bin_pol->magic =cpu_to_be32 (ACM_MAGIC ); - bin_pol->primary_policy_code =cpu_to_be32 (acm_bin_pol.primary_policy_code); - bin_pol->secondary_policy_code =cpu_to_be32 (acm_bin_pol.secondary_policy_code); + bin_pol->primary_policy_code = +cpu_to_be32 (acm_bin_pol.primary_policy_code); + bin_pol->secondary_policy_code = +cpu_to_be32 (acm_bin_pol.secondary_policy_code); bin_pol->len =cpu_to_be32 (sizeof (struct acm_policy_buffer )); bin_pol->policy_reference_offset =cpu_to_be32 (be32_to_cpu (bin_pol->len));
@@ -254,39 +257,47 @@ acm_get_policy(XEN_GUEST_HANDLE_64(void) &acm_bin_pol.xml_pol_version, sizeof(struct acm_policy_version)); - ret =acm_dump_policy_reference (policy_buffer +be32_to_cpu (bin_pol->policy_reference_offset), - buf_size -be32_to_cpu (bin_pol->policy_reference_offset)); -if (ret <0 ) + ret =acm_dump_policy_reference ( + policy_buffer +be32_to_cpu (bin_pol->policy_reference_offset), + buf_size -be32_to_cpu (bin_pol->policy_reference_offset)); + +if ( ret <0 ) goto error_free_unlock; bin_pol->len =cpu_to_be32 (be32_to_cpu (bin_pol->len) + ret); bin_pol->primary_buffer_offset =cpu_to_be32 (be32_to_cpu (bin_pol->len)); - ret = acm_primary_ops->dump_binary_policy (policy_buffer +be32_to_cpu (bin_pol->primary_buffer_offset), - buf_size -be32_to_cpu (bin_pol->primary_buffer_offset)); -if (ret <0 ) + ret = acm_primary_ops->dump_binary_policy ( + policy_buffer +be32_to_cpu (bin_pol->primary_buffer_offset), + buf_size -be32_to_cpu (bin_pol->primary_buffer_offset)); + +if ( ret <0 ) goto error_free_unlock; bin_pol->len =cpu_to_be32 (be32_to_cpu (bin_pol->len) + ret); bin_pol->secondary_buffer_offset =cpu_to_be32 (be32_to_cpu (bin_pol->len)); - ret = acm_secondary_ops->dump_binary_policy (policy_buffer +be32_to_cpu (bin_pol->secondary_buffer_offset), - buf_size -be32_to_cpu (bin_pol->secondary_buffer_offset)); -if (ret <0 ) + ret = acm_secondary_ops->dump_binary_policy ( + policy_buffer +be32_to_cpu (bin_pol->secondary_buffer_offset), + buf_size -be32_to_cpu (bin_pol->secondary_buffer_offset)); + +if ( ret <0 ) goto error_free_unlock; bin_pol->len =cpu_to_be32 (be32_to_cpu (bin_pol->len) + ret); -if (copy_to_guest (buf, policy_buffer,be32_to_cpu (bin_pol->len))) +if (copy_to_guest (buf, policy_buffer,be32_to_cpu (bin_pol->len)) ) goto error_free_unlock;read_unlock (&acm_bin_pol_rwlock);xfree (policy_buffer); +return ACM_OK ; error_free_unlock:read_unlock (&acm_bin_pol_rwlock);printk ("%s: Error getting policy.\n" , __func__);xfree (policy_buffer); +return -EFAULT ; }
@@ -298,40 +309,50 @@ acm_dump_statistics(XEN_GUEST_HANDLE_64(int len1, len2;struct acm_stats_buffer acm_stats; -if ((stats_buffer =xmalloc_array (u8, buf_size)) ==NULL ) +if ( (stats_buffer =xmalloc_array (u8, buf_size)) ==NULL )return -ENOMEM ;read_lock (&acm_bin_pol_rwlock); - len1 = acm_primary_ops->dump_statistics (stats_buffer +sizeof (struct acm_stats_buffer ), - buf_size -sizeof (struct acm_stats_buffer )); -if (len1 <0 ) + len1 = acm_primary_ops->dump_statistics ( + stats_buffer +sizeof (struct acm_stats_buffer ), + buf_size -sizeof (struct acm_stats_buffer )); +if ( len1 <0 ) goto error_lock_free; - len2 = acm_secondary_ops->dump_statistics (stats_buffer +sizeof (struct acm_stats_buffer ) + len1, - buf_size -sizeof (struct acm_stats_buffer ) - len1); -if (len2 <0 ) + len2 = acm_secondary_ops->dump_statistics ( + stats_buffer +sizeof (struct acm_stats_buffer ) + len1, + buf_size -sizeof (struct acm_stats_buffer ) - len1); +if ( len2 <0 ) goto error_lock_free; acm_stats.magic =cpu_to_be32 (ACM_MAGIC ); - acm_stats.primary_policy_code =cpu_to_be32 (acm_bin_pol.primary_policy_code); - acm_stats.secondary_policy_code =cpu_to_be32 (acm_bin_pol.secondary_policy_code); - acm_stats.primary_stats_offset =cpu_to_be32 (sizeof (struct acm_stats_buffer )); - acm_stats.secondary_stats_offset =cpu_to_be32 (sizeof (struct acm_stats_buffer ) + len1); + acm_stats.primary_policy_code = +cpu_to_be32 (acm_bin_pol.primary_policy_code); + acm_stats.secondary_policy_code = +cpu_to_be32 (acm_bin_pol.secondary_policy_code); + acm_stats.primary_stats_offset = +cpu_to_be32 (sizeof (struct acm_stats_buffer )); + acm_stats.secondary_stats_offset = +cpu_to_be32 (sizeof (struct acm_stats_buffer ) + len1); acm_stats.len =cpu_to_be32 (sizeof (struct acm_stats_buffer ) + len1 + len2);memcpy (stats_buffer, &acm_stats,sizeof (struct acm_stats_buffer )); -if (copy_to_guest (buf, stats_buffer,sizeof (struct acm_stats_buffer ) + len1 + len2)) +if (copy_to_guest (buf, + stats_buffer, +sizeof (struct acm_stats_buffer ) + len1 + len2) ) goto error_lock_free;read_unlock (&acm_bin_pol_rwlock);xfree (stats_buffer); +return ACM_OK ; error_lock_free:read_unlock (&acm_bin_pol_rwlock);xfree (stats_buffer); +return -EFAULT ; }
@@ -343,10 +364,10 @@ acm_get_ssid(ssidref_t ssidref, XEN_GUESu8 *ssid_buffer;int ret;struct acm_ssid_buffer *acm_ssid; -if (buf_size <sizeof (struct acm_ssid_buffer )) +if ( buf_size <sizeof (struct acm_ssid_buffer ) )return -EFAULT ; -if ((ssid_buffer =xmalloc_array (u8, buf_size)) ==NULL ) +if ( (ssid_buffer =xmalloc_array (u8, buf_size)) ==NULL )return -ENOMEM ;read_lock (&acm_bin_pol_rwlock);
@@ -358,45 +379,50 @@ acm_get_ssid(ssidref_t ssidref, XEN_GUES acm_ssid->secondary_policy_code = acm_bin_pol.secondary_policy_code; acm_ssid->policy_reference_offset = acm_ssid->len; - ret =acm_dump_policy_reference (ssid_buffer + acm_ssid->policy_reference_offset, - buf_size - acm_ssid->policy_reference_offset); -if (ret <0 ) + ret =acm_dump_policy_reference ( + ssid_buffer + acm_ssid->policy_reference_offset, + buf_size - acm_ssid->policy_reference_offset); +if ( ret <0 ) goto error_free_unlock; acm_ssid->len += ret; acm_ssid->primary_types_offset = acm_ssid->len;/* ret >= 0 --> ret == max_types */ - ret = acm_primary_ops->dump_ssid_types (ACM_PRIMARY (ssidref), - ssid_buffer + acm_ssid->primary_types_offset, - buf_size - acm_ssid->primary_types_offset); -if (ret <0 ) + ret = acm_primary_ops->dump_ssid_types ( +ACM_PRIMARY (ssidref), + ssid_buffer + acm_ssid->primary_types_offset, + buf_size - acm_ssid->primary_types_offset); +if ( ret <0 ) goto error_free_unlock; acm_ssid->len += ret; acm_ssid->primary_max_types = ret; acm_ssid->secondary_types_offset = acm_ssid->len; - ret = acm_secondary_ops->dump_ssid_types (ACM_SECONDARY (ssidref), - ssid_buffer + acm_ssid->secondary_types_offset, - buf_size - acm_ssid->secondary_types_offset); -if (ret <0 ) + ret = acm_secondary_ops->dump_ssid_types ( +ACM_SECONDARY (ssidref), + ssid_buffer + acm_ssid->secondary_types_offset, + buf_size - acm_ssid->secondary_types_offset); +if ( ret <0 ) goto error_free_unlock; acm_ssid->len += ret; acm_ssid->secondary_max_types = ret; -if (copy_to_guest (buf, ssid_buffer, acm_ssid->len)) +if (copy_to_guest (buf, ssid_buffer, acm_ssid->len) ) goto error_free_unlock;read_unlock (&acm_bin_pol_rwlock);xfree (ssid_buffer); +return ACM_OK ; error_free_unlock:read_unlock (&acm_bin_pol_rwlock);printk ("%s: Error getting ssid.\n" , __func__);xfree (ssid_buffer); +return -ENOMEM ; }
@@ -404,7 +430,8 @@ int acm_get_decision(ssidref_t ssidref1, ssidref_t ssidref2, u32 hook) { int ret = ACM_ACCESS_DENIED; -switch (hook) { +switch ( hook ) + {case ACMHOOK_sharing:/* Sharing hook restricts access in STE policy only */
@@ -438,18 +465,21 @@ acm_check_used_ssidref(uint32_t policy_tread_lock (&ssid_list_rwlock); -for_each_acmssid ( rawssid ) { +for_each_acmssid ( rawssid ) + {ssidref_t ssidref;void *s =GET_SSIDP (policy_type, rawssid); -if (policy_type ==ACM_CHINESE_WALL_POLICY ) { +if ( policy_type ==ACM_CHINESE_WALL_POLICY ) + { ssidref = ((struct chwall_ssid *)s)->chwall_ssidref; }else { ssidref = ((struct ste_ssid *)s)->ste_ssidref; }gdprintk (XENLOG_INFO ,"domid=%d: search ssidref=%d, ssidref=%d\n" , rawssid->domainid,search_ssidref,ssidref); -if (ssidref == search_ssidref) { +if ( ssidref == search_ssidref ) + {/* one is enough */ acm_array_append_tuple (errors,ACM_SSIDREF_IN_USE , search_ssidref); rc =1 ;
@@ -475,10 +505,13 @@ oldssid_to_newssid(const struct acm_ssid {uint i; -if (rawssid !=NULL ) { +if ( rawssid !=NULL ) + {ssidref_t ssid = rawssid->ssidref &0xffff ; -for (i =0 ; i+1 < map->num_items; i +=2 ) { -if (map->array[i] == ssid) { +for ( i =0 ; i +1 < map->num_items; i +=2 ) + { +if ( map->array[i] == ssid ) + {return (map->array[i+1 ] <<16 | map->array[i+1 ]); } }
@@ -491,7 +524,8 @@ oldssid_to_newssid(const struct acm_ssid* Assign an ssidref to the CHWALL policy component of the domain */ static void -acm_pri_policy_assign_ssidref (struct acm_ssid_domain *rawssid,ssidref_t new_ssid) +acm_pri_policy_assign_ssidref (struct acm_ssid_domain *rawssid, +ssidref_t new_ssid) {struct chwall_ssid *chwall = (struct chwall_ssid *)rawssid->primary_ssid; chwall->chwall_ssidref = new_ssid;
@@ -502,7 +536,8 @@ acm_pri_policy_assign_ssidref(struct acm* Assign an ssidref to the STE policy component of the domain */ static void -acm_sec_policy_assign_ssidref (struct acm_ssid_domain *rawssid,ssidref_t new_ssid) +acm_sec_policy_assign_ssidref (struct acm_ssid_domain *rawssid, +ssidref_t new_ssid) {struct ste_ssid *ste = (struct ste_ssid *)rawssid->secondary_ssid; ste->ste_ssidref = new_ssid;
@@ -521,13 +556,15 @@ acm_doms_change_ssidref(ssidref_t (*tranwrite_lock (&ssid_list_rwlock); -for_each_acmssid ( rawssid ) { +for_each_acmssid ( rawssid ) + {ssidref_t new_ssid; rawssid->old_ssidref = rawssid->ssidref; new_ssid =translator_fn (rawssid, translation_map); -if (new_ssid ==ACM_INVALID_SSIDREF ) { +if ( new_ssid ==ACM_INVALID_SSIDREF ) + {/* means no mapping found, so no change -- old = new */ continue ; }
@@ -551,10 +588,11 @@ acm_doms_restore_ssidref(void)write_lock (&ssid_list_rwlock); -for_each_acmssid ( rawssid ) { +for_each_acmssid ( rawssid ) + {ssidref_t old_ssid; -if (rawssid->old_ssidref == rawssid->ssidref) +if ( rawssid->old_ssidref == rawssid->ssidref )continue ; old_ssid = rawssid->old_ssidref &0xffff ;
@@ -579,13 +617,15 @@ acm_check_deleted_ssidrefs(struct acm_siint rc =0 ;uint idx;/* check for running domains that should not be there anymore */ -for (idx =0 ; idx < dels->num_items; idx++) { -if (acm_check_used_ssidref (ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY , - dels->array[idx], - errors) >0 || -acm_check_used_ssidref (ACM_CHINESE_WALL_POLICY , - dels->array[idx], - errors) >0 ) { +for ( idx =0 ; idx < dels->num_items; idx++ ) + { +if (acm_check_used_ssidref (ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY , + dels->array[idx], + errors) >0 || +acm_check_used_ssidref (ACM_CHINESE_WALL_POLICY , + dels->array[idx], + errors) >0 ) + { rc =ACM_ERROR ;break ; }
@@ -602,46 +642,56 @@ acm_change_policy(struct acm_change_poli {int rc =0 ;u8 *binpolicy =NULL ; -struct acm_sized_buffer dels = { +struct acm_sized_buffer dels = + { .array =NULL , }; -struct acm_sized_buffer ssidmap = { +struct acm_sized_buffer ssidmap = + { .array =NULL , }; -struct acm_sized_buffer errors = { +struct acm_sized_buffer errors = + { .array =NULL , };gdprintk (XENLOG_INFO ,"change policy operation\n" ); -if ((chgpolicy->delarray_size >4096 ) || - (chgpolicy->chgarray_size >4096 ) || - (chgpolicy->errarray_size >4096 )) { +if ( (chgpolicy->delarray_size >4096 ) || + (chgpolicy->chgarray_size >4096 ) || + (chgpolicy->errarray_size >4096 )) + {return ACM_ERROR ; } dels.num_items = chgpolicy->delarray_size /sizeof (uint32_t ); -if (dels.num_items >0 ) { +if ( dels.num_items >0 ) + { dels.array =xmalloc_array (uint32_t, dels.num_items); -if (dels.array ==NULL ) { +if ( dels.array ==NULL ) + { rc = -ENOMEM ; goto acm_chg_policy_exit; } } ssidmap.num_items = chgpolicy->chgarray_size /sizeof (uint32_t ); -if (ssidmap.num_items >0 ) { +if ( ssidmap.num_items >0 ) + { ssidmap.array =xmalloc_array (uint32_t, ssidmap.num_items); -if (ssidmap.array ==NULL ) { +if ( ssidmap.array ==NULL ) + { rc = -ENOMEM ; goto acm_chg_policy_exit; } } errors.num_items = chgpolicy->errarray_size /sizeof (uint32_t ); -if (errors.num_items >0 ) { +if ( errors.num_items >0 ) + { errors.array =xmalloc_array (uint32_t, errors.num_items); -if (errors.array ==NULL ) { +if ( errors.array ==NULL ) + { rc = -ENOMEM ; goto acm_chg_policy_exit; }
@@ -650,7 +700,8 @@ acm_change_policy(struct acm_change_poli binpolicy =xmalloc_array (u8, chgpolicy->policy_pushcache_size); -if (binpolicy ==NULL ) { +if ( binpolicy ==NULL ) + { rc = -ENOMEM ; goto acm_chg_policy_exit; }
@@ -663,7 +714,8 @@ acm_change_policy(struct acm_change_poli chgpolicy->chgarray_size) || copy_from_guest(binpolicy, chgpolicy->policy_pushcache, - chgpolicy->policy_pushcache_size )) { + chgpolicy->policy_pushcache_size )) + { rc = -EFAULT ; goto acm_chg_policy_exit; }
@@ -676,7 +728,8 @@ acm_change_policy(struct acm_change_poliif ( (errors.num_items >0 ) &©_to_guest (chgpolicy->err_array, errors.array, - errors.num_items ) ) { + errors.num_items ) ) + { rc = -EFAULT ; goto acm_chg_policy_exit; }
@@ -703,10 +756,10 @@ domid_to_newssid(const struct acm_ssid_d {domid_t domid = rawssid->domainid;uint i; -for (i =0 ; (i+1 ) < map->num_items; i +=2 ) { -if (map->array[i] == domid) { +for ( i =0 ; (i+1 ) < map->num_items; i +=2 ) + { +if ( map->array[i] == domid )return (ssidref_t )map->array[i+1 ]; - } }return ACM_INVALID_SSIDREF ; }
@@ -725,7 +778,8 @@ do_acm_relabel_doms(struct acm_sized_buf/* run tests; collect as much error info as possible */ irc =do_chwall_init_state_curr (errors); irc +=do_ste_init_state_curr (errors); -if (irc !=0 ) { +if ( irc !=0 ) + { rc = -EFAULT ; goto acm_relabel_doms_lock_err_exit; }
@@ -749,30 +803,37 @@ int acm_relabel_domains(struct acm_relabel_doms *relabel) {int rc =ACM_OK ; -struct acm_sized_buffer relabels = { +struct acm_sized_buffer relabels = + { .array =NULL , }; -struct acm_sized_buffer errors = { +struct acm_sized_buffer errors = + { .array =NULL , }; -if (relabel->relabel_map_size >4096 ) { +if ( relabel->relabel_map_size >4096 ) + {return ACM_ERROR ; } relabels.num_items = relabel->relabel_map_size /sizeof (uint32_t ); -if (relabels.num_items >0 ) { +if ( relabels.num_items >0 ) + { relabels.array =xmalloc_array (uint32_t, relabels.num_items); -if (relabels.array ==NULL ) { +if ( relabels.array ==NULL ) + { rc = -ENOMEM ; goto acm_relabel_doms_exit; } } errors.num_items = relabel->errarray_size /sizeof (uint32_t ); -if (errors.num_items >0 ) { +if ( errors.num_items >0 ) + { errors.array =xmalloc_array (uint32_t, errors.num_items); -if (errors.array ==NULL ) { +if ( errors.array ==NULL ) + { rc = -ENOMEM ; goto acm_relabel_doms_exit; }
@@ -781,7 +842,8 @@ acm_relabel_domains(struct acm_relabel_dif (copy_from_guest (relabels.array, relabel->relabel_map, - relabel->relabel_map_size) ) { + relabel->relabel_map_size) ) + { rc = -EFAULT ; goto acm_relabel_doms_exit; }
@@ -790,10 +852,8 @@ acm_relabel_domains(struct acm_relabel_dif (copy_to_guest (relabel->err_array, errors.array, - errors.num_items ) ) { + errors.num_items ) ) rc = -EFAULT ; - goto acm_relabel_doms_exit; - } acm_relabel_doms_exit:xfree (relabels.array);
xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c +159 -91
532 lines not on this page · raw message
traceprintk("%s: dom%x-->dom%x.\n", __func__,
@@ -628,17 +696,21 @@ ste_pre_eventchannel_interdomain(domid_t
/* following is a bit longer but ensures that we
* "put" only domains that we where "find"-ing
*/- if (id == DOMID_SELF) id = current->domain->domain_id;
+ if ( id == DOMID_SELF )
+ id = current->domain->domain_id;
subj = current->domain;
obj = rcu_lock_domain_by_id(id);
- if (obj == NULL) {
+
+ if ( obj == NULL )
+ {
ret = ACM_ACCESS_DENIED;
goto out;
}
/* cache check late, but evtchn is not on performance critical path */
- if (check_cache(subj, obj->domain_id)) {
+ if ( check_cache(subj, obj->domain_id) )
+ {
atomic_inc(&ste_bin_pol.ec_cachehit_count);
ret = ACM_ACCESS_PERMITTED;
goto out;@@ -646,7 +718,8 @@ ste_pre_eventchannel_interdomain(domid_t
atomic_inc(&ste_bin_pol.ec_eval_count);
- if (share_common_type(subj, obj)) {
+ if ( share_common_type(subj, obj) )
+ {
cache_result(subj, obj);
ret = ACM_ACCESS_PERMITTED;
} else {
@@ -654,29 +727,35 @@ ste_pre_eventchannel_interdomain(domid_t
ret = ACM_ACCESS_DENIED;
}
out:
- if (obj != NULL)
+ if ( obj != NULL )
rcu_unlock_domain(obj);
+
return ret;}
/* -------- SHARED MEMORY OPERATIONS -----------*/
static int
-ste_pre_grant_map_ref (domid_t id) {
+ste_pre_grant_map_ref (domid_t id)
+{
struct domain *obj, *subj;
int ret;
+
traceprintk("%s: dom%x-->dom%x.\n", __func__,
current->domain->domain_id, id);- if (check_cache(current->domain, id)) {
+ if ( check_cache(current->domain, id) )
+ {
atomic_inc(&ste_bin_pol.gt_cachehit_count);
return ACM_ACCESS_PERMITTED;
}
+
atomic_inc(&ste_bin_pol.gt_eval_count);
subj = current->domain;
obj = rcu_lock_domain_by_id(id);- if (share_common_type(subj, obj)) {
+ if ( share_common_type(subj, obj) )
+ {
cache_result(subj, obj);
ret = ACM_ACCESS_PERMITTED;
} else {
@@ -684,8 +763,10 @@ ste_pre_grant_map_ref (domid_t id) {
printkd("%s: ACCESS DENIED!\n", __func__);
ret = ACM_ACCESS_DENIED;
}
- if (obj != NULL)
+
+ if ( obj != NULL )
rcu_unlock_domain(obj);
+
return ret;}
@@ -700,29 +781,37 @@ ste_pre_grant_setup (domid_t id) {
traceprintk("%s: dom%x-->dom%x.\n", __func__,
current->domain->domain_id, id);- if (check_cache(current->domain, id)) {
+ if ( check_cache(current->domain, id) )
+ {
atomic_inc(&ste_bin_pol.gt_cachehit_count);
return ACM_ACCESS_PERMITTED;
}
+
atomic_inc(&ste_bin_pol.gt_eval_count);
+
/* a) check authorization (eventually use specific capabilities) */- if (!IS_PRIV(current->domain)) {
- printk("%s: Grant table management authorization denied ERROR!\n", __func__);
+ if ( !IS_PRIV(current->domain) )
+ {
+ printk("%s: Grant table management authorization denied ERROR!\n",
+ __func__);
return ACM_ACCESS_DENIED;
}
/* b) check types */
subj = current->domain;
obj = rcu_lock_domain_by_id(id);- if (share_common_type(subj, obj)) {
+ if ( share_common_type(subj, obj) )
+ {
cache_result(subj, obj);
ret = ACM_ACCESS_PERMITTED;
} else {
atomic_inc(&ste_bin_pol.gt_denied_count);
ret = ACM_ACCESS_DENIED;
}
- if (obj != NULL)
+
+ if ( obj != NULL )
rcu_unlock_domain(obj);
+
return ret;}
@@ -730,10 +819,10 @@ ste_pre_grant_setup (domid_t id) {
static int
ste_sharing(ssidref_t ssidref1, ssidref_t ssidref2) {
- if (have_common_type (
- GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref1), - GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref2) - ))
+ if ( have_common_type (
+ GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref1),
+ GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref2)
+ ))
return ACM_ACCESS_PERMITTED;
else
return ACM_ACCESS_DENIED;@@ -749,26 +838,26 @@ ste_is_default_policy(void)
}
/* now define the hook structure similarly to LSM */
-struct acm_operations acm_simple_type_enforcement_ops = { -
+struct acm_operations acm_simple_type_enforcement_ops = +{
/* policy management services */ .init_domain_ssid = ste_init_domain_ssid, .free_domain_ssid = ste_free_domain_ssid,
.dump_binary_policy = ste_dump_policy,
.test_binary_policy = ste_test_policy,
.set_binary_policy = ste_set_policy,
- .dump_statistics = ste_dump_stats,
+ .dump_statistics = ste_dump_stats,
.dump_ssid_types = ste_dump_ssid_types,
/* domain management control hooks */
- .domain_create = ste_domain_create,
+ .domain_create = ste_domain_create,
.domain_destroy = ste_domain_destroy,
/* event channel control hooks */
- .pre_eventchannel_unbound = ste_pre_eventchannel_unbound, - .fail_eventchannel_unbound = NULL, - .pre_eventchannel_interdomain = ste_pre_eventchannel_interdomain, - .fail_eventchannel_interdomain = NULL, + .pre_eventchannel_unbound = ste_pre_eventchannel_unbound, + .fail_eventchannel_unbound = NULL, + .pre_eventchannel_interdomain = ste_pre_eventchannel_interdomain, + .fail_eventchannel_interdomain = NULL,
/* grant table control hooks */
.pre_grant_map_ref = ste_pre_grant_map_ref,
xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c +91 -87
407 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel