Enable updating of policy on running system
PATCH 1/2 Enable updating of policy on running system
This is a revised version of the previously posted patch that adds functionality to allow a policy to be updated on a running system and domains to be relabeled. The updating of a policy is happening in several steps: relabeling the domains, testing whether the system would be in a valid state after the relabeling, committing the changes if state is determined to be valid.
To avoid a domain from being created while the policy is updated, the read-lock to the ACM policy must be held during all operations that evaluate against the current policy. In this patch I implement a function pair acm_rlock_policy()/acm_runlock_policy() that grab the read-lock in do_domctl() only when the operation is XEN_DOMCTL_createdomain. The operations are void if ACM is not compiled into Xen. The 2nd part of the patch restructures the code so that the pair of locking functions need not take the operation as parameter anymore.
--- xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c | 146 ++- xen-unstable.hg/xen/acm/acm_core.c | 7 xen-unstable.hg/xen/acm/acm_null_hooks.c | 10 xen-unstable.hg/xen/acm/acm_policy.c | 544 +++++++++++- xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c | 127 ++ xen-unstable.hg/xen/common/acm_ops.c | 36 xen-unstable.hg/xen/common/domctl.c | 8 xen-unstable.hg/xen/include/acm/acm_core.h | 49 - xen-unstable.hg/xen/include/acm/acm_hooks.h | 23 xen-unstable.hg/xen/include/public/acm.h | 13 xen-unstable.hg/xen/include/public/acm_ops.h | 30 11 files changed, 868 insertions(+), 125 deletions(-)
xen-unstable.hg/xen/common/domctl.c +7 -1
@@ -188,8 +188,12 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domcif ( op->interface_version !=XEN_DOMCTL_INTERFACE_VERSION )return -EACCES ; -if (acm_pre_domctl (op, &ssid) ) +acm_rlock_policy (op->cmd); + +if (acm_pre_domctl (op, &ssid) ) { +acm_runlock_policy (op->cmd);return -EPERM ; + }spin_lock (&domctl_lock);
@@ -723,6 +727,8 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domcelse acm_fail_domctl (op, &ssid); +acm_runlock_policy (op->cmd); +return ret; }
xen-unstable.hg/xen/include/acm/acm_hooks.h +21 -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) */
@@ -152,6 +154,10 @@ static inline void acm_post_domain0_crea {return ; }static inline int acm_sharing (ssidref_t ssidref1,ssidref_t ssidref2) {return 0 ; } +static inline void acm_rlock_policy (int cmd) +{return ; } +static inline void acm_runlock_policy (int cmd) +{return ; }#else
@@ -369,6 +375,19 @@ static inline int acm_sharing(ssidref_treturn ACM_ACCESS_PERMITTED ; } +static inline void acm_rlock_policy (int cmd) +{ +if (cmd == XEN_DOMCTL_createdomain) { +read_lock (&acm_bin_pol_rwlock); + } +} + +static inline void acm_runlock_policy (int cmd) +{ +if (cmd == XEN_DOMCTL_createdomain) { +read_unlock (&acm_bin_pol_rwlock); + } +}extern int acm_init (char *policy_start,unsigned long policy_len);
xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c +106 -40
202 lines not on this page · raw message
xen-unstable.hg/xen/acm/acm_core.c +4 -3
@@ -62,7 +62,7 @@ struct acm_binary_policy acm_bin_pol;/* acm binary policy lock */ DEFINE_RWLOCK (acm_bin_pol_rwlock); -/* ACM's only accepted policy name */ +/* ACM's only accepted policy name during boot */ char polname[80 ];char *acm_accepted_boot_policy_name =NULL ;
@@ -77,7 +77,7 @@ static void __init set_dom0_ssidref(consint i;int dom0_ssidref =simple_strtoull (val, &c,0 ); -if (!strncmp (&c[0 ],":sHype:" ,7 )) { +if (!strncmp (&c[0 ],":ACM:" ,5 )) { lo = dom0_ssidref &0xffff ;if (lo <ACM_MAX_NUM_TYPES && lo >=1 ) dom0_chwall_ssidref = lo;
@@ -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 +507 -37
616 lines not on this page · raw message
xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c +94 -33
226 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/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