From: "Jan Beulich" Subject: [PATCH v3 5/5] x86/MSI: drop workaround for insecure Dom0 kernels Date: Mon, 07 Apr 2014 11:11:33 +0100 Message-ID: <534295F50200007800006152@nat28.tlf.novell.com> References: <534293A90200007800006102@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC5F7D9C5.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WX6Wg-0000Gq-Qf for xen-devel@lists.xenproject.org; Mon, 07 Apr 2014 10:11:39 +0000 In-Reply-To: <534293A90200007800006102@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser , Kevin Tian , Eddie Dong , Jun Nakajima , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartC5F7D9C5.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Considering that - the workaround is expensive (iterating through the entire P2M space of a domain), - the planned elimination of the expensiveness (by propagating the type change step by step to the individual P2M leaves) wouldn't address the IOMMU side of things (as for it to obey to the changed permissions the adjustments must be pushed down immediately through the entire tree) - the proper solution (PHYSDEVOP_msix_prepare) should by now be implemented by all security conscious Dom0 kernels remove the workaround, killing eventual guests that would be known to become a security risk instead. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -770,7 +770,7 @@ static void ept_change_entry_type_global return; =20 BUG_ON(p2m_is_grant(ot) || p2m_is_grant(nt)); - BUG_ON(ot !=3D nt && (ot =3D=3D p2m_mmio_direct || nt =3D=3D = p2m_mmio_direct)); + BUG_ON(p2m_is_mmio(ot) || p2m_is_mmio(nt)); =20 ept_change_entry_type_page(_mfn(ept_get_asr(ept)), ept_get_wl(ept), ot, nt); --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -825,32 +825,22 @@ static int msix_capability_init(struct p msix->pba.last) ) WARN(); =20 - if ( dev->domain ) - p2m_change_entry_type_global(dev->domain, - p2m_mmio_direct, p2m_mmio_direct)= ; - if ( desc && (!dev->domain || !paging_mode_translate(dev->domain))= ) + if ( desc ) { - struct domain *d =3D dev->domain; + struct domain *currd =3D current->domain; + struct domain *d =3D dev->domain ?: currd; =20 - if ( !d ) - for_each_domain(d) - if ( !paging_mode_translate(d) && - (iomem_access_permitted(d, msix->table.first, - msix->table.last) || - iomem_access_permitted(d, msix->pba.first, - msix->pba.last)) ) - break; - if ( d ) - { - if ( !is_hardware_domain(d) && msix->warned !=3D = d->domain_id ) - { - msix->warned =3D d->domain_id; - printk(XENLOG_ERR - "Potentially insecure use of MSI-X on = %04x:%02x:%02x.%u by Dom%d\n", - seg, bus, slot, func, d->domain_id); - } - /* XXX How to deal with existing mappings? */ - } + if ( !is_hardware_domain(currd) || d !=3D currd ) + printk("%s use of MSI-X on %04x:%02x:%02x.%u by Dom%d\n", + is_hardware_domain(currd) + ? XENLOG_WARNING "Potentially insecure" + : XENLOG_ERR "Insecure", + seg, bus, slot, func, d->domain_id); + if ( !is_hardware_domain(d) && + /* Assume a domain without memory has no mappings yet. = */ + (!is_hardware_domain(currd) || d->tot_pages) ) + domain_crash(d); + /* XXX How to deal with existing mappings? */ } } WARN_ON(msix->nr_entries !=3D nr_entries); --=__PartC5F7D9C5.1__= Content-Type: text/plain; name="x86-MSI-drop-workaround.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-MSI-drop-workaround.patch" x86/MSI: drop workaround for insecure Dom0 kernels=0A=0AConsidering = that=0A- the workaround is expensive (iterating through the entire P2M = space=0A of a domain),=0A- the planned elimination of the expensiveness = (by propagating the type=0A change step by step to the individual P2M = leaves) wouldn't address=0A the IOMMU side of things (as for it to obey = to the changed=0A permissions the adjustments must be pushed down = immediately through=0A the entire tree)=0A- the proper solution (PHYSDEVOP= _msix_prepare) should by now be=0A implemented by all security conscious = Dom0 kernels=0Aremove the workaround, killing eventual guests that would = be known to=0Abecome a security risk instead.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/arch/x86/mm/p2m-ept.c=0A+++ = b/xen/arch/x86/mm/p2m-ept.c=0A@@ -770,7 +770,7 @@ static void ept_change_en= try_type_global=0A return;=0A =0A BUG_ON(p2m_is_grant(ot) || = p2m_is_grant(nt));=0A- BUG_ON(ot !=3D nt && (ot =3D=3D p2m_mmio_direct = || nt =3D=3D p2m_mmio_direct));=0A+ BUG_ON(p2m_is_mmio(ot) || p2m_is_mmi= o(nt));=0A =0A ept_change_entry_type_page(_mfn(ept_get_asr(ept)),=0A = ept_get_wl(ept), ot, nt);=0A--- a/xen/arch/x86= /msi.c=0A+++ b/xen/arch/x86/msi.c=0A@@ -825,32 +825,22 @@ static int = msix_capability_init(struct p=0A msix->pba.= last) )=0A WARN();=0A =0A- if ( dev->domain )=0A- = p2m_change_entry_type_global(dev->domain,=0A- = p2m_mmio_direct, p2m_mmio_direct);=0A- if ( desc && = (!dev->domain || !paging_mode_translate(dev->domain)) )=0A+ if ( = desc )=0A {=0A- struct domain *d =3D dev->domain;=0A+ = struct domain *currd =3D current->domain;=0A+ struct = domain *d =3D dev->domain ?: currd;=0A =0A- if ( !d )=0A- = for_each_domain(d)=0A- if ( !paging_mode_transl= ate(d) &&=0A- (iomem_access_permitted(d, msix->tabl= e.first,=0A- msix->table.la= st) ||=0A- iomem_access_permitted(d, msix->pba.fir= st,=0A- msix->pba.last)) = )=0A- break;=0A- if ( d )=0A- = {=0A- if ( !is_hardware_domain(d) && msix->warned !=3D = d->domain_id )=0A- {=0A- msix->warned = =3D d->domain_id;=0A- printk(XENLOG_ERR=0A- = "Potentially insecure use of MSI-X on %04x:%02x:%02x.%u by = Dom%d\n",=0A- seg, bus, slot, func, d->domain_id)= ;=0A- }=0A- /* XXX How to deal with existing = mappings? */=0A- }=0A+ if ( !is_hardware_domain(currd= ) || d !=3D currd )=0A+ printk("%s use of MSI-X on = %04x:%02x:%02x.%u by Dom%d\n",=0A+ is_hardware_domain= (currd)=0A+ ? XENLOG_WARNING "Potentially = insecure"=0A+ : XENLOG_ERR "Insecure",=0A+ = seg, bus, slot, func, d->domain_id);=0A+ if ( = !is_hardware_domain(d) &&=0A+ /* Assume a domain without = memory has no mappings yet. */=0A+ (!is_hardware_domain(cur= rd) || d->tot_pages) )=0A+ domain_crash(d);=0A+ = /* XXX How to deal with existing mappings? */=0A }=0A }=0A = WARN_ON(msix->nr_entries !=3D nr_entries);=0A --=__PartC5F7D9C5.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartC5F7D9C5.1__=--