Enable updating policy on running system
RFC PATCH 1/1 Enable updating policy on running system
Keir,
as part of the effort to make ACM functionality available via the
Xen-API, we are adding further functionality to the ACM module in the hypervisor. One of these functions is to be able to update a running system with a modified policy. The update is happening in several steps:
relabeling of the domains, testing against the current state of the system, committing the changes. During that time it is necessary that no other domain be created. I am currently using the domlist_update_lock (see DOM_CREATE_LOCK define in the patch) to prevent other domains from being added to the system while the update is happening. This is not the correct lock to use, though, and I'd rather like to use domctl_lock in do_domctl, because that will prevent a domain from being 'created' and not just 'added to the list'. So would it be possible to make this lock globally available since it is currently a local lock only accessible from within do_domctl or are there other ways to achieve this?
Thanks.
Stefan
--- xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c | 148 ++- xen-unstable.hg/xen/acm/acm_core.c | 3 xen-unstable.hg/xen/acm/acm_null_hooks.c | 10 xen-unstable.hg/xen/acm/acm_policy.c | 539 +++++++++++- xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c | 120 +- xen-unstable.hg/xen/common/acm_ops.c | 36 xen-unstable.hg/xen/include/acm/acm_core.h | 49 - xen-unstable.hg/xen/include/acm/acm_hooks.h | 6 xen-unstable.hg/xen/include/public/acm.h | 13 xen-unstable.hg/xen/include/public/acm_ops.h | 30 10 files changed, 830 insertions(+), 124 deletions(-)
xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c +106 -42
@@ -183,23 +183,26 @@ static int chwall_dump_policy(u8 * buf,return ret; } -/* adapt security state (running_types and conflict_aggregate_set) to all running -* domains; chwall_init_state is called when a policy is changed to bring the security -* information into a consistent state and to detect violations (return != 0). -* from a security point of view, we simulate that all running domains are re-started +/* +* Adapt security state (running_types and conflict_aggregate_set) to all +* running domains; chwall_init_state is called when a policy is changed +* to bring the security information into a consistent state and to detect +* violations (return != 0) from a security point of view, we simulate +* that all running domains are re-started */ static int chwall_init_state (struct acm_chwall_policy_buffer *chwall_buf, -domaintype_t * ssidrefs,domaintype_t * conflict_sets, +domaintype_t * ssidrefs, +domaintype_t * conflict_sets,domaintype_t * running_types, -domaintype_t * conflict_aggregate_set) +domaintype_t * conflict_aggregate_set, +struct acm_sized_buffer *errors/* may be NULL */ ) {int violation =0 , i, j;struct chwall_ssid *chwall_ssid;ssidref_t chwall_ssidref;struct domain *d; -spin_lock (&domlist_update_lock);/* go through all domains and adjust policy as if this domain was started now */ for_each_domain ( d ) {
@@ -222,6 +225,9 @@ chwall_init_state(struct acm_chwall_poliprintk ("%s: CHINESE WALL CONFLICT in type %02x.\n" , __func__, i); violation =1 ; + +acm_array_append_tuple (errors,ACM_CHWALL_CONFLICT , i); + goto out; }/* set violation and break out of the loop */
@@ -249,7 +255,6 @@ chwall_init_state(struct acm_chwall_poli } } out: -spin_unlock (&domlist_update_lock);return violation;/* returning "violation != 0" means that the currently running set of domains would * not be possible if the new policy had been enforced before starting them; for chinese
@@ -257,44 +262,45 @@ chwall_init_state(struct acm_chwall_poli* more than one type is currently running */ } -static int chwall_set_policy (u8 * buf,u32 buf_size,int is_bootpolicy) + +int +do_chwall_init_state_curr (struct acm_sized_buffer *errors) +{ +struct acm_chwall_policy_buffer chwall_buf = { +/* only these two are important */ + .chwall_max_types = chwall_bin_pol.max_types, + .chwall_max_conflictsets = chwall_bin_pol.max_conflictsets, + }; +/* reset running_types and aggregate set for recalculation */ +memset (chwall_bin_pol.running_types, +0x0 , +sizeof (domaintype_t) * chwall_bin_pol.max_types); +memset (chwall_bin_pol.conflict_aggregate_set, +0x0 , +sizeof (domaintype_t) * chwall_bin_pol.max_types); +return chwall_init_state (&chwall_buf, + chwall_bin_pol.ssidrefs, + chwall_bin_pol.conflict_sets, + chwall_bin_pol.running_types, + chwall_bin_pol.conflict_aggregate_set, + errors); +} + +/* +* Attempt to set the policy. This function must be called in test_only +* mode first to only perform checks. A second call then does the +* actual changes. +*/ +static int _chwall_update_policy (u8 *buf,u32 buf_size,int test_only, +struct acm_sized_buffer *errors) { +int rc = -EFAULT ;/* policy write-locked already */ struct acm_chwall_policy_buffer *chwall_buf = (struct acm_chwall_policy_buffer *) buf;void *ssids =NULL , *conflict_sets =NULL , *running_types =NULL , *conflict_aggregate_set =NULL ; -if (buf_size <sizeof (struct acm_chwall_policy_buffer )) -return -EINVAL ; - -/* rewrite the policy due to endianess */ - chwall_buf->policy_code =be32_to_cpu (chwall_buf->policy_code); - chwall_buf->policy_version =be32_to_cpu (chwall_buf->policy_version); - chwall_buf->chwall_max_types =be32_to_cpu (chwall_buf->chwall_max_types); - chwall_buf->chwall_max_ssidrefs = -be32_to_cpu (chwall_buf->chwall_max_ssidrefs); - chwall_buf->chwall_max_conflictsets = -be32_to_cpu (chwall_buf->chwall_max_conflictsets); - chwall_buf->chwall_ssid_offset =be32_to_cpu (chwall_buf->chwall_ssid_offset); - chwall_buf->chwall_conflict_sets_offset = -be32_to_cpu (chwall_buf->chwall_conflict_sets_offset); - chwall_buf->chwall_running_types_offset = -be32_to_cpu (chwall_buf->chwall_running_types_offset); - chwall_buf->chwall_conflict_aggregate_offset = -be32_to_cpu (chwall_buf->chwall_conflict_aggregate_offset); - -/* policy type and version checks */ -if ((chwall_buf->policy_code !=ACM_CHINESE_WALL_POLICY ) || - (chwall_buf->policy_version !=ACM_CHWALL_VERSION )) -return -EINVAL ; - -/* during boot dom0_chwall_ssidref is set */ -if (is_bootpolicy && - (dom0_chwall_ssidref >= chwall_buf->chwall_max_ssidrefs)) { - goto error_free; - } -/* 1. allocate new buffers */ ssids = xmalloc_array(domaintype_t,
@@ -343,12 +349,20 @@ static int chwall_set_policy(u8 * buf, u* this can fail if new policy is conflicting with running domains */ if (chwall_init_state (chwall_buf, ssids, conflict_sets, running_types, - conflict_aggregate_set)) + conflict_aggregate_set, + errors)) {printk ("%s: New policy conflicts with running domains. Policy load aborted.\n" , __func__); goto error_free;/* new policy conflicts with running domains */ } + +/* if this was only a test run, exit with ACM_OK */ +if (test_only) { + rc =ACM_OK ; + goto error_free; + } +/* 4. free old policy buffers, replace with new ones */ chwall_bin_pol.max_types = chwall_buf->chwall_max_types; chwall_bin_pol.max_ssidrefs = chwall_buf->chwall_max_ssidrefs;
@@ -364,12 +378,61 @@ static int chwall_set_policy(u8 * buf, ureturn ACM_OK ; error_free: -printk ("%s: ERROR setting policy.\n" , __func__); +if (!test_only)printk ("%s: ERROR setting policy.\n" , __func__);xfree (ssids);xfree (conflict_sets);xfree (running_types);xfree (conflict_aggregate_set); -return -EFAULT ; +return rc; +} + +/* +* This function MUST be called before the chwall_ste_policy function! +*/ +static int chwall_test_policy (u8 *buf,u32 buf_size,int is_bootpolicy, +struct acm_sized_buffer *errors) +{ +struct acm_chwall_policy_buffer *chwall_buf = + (struct acm_chwall_policy_buffer *) buf; + +if (buf_size <sizeof (struct acm_chwall_policy_buffer )) +return -EINVAL ; + +/* rewrite the policy due to endianess */ + chwall_buf->policy_code =be32_to_cpu (chwall_buf->policy_code); + chwall_buf->policy_version =be32_to_cpu (chwall_buf->policy_version); + chwall_buf->chwall_max_types = +be32_to_cpu (chwall_buf->chwall_max_types); + chwall_buf->chwall_max_ssidrefs = +be32_to_cpu (chwall_buf->chwall_max_ssidrefs); + chwall_buf->chwall_max_conflictsets = +be32_to_cpu (chwall_buf->chwall_max_conflictsets); + chwall_buf->chwall_ssid_offset = +be32_to_cpu (chwall_buf->chwall_ssid_offset); + chwall_buf->chwall_conflict_sets_offset = +be32_to_cpu (chwall_buf->chwall_conflict_sets_offset); + chwall_buf->chwall_running_types_offset = +be32_to_cpu (chwall_buf->chwall_running_types_offset); + chwall_buf->chwall_conflict_aggregate_offset = +be32_to_cpu (chwall_buf->chwall_conflict_aggregate_offset); + +/* policy type and version checks */ +if ((chwall_buf->policy_code !=ACM_CHINESE_WALL_POLICY ) || + (chwall_buf->policy_version !=ACM_CHWALL_VERSION )) +return -EINVAL ; + +/* during boot dom0_chwall_ssidref is set */ +if (is_bootpolicy && + (dom0_chwall_ssidref >= chwall_buf->chwall_max_ssidrefs)) +return -EINVAL ; + + +return _chwall_update_policy (buf, buf_size,1 , errors); +} + +static int chwall_set_policy (u8 *buf,u32 buf_size) +{ +return _chwall_update_policy (buf, buf_size,0 ,NULL ); }static int chwall_dump_stats (u8 * buf,u16 len)
@@ -610,6 +673,7 @@ struct acm_operations acm_chinesewall_op .init_domain_ssid = chwall_init_domain_ssid, .free_domain_ssid = chwall_free_domain_ssid, .dump_binary_policy = chwall_dump_policy, + .test_binary_policy = chwall_test_policy, .set_binary_policy = chwall_set_policy, .dump_statistics = chwall_dump_stats, .dump_ssid_types = chwall_dump_ssid_types,
xen-unstable.hg/xen/acm/acm_core.c +2 -1
@@ -249,7 +249,8 @@ acm_setup(char *policy_start,return rc; rc =do_acm_set_policy ((void *)policy_start, (u32 )policy_len, - is_bootpolicy); + is_bootpolicy, +NULL ,NULL ,NULL );if (rc ==ACM_OK ) {printkd ("Policy len 0x%lx, start at %p.\n" ,policy_len,policy_start);
xen-unstable.hg/xen/acm/acm_null_hooks.c +9 -1
@@ -33,7 +33,14 @@ null_dump_binary_policy(u8 *buf, u32 buf }static int -null_set_binary_policy (u8 *buf,u32 buf_size,int is_bootpolicy) +null_test_binary_policy (u8 *buf,u32 buf_size,int is_bootpolicy, +struct acm_sized_buffer *errors) +{ +return ACM_OK ; +} + +static int +null_set_binary_policy (u8 *buf,u32 buf_size) {return ACM_OK ; }
@@ -58,6 +65,7 @@ struct acm_operations acm_null_ops = { .init_domain_ssid = null_init_domain_ssid, .free_domain_ssid = null_free_domain_ssid, .dump_binary_policy = null_dump_binary_policy, + .test_binary_policy = null_test_binary_policy, .set_binary_policy = null_set_binary_policy, .dump_statistics = null_dump_stats, .dump_ssid_types = null_dump_ssid_types,
xen-unstable.hg/xen/acm/acm_policy.c +123 -36
222 lines not on this page · raw message
return -EFAULT;
@@ -156,7 +243,7 @@ acm_get_policy(XEN_GUEST_HANDLE(void) bu
bin_pol->policy_reference_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
bin_pol->primary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
bin_pol->secondary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
-
+
memcpy(&bin_pol->xml_pol_version,
&acm_bin_pol.xml_pol_version,
sizeof(struct acm_policy_version));
@@ -330,6 +417,384 @@ acm_get_decision(ssidref_t ssidref1, ssi
return ret;}
+
+/*
+ Check if an ssidref of the current policy type is being used by any + domain. + The caller must hold the lock to the domain list.
+ */
+static int
+acm_check_used_ssidref(uint32_t policy_type, uint32_t idx,
+ struct acm_sized_buffer *errors)
+{
+ int rc = 0;
+ struct domain *d;
+
+ for_each_domain(d) {
+ struct acm_ssid_domain *rawssid; + ssidref_t ssidref; + void *s;
+
+ rawssid = (struct acm_ssid_domain *)d->ssid;
+
+ if (rawssid == NULL)
+ continue;
+
+ s = GET_SSIDP(policy_type, rawssid);
+ 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: idx=%d, ssidref=%d\n",
+ idx,ssidref,d->domain_id);
+ if (ssidref == idx) {
+ /* one is enough */ + acm_array_append_tuple(errors, ACM_SSIDREF_IN_USE, idx); + rc = 1; + break;
+ }
+ }
+ return rc;
+}
+
+
+/*
+ * Translate a current ssidref into its future representation under
+ * the new policy.
+ * The map provides translation of ssidrefs from old to new in tuples
+ * of (old ssidref, new ssidref).
+ */
+static ssidref_t
+oldssid_to_newssid(const struct domain *d, const struct acm_sized_buffer *map) +{
+ uint i;
+ struct acm_ssid_domain *rawssid = (struct acm_ssid_domain *)d->ssid;
+
+ if (rawssid != NULL) {
+ ssidref_t ssid = rawssid->ssidref & 0xffff;
+ 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]);
+ }
+ }
+ }
+ return ACM_INVALID_SSIDREF;
+}
+
+
+/*
+ * Assign an ssidref to the CHWALL policy component of the domain
+ */
+static void
+acm_pri_policy_assign_ssidref(struct domain *d, ssidref_t new_ssid) +{
+ struct acm_ssid_domain *rawssid = (struct acm_ssid_domain *)d->ssid;
+ struct chwall_ssid *chwall;
+
+ chwall = (struct chwall_ssid *)rawssid->primary_ssid;
+ chwall->chwall_ssidref = new_ssid;
+}
+
+
+/*
+ * Assign an ssidref to the STE policy component of the domain
+ */
+static void
+acm_sec_policy_assign_ssidref(struct domain *d, ssidref_t new_ssid) +{
+ struct acm_ssid_domain *rawssid = (struct acm_ssid_domain *)d->ssid;
+ struct ste_ssid *ste;
+
+ ste = (struct ste_ssid *)rawssid->secondary_ssid;
+ ste->ste_ssidref = new_ssid;
+}
+
+/*
+ change the ssidrefs on each domain using a passed translation function;
+ The caller must hold the write-lock to the domain list
+ */
+static void
+acm_doms_change_ssidref(ssidref_t (*translator_fn)
+ (const struct domain *,
+ const struct acm_sized_buffer *),
+ struct acm_sized_buffer *translation_map)
+{
+ struct domain *d;
+ for_each_domain(d) {
+ ssidref_t new_ssid;
+ struct acm_ssid_domain *rawssid = (struct acm_ssid_domain *)d->ssid;
+
+ rawssid->old_ssidref = rawssid->ssidref;
+
+ new_ssid = translator_fn(d, translation_map);
+ if (new_ssid == ACM_INVALID_SSIDREF) {
+ /* means no mapping found, so no change -- old = new */
+ continue;
+ }
+
+ acm_pri_policy_assign_ssidref(d, ACM_PRIMARY (new_ssid) );
+ acm_sec_policy_assign_ssidref(d, ACM_SECONDARY(new_ssid) );
+
+ rawssid->ssidref = new_ssid;
+ }
+}
+
+/*
+ * Restore the previous ssidref values on all domains
+ */
+static void
+acm_doms_restore_ssidref(void)
+{
+ struct domain *d;
+ for_each_domain(d) {
+ struct acm_ssid_domain *rawssid;
+ ssidref_t old_ssid;
+
+ rawssid = (struct acm_ssid_domain *)d->ssid;
+
+ if (rawssid == NULL ||
+ rawssid->old_ssidref == rawssid->ssidref)
+ continue;
+
+ old_ssid = rawssid->old_ssidref & 0xffff;
+ rawssid->ssidref = rawssid->old_ssidref;
+
+ acm_pri_policy_assign_ssidref(d, old_ssid);
+ acm_sec_policy_assign_ssidref(d, old_ssid);
+ }
+}
+
+/*
+ Check the list of domains whether either one of them uses a + to-be-deleted ssidref. + The caller must hold the lock to the domain list.
+ */
+static int
+acm_check_deleted_ssidrefs(struct acm_sized_buffer *dels,
+ struct acm_sized_buffer *errors)
+{
+ int 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) {
+ rc = ACM_ERROR;
+ break;
+ }
+ }
+ return rc;
+}
+
+
+/*
+ * Change the policy of the system.
+ */
+int
+acm_change_policy(struct acm_change_policy *chgpolicy) +{
+ int rc = 0;
+ u8 *binpolicy = NULL;
+ struct acm_sized_buffer dels = {+ .array = NULL,
+ };
+ struct acm_sized_buffer ssidmap = {
+ .array = NULL,
+ };
+ 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)) {
+ return ACM_ERROR;
+ }
+
+ dels.num_items = chgpolicy->delarray_size / sizeof(uint32_t);
+ if (dels.num_items > 0) {
+ dels.array = xmalloc_array(uint32_t, dels.num_items);
+ 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) {
+ ssidmap.array = xmalloc_array(uint32_t, ssidmap.num_items);
+ 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) {
+ errors.array = xmalloc_array(uint32_t, errors.num_items);
+ if (errors.array == NULL) {
+ rc = -ENOMEM;
+ goto acm_chg_policy_exit;
+ }
+ memset(errors.array, 0x0, sizeof(uint32_t) * errors.num_items);
+ }
+
+ binpolicy = xmalloc_array(u8,
+ chgpolicy->policy_pushcache_size);
+ if (binpolicy == NULL) {
+ rc = -ENOMEM;
+ goto acm_chg_policy_exit;
+ }
+
+ if ( copy_from_guest(dels.array,
+ chgpolicy->del_array,
+ chgpolicy->delarray_size) ||
+ copy_from_guest(ssidmap.array,
+ chgpolicy->chg_array,
+ chgpolicy->chgarray_size) ||
+ copy_from_guest(binpolicy,
+ chgpolicy->policy_pushcache,
+ chgpolicy->policy_pushcache_size )) {
+ rc = -EFAULT;
+ goto acm_chg_policy_exit;
+ }
+
+ rc = do_acm_set_policy(binpolicy,
+ chgpolicy->policy_pushcache_size, + 0, + &dels, &ssidmap, &errors);
+
+ if ( (errors.num_items > 0) &&
+ copy_to_guest(chgpolicy->err_array,
+ errors.array,
+ errors.num_items ) ) {
+ rc = -EFAULT;
+ goto acm_chg_policy_exit;
+ }
+
+
+acm_chg_policy_exit:
+ xfree(dels.array); + xfree(ssidmap.array); + xfree(errors.array); + xfree(binpolicy);
+
+ return rc;
+}
+
+
+/*
+ * Lookup the new ssidref given the domain's id.
+ * The translation map provides a list of tuples in the format
+ * (domid, new ssidref).
+ */
+static ssidref_t
+domid_to_newssid(const struct domain *d, const struct acm_sized_buffer *map) +{
+ domid_t domid = d->domain_id;
+ uint i;
+ 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;
+}
+
+
+int
+do_acm_relabel_doms(struct acm_sized_buffer *relabel_map,
+ struct acm_sized_buffer *errors)
+{
+ int rc = 0, irc;
+
+ DOM_CREATE_LOCK
+
+ acm_doms_change_ssidref(domid_to_newssid, relabel_map);
+
+ /* 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) {+ rc = -EFAULT;
+ goto acm_relabel_doms_lock_err_exit;
+ }
+
+ DOM_CREATE_UNLOCK
+ return rc;
+
+acm_relabel_doms_lock_err_exit:
+ /* revert the new ssidref assignment */ + acm_doms_restore_ssidref(); + do_chwall_init_state_curr(NULL);
+
+ DOM_CREATE_UNLOCK
+
+ return rc;
+}
+
+
+int
+acm_relabel_domains(struct acm_relabel_doms *relabel) +{
+ int rc = ACM_OK; + struct acm_sized_buffer relabels; + struct acm_sized_buffer errors; + relabels.array = NULL; + errors.array = NULL;
+
+ if (relabel->relabel_map_size > 4096) {
+ return ACM_ERROR;
+ }
+
+ relabels.num_items = relabel->relabel_map_size / sizeof(uint32_t);
+ if (relabels.num_items > 0) {
+ relabels.array = xmalloc_array(uint32_t, relabels.num_items);
+ 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) {
+ errors.array = xmalloc_array(uint32_t, errors.num_items);
+ if (errors.array == NULL) {
+ rc = -ENOMEM;
+ goto acm_relabel_doms_exit;
+ }
+ memset(errors.array, 0x0, sizeof(uint32_t) * errors.num_items);
+ }
+
+ if ( copy_from_guest(relabels.array,
+ relabel->relabel_map,
+ relabel->relabel_map_size) ) {
+ rc = -EFAULT;
+ goto acm_relabel_doms_exit;
+ }
+
+ rc = do_acm_relabel_doms(&relabels, &errors);
+
+ if ( copy_to_guest(relabel->err_array,
+ errors.array,
+ errors.num_items ) ) {
+ rc = -EFAULT;
+ goto acm_relabel_doms_exit;
+ }
+
+acm_relabel_doms_exit:
+ xfree(relabels.array); + xfree(errors.array); + return rc;
+}
+
/*
* Local variables:
* mode: C
xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c +87 -33
213 lines not on this page · raw message
xen-unstable.hg/xen/common/acm_ops.c +36 -0
@@ -216,6 +216,42 @@ ret_t do_acm_op(int cmd, XEN_GUEST_HANDLbreak ; } +case ACMOP_chgpolicy: { +struct acm_change_policy chgpolicy; + +if (copy_from_guest (&chgpolicy, arg,1 ) !=0 ) +return -EFAULT ; +if (chgpolicy.interface_version !=ACM_INTERFACE_VERSION ) +return -EACCES ; + + rc =acm_change_policy (&chgpolicy); + +if (rc ==0 ) { +if (copy_to_guest (arg, &chgpolicy,1 ) !=0 ) { + rc = -EFAULT ; + } + } +break ; + } + +case ACMOP_relabeldoms: { +struct acm_relabel_doms relabeldoms; + +if (copy_from_guest (&relabeldoms, arg,1 ) !=0 ) +return -EFAULT ; +if (relabeldoms.interface_version !=ACM_INTERFACE_VERSION ) +return -EACCES ; + + rc =acm_relabel_domains (&relabeldoms); + +if (rc ==0 ) { +if (copy_to_guest (arg, &relabeldoms,1 ) !=0 ) { + rc = -EFAULT ; + } + } +break ; + } +default : rc = -ENOSYS ;break ;
xen-unstable.hg/xen/include/acm/acm_core.h +42 -7
78 lines not on this page · raw message
xen-unstable.hg/xen/include/acm/acm_hooks.h +4 -2
@@ -91,8 +91,10 @@ struct acm_operations {int (*init_domain_ssid) (void **ssid,ssidref_t ssidref);void (*free_domain_ssid) (void *ssid);int (*dump_binary_policy) (u8 *buffer,u32 buf_size); -int (*set_binary_policy) (u8 *buffer,u32 buf_size, -int is_bootpolicy); +int (*test_binary_policy) (u8 *buffer,u32 buf_size, +int is_bootpolicy, +struct acm_sized_buffer *); +int (*set_binary_policy) (u8 *buffer,u32 buf_size);int (*dump_statistics) (u8 *buffer,u16 buf_size);int (*dump_ssid_types) (ssidref_t ssidref,u8 *buffer,u16 buf_size);/* domain management control hooks (can be NULL) */
xen-unstable.hg/xen/include/public/acm.h +13 -0
@@ -56,6 +56,19 @@#define ACM_ACCESS_DENIED -111#define ACM_NULL_POINTER_ERROR -200 +/* +Error codes reported in when trying to test for a new policy +These error codes are reported in an array of tuples where +each error code is followed by a parameter describing the error +more closely, such as a domain id. +*/ +#define ACM_EVTCHN_SHARING_VIOLATION 0x100 +#define ACM_GNTTAB_SHARING_VIOLATION 0x101 +#define ACM_DOMAIN_LOOKUP 0x102 +#define ACM_CHWALL_CONFLICT 0x103 +#define ACM_SSIDREF_IN_USE 0x104 + +/* primary policy in lower 4 bits */ #define ACM_NULL_POLICY 0#define ACM_CHINESE_WALL_POLICY 1
xen-unstable.hg/xen/include/public/acm_ops.h +29 -1
@@ -34,7 +34,7 @@* This makes sure that old versions of acm tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define ACM_INTERFACE_VERSION 0xAAAA0008 +#define ACM_INTERFACE_VERSION 0xAAAA0009/************************************************************************/
@@ -107,6 +107,34 @@ struct acm_getdecision { uint32_t acm_decision; }; + +#define ACMOP_chgpolicy 6 +struct acm_change_policy { +/* IN */ +uint32_t interface_version; +XEN_GUEST_HANDLE (void ) policy_pushcache; +uint32_t policy_pushcache_size; +XEN_GUEST_HANDLE (void ) del_array; +uint32_t delarray_size; +XEN_GUEST_HANDLE (void ) chg_array; +uint32_t chgarray_size; +/* OUT */ +/* array with error code */ +XEN_GUEST_HANDLE (void ) err_array; +uint32_t errarray_size; +}; + +#define ACMOP_relabeldoms 7 +struct acm_relabel_doms { +/* IN */ +uint32_t interface_version; +XEN_GUEST_HANDLE (void ) relabel_map; +uint32_t relabel_map_size; +/* OUT */ +XEN_GUEST_HANDLE (void ) err_array; +uint32_t errarray_size; +}; +#endif /* __XEN_PUBLIC_ACM_OPS_H__ */ /*
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Is there now some consensus on how to add security features to XenAPI that does not cause conflict between XSM and ACM?
Anyway, in response to your main question, I wonder what you actually need to serialise against? Is it sufficient to just sync against domain creation -- what if event channels or grant mappings are also occurring during the policy change? Is there some specific part of domain creation you need to serialise against?
-- Keir
Quoted 28 lines · Stefan Berger
Keir,
as part of the effort to make ACM functionality available via the
Xen-API, we are adding further functionality to the ACM module in the hypervisor. One of these functions is to be able to update a running system with a modified policy. The update is happening in several steps:
relabeling of the domains, testing against the current state of the system, committing the changes. During that time it is necessary that no other domain be created. I am currently using thedomlist_update_lock(seeDOM_CREATE_LOCKdefine in the patch) to prevent other domains from being added to the system while the update is happening. This is not the correct lock to use, though, and I'd rather like to usedomctl_lockindo_domctl, because that will prevent a domain from being 'created' and not just 'added to the list'. So would it be possible to make this lock globally available since it is currently a local lock only accessible from withindo_domctlor are there other ways to achieve this?Thanks.
StefanSigned-off-by Stefan Berger <[email protected]>_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Keir Fraser <[email protected]> wrote on 04/20/2007 11:28:26 AM:
Quoted 1 line
Is there now some consensus on how to add security features to XenAPI
that
Quoted 1 line
does not cause conflict between XSM and ACM?
We are only supporting a single policy on the system and that may either be an ACM or a Flask policy. When someone sets the policy, he has to choose between either one of them and the API supports setting this policy and making modifications to it later on, at least for the ACM implementation the code behind the API does that.
Quoted 2 lines
Anyway, in response to your main question, I wonder what you actually
need
Quoted 1 line
to serialise against? Is it sufficient to just sync against domain
creation
Quoted 1 line
-- what if event channels or grant mappings are also occurring during
the
Quoted 1 line
policy change? Is there some specific part of domain creation you need
to
Quoted 1 line
serialise against?
While the policy update is happening, a domain could be created with a label that is about to be modified or even deleted as part of the policy update.
For serializing against event channel and grant mappings I hold the write-lock to the current policy. The functions that evaluate whether two domains may establish an event channel or grant mappings run into acm/acm_simple_type_enforcement_hooks:share_common_type() function where they try to grab the read-lock to the current policy. So this is going to block them until it's clear what policy will be on the system. I'd say an update of a policy does not happen all that frequently, so this blocking won't happen very often.
Stefan
Quoted 11 lines
-- Keir
Quoted 6 lines · Stefan Berger
Keir,
as part of the effort to make ACM functionality available via the
Xen-API, we are adding further functionality to the ACM module in the hypervisor. One of these functions is to be able to update a running system with a modified policy. The update is happening in several
steps:
Quoted 2 lines
Quoted 2 lines
relabeling of the domains, testing against the current state of the system, committing the changes. During that time it is necessary that
no
Quoted 2 lines
Quoted 2 lines
other domain be created. I am currently using the
domlist_update_lock(seeDOM_CREATE_LOCKdefine in the patch) to prevent other domains
from
Quoted 1 line
Quoted 1 line
being added to the system while the update is happening. This is not
the
Quoted 3 lines
Quoted 3 lines
correct lock to use, though, and I'd rather like to use
domctl_lockindo_domctl, because that will prevent a domain from being 'created' and not just 'added to the list'. So would it be possible to make this
lock
Quoted 6 lines
Quoted 6 lines
globally available since it is currently a local lock only accessible from within
do_domctlor are there other ways to achieve this?Thanks.
Stefan
Quoted 9 lines
Quoted 8 lines
Signed-off-by Stefan Berger <[email protected]>_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 9 lines · Stefan Berger
Quoted 6 lines
Quoted 6 lines
Anyway, in response to your main question, I wonder what you actually need to serialise against? Is it sufficient to just sync against domain creation -- what if event channels or grant mappings are also occurring during the policy change? Is there some specific part of domain creation you need to serialise against?
While the policy update is happening, a domain could be created with a label that is about to be modified or even deleted as part of the policy update.
When a label is associated with a domain, doesn¹t that call into ACM code? In which case you could define your own locking against that event.
-- Keir
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Keir Fraser <[email protected]> wrote on 04/20/2007 12:46:40 PM:
Quoted 4 lines · Stefan Berger
Quoted 3 lines
Anyway, in response to your main question, I wonder what you actually
need
Quoted 1 line
Quoted 1 line
to serialise against? Is it sufficient to just sync against domain
creation
Quoted 1 line
Quoted 1 line
-- what if event channels or grant mappings are also occurring during
the
Quoted 1 line
Quoted 1 line
policy change? Is there some specific part of domain creation you need
to
Quoted 8 lines
Quoted 1 line
serialise against?
While the policy update is happening, a domain could be created with a label that is about to be modified or even deleted as part of the policy update.
When a label is associated with a domain, doesn?t that call into ACM code? In which case you could define your own locking against that
event.
Actually the easiest solution would be to grab the read-lock of the acm policy in do_domctl() before acm_pre_domctl() and release it after acm_post_domctl() or acm_fail_domctl(), which are both at the end of do_domctl(). All of these functions grab and release the read lock individually in some subfunction, but the lock is not being held permanently which is what bothers me for the update.
Stefan
Quoted 2 lines
-- Keir
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel