refactor IO hooks/sysctl hooks
PATCH 1/1 refactor IO hooks/sysctl hooks
- The patch refactors the IO resource checks into the rangeset add/del code. This produces a much more architecture friendly implementation and ensures that HVM and paravirtualized guests are checked consistently.
- The patch removes the following hooks in support of the refactoring of the IO resource checks:
- xsm_irq_permission
- xsm_iomem_permission
- xsm_ioport_permission
- The patch adds the following hooks in support of the refactoring of the IO resource checks:
- xsm_add_range
- xsm_remove_range
- These IO refactoring changes are transparent to any pre-existing Flask policies.
- The patch adds also adds hooks for sysctl functionality that was added since the last major XSM patch. The following hooks were added:
- xsm_set_target
- xsm_debug_keys
- xsm_getcpuinfo
- xsm_availheap
- xsm_firmware_info
- xsm_acpi_sleep
- xsm_change_freq
- xsm_getidletime
- xsm_sendtrigger
- xsm_test_assign_device
- xsm_assign_device
- xsm_deassign_device
- xsm_bind_pt_irq
- xsm_pin_mem_cacheattr
- xsm_ext_vcpucontext
xen/arch/x86/domctl.c +37 -8
@@ -67,14 +67,6 @@ ret = -ESRCH ;if (unlikely ((d =rcu_lock_domain_by_id (domctl->domain)) ==NULL ) )break ; - - ret =xsm_ioport_permission (d, fp, - domctl->u.ioport_permission.allow_access); -if ( ret ) - { -rcu_unlock_domain (d); -break ; - }if ( np ==0 ) ret =0 ;
@@ -550,6 +542,10 @@if ( (d =rcu_lock_domain_by_id (domctl->domain)) ==NULL )break ; + ret =xsm_sendtrigger (d); +if ( ret ) + goto sendtrigger_out; + ret = -EINVAL ;if ( domctl->u.sendtrigger.vcpu >=MAX_VIRT_CPUS ) goto sendtrigger_out;
@@ -628,6 +624,10 @@ bus = (domctl->u.assign_device.machine_bdf >>16 ) &0xff ; devfn = (domctl->u.assign_device.machine_bdf >>8 ) &0xff ; + ret =xsm_test_assign_device (domctl->u.assign_device.machine_bdf); +if ( ret ) +break ; +if (device_assigned (bus, devfn) ) { gdprintk(XENLOG_ERR, "XEN_DOMCTL_test_assign_device: "
@@ -655,6 +655,11 @@ "XEN_DOMCTL_assign_device: get_domain_by_id() failed\n");break ; } + + ret =xsm_assign_device (d, domctl->u.assign_device.machine_bdf); +if ( ret ) + goto assign_device_out; + bus = (domctl->u.assign_device.machine_bdf >>16 ) &0xff ; devfn = (domctl->u.assign_device.machine_bdf >>8 ) &0xff ;
@@ -680,6 +685,7 @@"assign device (%x:%x:%x) failed\n" , bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + assign_device_out:put_domain (d); }break ;
@@ -700,6 +706,11 @@ "XEN_DOMCTL_deassign_device: get_domain_by_id() failed\n");break ; } + + ret =xsm_assign_device (d, domctl->u.assign_device.machine_bdf); +if ( ret ) + goto deassign_device_out; + bus = (domctl->u.assign_device.machine_bdf >>16 ) &0xff ; devfn = (domctl->u.assign_device.machine_bdf >>8 ) &0xff ;
@@ -720,6 +731,8 @@deassign_device (d, bus, devfn);gdprintk (XENLOG_INFO ,"XEN_DOMCTL_deassign_device: bdf = %x:%x:%x\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn)); + + deassign_device_out:put_domain (d); }break ;
@@ -733,10 +746,17 @@if ( (d =rcu_lock_domain_by_id (domctl->domain)) ==NULL )break ; bind = &(domctl->u.bind_pt_irq); + + ret =xsm_bind_pt_irq (d, bind); +if ( ret ) + goto bind_out; +if ( iommu_enabled ) ret =pt_irq_create_bind_vtd (d, bind);if ( ret <0 )gdprintk (XENLOG_ERR ,"pt_irq_create_bind failed!\n" ); + + bind_out:rcu_unlock_domain (d); }break ;
@@ -877,11 +897,16 @@if ( d ==NULL )break ; + ret =xsm_pin_mem_cacheattr (d); +if ( ret ) + goto pin_out; + ret =hvm_set_mem_pinned_cacheattr ( d, domctl->u.pin_mem_cacheattr.start, domctl->u.pin_mem_cacheattr.end, domctl->u.pin_mem_cacheattr.type); + pin_out:rcu_unlock_domain (d); }break ;
@@ -899,6 +924,10 @@ d =rcu_lock_domain_by_id (domctl->domain);if ( d ==NULL )break ; + + ret =xsm_ext_vcpucontext (d, domctl->cmd); +if ( ret ) + goto ext_vcpucontext_out; ret = -ESRCH ; if ( (evc->vcpu >= MAX_VIRT_CPUS) ||
xen/arch/x86/platform_hypercall.c +16 -0
@@ -192,6 +192,10 @@break ;case XENPF_firmware_info: + ret =xsm_firmware_info (); +if ( ret ) +break ; +switch ( op->u.firmware_info.type ) {case XEN_FW_DISK_INFO : {
@@ -280,10 +284,18 @@break ;case XENPF_enter_acpi_sleep: + ret =xsm_acpi_sleep (); +if ( ret ) +break ; + ret =acpi_enter_sleep (&op->u.enter_acpi_sleep);break ;case XENPF_change_freq: + ret =xsm_change_freq (); +if ( ret ) +break ; + ret = -ENOSYS ;if ( cpufreq_controller != FREQCTL_dom0_kernel )break ;
@@ -305,6 +317,10 @@cpumask_t cpumap;XEN_GUEST_HANDLE (uint8) cpumap_bitmap;XEN_GUEST_HANDLE (uint64) idletimes; + + ret =xsm_getidletime (); +if ( ret ) +break ; ret = -ENOSYS ;if ( cpufreq_controller != FREQCTL_dom0_kernel )
xen/common/domctl.c +6 -10
@@ -729,16 +729,11 @@if ( d ==NULL )break ; - ret =xsm_irq_permission (d, pirq, op->u.irq_permission.allow_access); -if ( ret ) - goto irq_permission_out; -if ( op->u.irq_permission.allow_access ) ret =irq_permit_access (d, pirq);else ret =irq_deny_access (d, pirq); - irq_permission_out:rcu_unlock_domain (d); }break ;
@@ -758,16 +753,11 @@if ( d ==NULL )break ; - ret =xsm_iomem_permission (d, mfn, op->u.iomem_permission.allow_access); -if ( ret ) - goto iomem_permission_out; -if ( op->u.iomem_permission.allow_access ) ret =iomem_permit_access (d, mfn, mfn + nr_mfns -1 );else ret =iomem_deny_access (d, mfn, mfn + nr_mfns -1 ); - iomem_permission_out:rcu_unlock_domain (d); }break ;
@@ -815,6 +805,12 @@ goto set_target_out; } + ret =xsm_set_target (d, e); +if ( ret ) { +put_domain (e); + goto set_target_out; + } +/* Hold reference on @e until we destroy @d. */ d->target = e;
xen/common/rangeset.c +9 -0
@@ -10,6 +10,7 @@#include <xen/sched.h> #include <xen/errno.h> #include <xen/rangeset.h> +#include <xsm/xsm.h> /* An inclusive range [s,e] and pointer to next range in ascending order. */ struct range {
@@ -96,6 +97,10 @@struct range *x, *y;int rc =0 ; + rc =xsm_add_range (r->domain, r->name, s, e); +if ( rc ) +return rc; +ASSERT (s <= e);spin_lock (&r->lock);
@@ -163,6 +168,10 @@ {struct range *x, *y, *t;int rc =0 ; + + rc =xsm_remove_range (r->domain, r->name, s, e); +if ( rc ) +return rc;ASSERT (s <= e);
xen/common/sysctl.c +12 -0
@@ -149,6 +149,10 @@char c;uint32_t i; + ret =xsm_debug_keys (); +if ( ret ) +break ; +for ( i =0 ; i < op->u.debug_keys.nr_keys; i++ ) {if (copy_from_guest_offset (&c, op->u.debug_keys.keys, i,1 ) )
@@ -165,6 +169,10 @@struct vcpu *v; nr_cpus =min_t (uint32_t, op->u.getcpuinfo.max_cpus,NR_CPUS ); + + ret =xsm_getcpuinfo (); +if ( ret ) +break ;for ( i =0 ; i < nr_cpus; i++ ) {
@@ -188,6 +196,10 @@case XEN_SYSCTL_availheap: { + ret =xsm_availheap (); +if ( ret ) +break ; + op->u.availheap.avail_bytes = avail_domheap_pages_region( op->u.availheap.node, op->u.availheap.min_bitwidth,
xen/include/xsm/xsm.h +105 -23
203 lines not on this page · raw message
xen/xsm/dummy.c +95 -11
182 lines not on this page · raw message
xen/xsm/flask/hooks.c +250 -24
396 lines not on this page · raw message
xen/xsm/flask/include/av_perm_to_string.h +17 -4
@@ -17,11 +17,19 @@ S_(SECCLASS_XEN, XEN__PRIVPROFILE, "privprofile") S_(SECCLASS_XEN, XEN__NONPRIVPROFILE, "nonprivprofile") S_(SECCLASS_XEN, XEN__KEXEC, "kexec") + S_(SECCLASS_XEN, XEN__FIRMWARE, "firmware") + S_(SECCLASS_XEN, XEN__SLEEP, "sleep") + S_(SECCLASS_XEN, XEN__FREQUENCY, "frequency") + S_(SECCLASS_XEN, XEN__GETIDLE, "getidle") + S_(SECCLASS_XEN, XEN__DEBUG, "debug") + S_(SECCLASS_XEN, XEN__GETCPUINFO, "getcpuinfo") + S_(SECCLASS_XEN, XEN__HEAP, "heap") S_(SECCLASS_DOMAIN, DOMAIN__SETVCPUCONTEXT, "setvcpucontext") S_(SECCLASS_DOMAIN, DOMAIN__PAUSE, "pause") S_(SECCLASS_DOMAIN, DOMAIN__UNPAUSE, "unpause") S_(SECCLASS_DOMAIN, DOMAIN__RESUME, "resume") S_(SECCLASS_DOMAIN, DOMAIN__CREATE, "create") + S_(SECCLASS_DOMAIN, DOMAIN__TRANSITION, "transition") S_(SECCLASS_DOMAIN, DOMAIN__MAX_VCPUS, "max_vcpus") S_(SECCLASS_DOMAIN, DOMAIN__DESTROY, "destroy")S_ (SECCLASS_DOMAIN ,DOMAIN__SETVCPUAFFINITY ,"setvcpuaffinity" )
@@ -34,11 +42,14 @@ S_(SECCLASS_DOMAIN, DOMAIN__SETDOMAINHANDLE, "setdomainhandle") S_(SECCLASS_DOMAIN, DOMAIN__SETDEBUGGING, "setdebugging") S_(SECCLASS_DOMAIN, DOMAIN__HYPERCALL, "hypercall") - S_(SECCLASS_DOMAIN, DOMAIN__TRANSITION, "transition") S_(SECCLASS_DOMAIN, DOMAIN__SETTIME, "settime") + S_(SECCLASS_DOMAIN, DOMAIN__SET_TARGET, "set_target") S_(SECCLASS_DOMAIN, DOMAIN__SHUTDOWN, "shutdown") S_(SECCLASS_DOMAIN, DOMAIN__SETADDRSIZE, "setaddrsize") S_(SECCLASS_DOMAIN, DOMAIN__GETADDRSIZE, "getaddrsize") + S_(SECCLASS_DOMAIN, DOMAIN__TRIGGER, "trigger") + S_(SECCLASS_DOMAIN, DOMAIN__GETEXTVCPUCONTEXT, "getextvcpucontext") + S_(SECCLASS_DOMAIN, DOMAIN__SETEXTVCPUCONTEXT, "setextvcpucontext") S_(SECCLASS_HVM, HVM__SETHVMC, "sethvmc") S_(SECCLASS_HVM, HVM__GETHVMC, "gethvmc")S_ (SECCLASS_HVM ,HVM__SETPARAM ,"setparam" )
@@ -46,14 +57,13 @@ S_(SECCLASS_HVM, HVM__PCILEVEL, "pcilevel") S_(SECCLASS_HVM, HVM__IRQLEVEL, "irqlevel") S_(SECCLASS_HVM, HVM__PCIROUTE, "pciroute") + S_(SECCLASS_HVM, HVM__BIND_IRQ, "bind_irq") + S_(SECCLASS_HVM, HVM__CACHEATTR, "cacheattr") S_(SECCLASS_EVENT, EVENT__BIND, "bind") - S_(SECCLASS_EVENT, EVENT__CLOSE, "close") S_(SECCLASS_EVENT, EVENT__SEND, "send") S_(SECCLASS_EVENT, EVENT__STATUS, "status") - S_(SECCLASS_EVENT, EVENT__UNMASK, "unmask") S_(SECCLASS_EVENT, EVENT__NOTIFY, "notify") S_(SECCLASS_EVENT, EVENT__CREATE, "create") - S_(SECCLASS_EVENT, EVENT__ALLOC, "alloc") S_(SECCLASS_EVENT, EVENT__VECTOR, "vector") S_(SECCLASS_EVENT, EVENT__RESET, "reset")S_ (SECCLASS_GRANT ,GRANT__MAP_READ ,"map_read" )
@@ -87,6 +97,9 @@ S_(SECCLASS_RESOURCE, RESOURCE__REMOVE_IOPORT, "remove_ioport") S_(SECCLASS_RESOURCE, RESOURCE__ADD_IOMEM, "add_iomem") S_(SECCLASS_RESOURCE, RESOURCE__REMOVE_IOMEM, "remove_iomem") + S_(SECCLASS_RESOURCE, RESOURCE__STAT_DEVICE, "stat_device") + S_(SECCLASS_RESOURCE, RESOURCE__ADD_DEVICE, "add_device") + S_(SECCLASS_RESOURCE, RESOURCE__REMOVE_DEVICE, "remove_device") S_(SECCLASS_SECURITY, SECURITY__COMPUTE_AV, "compute_av") S_(SECCLASS_SECURITY, SECURITY__COMPUTE_CREATE, "compute_create")S_ (SECCLASS_SECURITY ,SECURITY__COMPUTE_MEMBER ,"compute_member" )
xen/xsm/flask/include/av_permissions.h +38 -25
90 lines not on this page · raw message
xen/xsm/flask/include/flask.h +5 -6
@@ -1,6 +1,6 @@/* This file is automatically generated. Do not edit. */ -#ifndef _FLASK_FLASK_H_ -#define _FLASK_FLASK_H_ +#ifndef _SELINUX_FLASK_H_ +#define _SELINUX_FLASK_H_/* * Security object class definitions
@@ -27,10 +27,9 @@#define SECINITSID_SECURITY 7#define SECINITSID_IOPORT 8#define SECINITSID_IOMEM 9 -#define SECINITSID_VCPU 10 -#define SECINITSID_VIRQ 11 -#define SECINITSID_PIRQ 12 +#define SECINITSID_PIRQ 10 +#define SECINITSID_DEVICE 11 -#define SECINITSID_NUM 12 +#define SECINITSID_NUM 11#endif
xen/xsm/flask/include/initial_sid_to_string.h +1 -2
@@ -11,8 +11,7 @@"security" ,"ioport" ,"iomem" , -"vcpu" , -"virq" ,"pirq" , + "device", };
xen/xsm/flask/include/security.h +2 -4
@@ -69,13 +69,11 @@int security_pirq_sid (int pirq,u32 *out_sid); -int security_virq_sid (int virq,u32 *out_sid); - -int security_vcpu_sid (int vcpu,u32 *out_sid); -int security_iomem_sid (unsigned long ,u32 *out_sid);int security_ioport_sid (u32 ioport,u32 *out_sid); + +int security_device_sid (u32 device,u32 *out_sid);int security_validate_transition (u32 oldsid,u32 newsid,u32 tasksid,u16 tclass);
xen/xsm/flask/ss/policydb.h +6 -7
@@ -133,10 +133,9 @@union {char *name;/* name of initial SID, fs, netif, fstype, path */ int pirq; -int virq; -int vcpu;u32 ioport;unsigned long iomem; +u32 device; } u;struct context context[2 ];/* security context(s) */ u32 sid[2 ];/* SID(s) */
@@ -157,11 +156,11 @@/* object context array indices */ #define OCON_ISID 0/* initial SIDs */ #define OCON_PIRQ 1/* physical irqs */ -#define OCON_VIRQ 2/* virtual irqs */ -#define OCON_VCPU 3/* virtual cpus */ -#define OCON_IOPORT 4/* io ports */ -#define OCON_IOMEM 5/* io memory */ -#define OCON_DUMMY 6 +#define OCON_IOPORT 2/* io ports */ +#define OCON_IOMEM 3/* io memory */ +#define OCON_DEVICE 4/* pci devices */ +#define OCON_DUMMY1 5/* reserved */ +#define OCON_DUMMY2 6/* reserved */ #define OCON_NUM 7/* The policy database */
xen/xsm/flask/ss/services.c +40 -0
@@ -1418,6 +1418,46 @@return rc; } +/** +* security_ioport_sid - Obtain the SID for an ioport. +* @ioport: ioport +* @out_sid: security identifier +*/ +int security_device_sid (u32 device,u32 *out_sid) +{ +struct ocontext *c; +int rc =0 ; + +POLICY_RDLOCK ; + + c = policydb.ocontexts[OCON_DEVICE ]; +while ( c ) + { +if ( c->u.device == device ) +break ; + c = c->next; + } + +if ( c ) + { +if ( !c->sid[0 ] ) + { + rc =sidtab_context_to_sid (&sidtab, &c->context[0 ], &c->sid[0 ]); +if ( rc ) + goto out; + } + *out_sid = c->sid[0 ]; + } +else + { + *out_sid =SECINITSID_DEVICE ; + } + +out: +POLICY_RDUNLOCK ; +return rc; +} +#define SIDS_NEL 25/**
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel