Xen Security Advisory 261 - x86 vHPET interrupt injection errors
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Xen Security Advisory XSA-261
version 2
x86 vHPET interrupt injection errors
UPDATES IN VERSION 2
====================
Versions 3.1 ... 3.3 don't appear to be vulnerable.
Public release.
Updated .meta file
ISSUE DESCRIPTION
=================
The High Precision Event Timer (HPET) can be configured to deliver interrupts in one of three different modes - through legacy interrupts; through the IO-APIC; or optionally via a method similar to PCI MSI. The last mode is optional and not implemented by Xen. However, of the first two modes, only the legacy variant was properly implemented.
If a guest set up an HPET timer in IO-APIC mode, Xen would still handle this using the code for the legacy mode. Unfortunately, the available IO-APIC mode interrupt numbers are higher than legacy mode interrupts. The result was array overruns.
IMPACT
======
A malicious or buggy HVM guest may cause a hypervisor crash, resulting in a Denial of Service (DoS) affecting the entire host. Privilege escalation, or information leaks, cannot be excluded.
VULNERABLE SYSTEMS
==================
Xen versions 3.4 and later are vulnerable.
Only x86 systems are vulnerable. ARM systems are not vulnerable.
Only x86 HVM guests can exploit the vulnerability. x86 PV and PVH guests cannot exploit the vulnerability.
Only x86 HVM guests provided with hypervisor-side HPET emulation can exploit the vulnerability. That is the default configuration. x86 HVM guests whose configuration explicitly disables this emulation (via "hpet=0") cannot exploit the vulnerability.
MITIGATION
==========
Running only PV or PVH guests avoids the vulnerability.
Not exposing the hypervisor based HPET emulation to HVM guests, by adding "hpet=0" to the guest configuration, also avoids the vulnerability.
CREDITS
=======
This issue was discovered by Roger Pau Monné of Citrix.
RESOLUTION
==========
Applying the appropriate attached patch resolves this issue.
xsa261.patch xen-unstable, Xen 4.10.x xsa261-4.9.patch Xen 4.9.x xsa261-4.8.patch Xen 4.8.x xsa261-4.7.patch Xen 4.7.x, Xen 4.6.x
$ sha256sum xsa261* 7b7bbf0fb497491911816e522902f72d3b41355ba71455ab82ebf980160d1a1f xsa261.meta 175501977204db84d08a6fd81d9fd4b69f97f70cbf6f65e6ce0abfeab03eae95 xsa261.patch 98fb28bac871aae7c2f897a5506a2b03f340bf122a3a7f65aa65f3b3c9a525b4 xsa261-4.7.patch 503f1476813e6572dc37b5a0df65b5390567230d9cc006752bf72bf57bbd754d xsa261-4.8.patch f1aac841327d3b5b1e2007b4ebe56223de488e1eb2fa636653725d7d7cd5f82a xsa261-4.9.patch $
DEPLOYMENT DURING EMBARGO
=========================
Deployment of the patches described above (or others which are substantially similar) and the PV/PVH guest mitigation are permitted during the embargo, even on public-facing systems with untrusted guest users and administrators.
HOWEVER deployment of the "hpet=0" guest config mitigation described above is NOT permitted (except where all the affected systems and VMs are administered and used only by organisations which are members of the Xen Project Security Issues Predisclosure List). Specifically, deployment on public cloud systems is NOT permitted.
This is because in that case the configuration change is visible to the guest, which could lead to the rediscovery of the vulnerability.
But: Distribution of updated software is prohibited (except to other members of the predisclosure list).
Predisclosure list members who wish to deploy significantly different patches and/or mitigations, please contact the Xen Project Security Team.
(Note: this during-embargo deployment notice is retained in post-embargo publicly released Xen Project advisories, even though it is then no longer applicable. This is to enable the community to have oversight of the Xen Project Security Team's decisionmaking.)
For more information about permissible uses of embargoed information, consult the Xen Project community's agreed Security Policy:
http://www.xenproject.org/security-policy.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBCAAGBQJa8dQgAAoJEIP+FMlX6CvZZ54IAIlcZ6vu0mYvjwL8I23QbbtW 8uDzgozK9S8r2tPXxn6gbqSwFACuKeS61hnhw7v3gNEClpSQip+dHlGS6ME3AUVZ m0Vtn6eDQXHiwW+9jM4/j8gxLAqgfxUUpTuR74tZxh0kMmXKShirt+ob+9ptxfB7 nu8QiEVDH87P7JnDUXn1czNBRuD3KP0cmsAW/7VaOUm5R/+1RwYX6df9rEN6TU/+ LWMrBeepU8mh8oRgA5yJ78iiCB6KUfURsz1JuPmNd49rSTVK2WGFAH5vNz7EjRyU kbVAJgjWYGGFo0BTXSt8kCi0pdlGEHRh3+KIIuvAxm+JfQtrFC0K8lpzQcpTPYY= =jUil
-----END PGP SIGNATURE-----
From: Xen Project Security Team <[email protected]>
Subject: x86/vpt: add support for IO-APIC routed interrupts
And modify the HPET code to make use of it. Currently HPET interrupts are always treated as ISA and thus injected through the vPIC. This is wrong because HPET interrupts when not in legacy mode should be injected from the IO-APIC.
To make things worse, the supported interrupt routing values are set to [20..23], which clearly falls outside of the ISA range, thus leading to an ASSERT in debug builds or memory corruption in non-debug builds because the interrupt injection code will write out of the bounds of the arch.hvm_domain.vpic array.
Since the HPET interrupt source can change between ISA and IO-APIC always destroy the timer before changing the mode, or else Xen risks changing it while the timer is active.
Note that vpt interrupt injection is racy in the sense that the vIO-APIC RTE entry can be written by the guest in between the call to pt_irq_masked and hvm_ioapic_assert, or the call to pt_update_irq and pt_intr_post. Those are not deemed to be security issues, but rather quirks of the current implementation. In the worse case the guest might lose interrupts or get multiple interrupt vectors injected for the same timer source.
This is part of XSA-261.
Address actual and potential compiler warnings. Fix formatting.
---
Changes since v2:
- Move fallthrough comment to be just above the case label.
- Fix now stale comment in pt_update_irq.
- Use NR_ISAIRQS instead of 16.
- Expand commit message to mention the quirkiness of vpt interrupt injection.
Changes since v1:
- Simply usage of gsi in pt_irq_masked.
- Introduce hvm_ioapic_assert.
- Fix pt->source == PTSRC_isa in create_periodic_time.
xen/arch/x86/hvm/hpet.c +7 -0
@@ -264,13 +264,20 @@ static void hpet_set_timer(HPETState *h, diff = (timer_is_32bit (h, tn) && (-diff >HPET_TINY_TIME_SPAN )) ? (uint32_t )diff :0 ; +destroy_periodic_time (&h->pt[tn]);if ( (tn <=1 ) && (h->hpet.config &HPET_CFG_LEGACY ) ) + {/* if LegacyReplacementRoute bit is set, HPET specification requires timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC, timer1 be routed to IRQ8 in NON-APIC or IRQ8 in the I/O APIC. */ irq = (tn ==0 ) ?0 :8 ; + h->pt[tn].source = PTSRC_isa; + }else + { irq =timer_int_route (h, tn); + h->pt[tn].source = PTSRC_ioapic; + }/* * diff is the time from now when the timer should fire, for a periodic
xen/arch/x86/hvm/irq.c +20 -0
@@ -41,6 +41,26 @@ static void assert_gsi(struct domain *d,vioapic_irq_positive_edge (d, ioapic_gsi); } +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); +int vector; + +if ( gsi >= hvm_irq->nr_gsis ) + { +ASSERT_UNREACHABLE (); +return -1 ; + } + +spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !level || hvm_irq->gsi_assert_count[gsi]++ ==0 ) +assert_gsi (d, gsi); + vector =vioapic_get_vector (d, gsi); +spin_unlock (&d->arch.hvm_domain.irq_lock); + +return vector; +} +static void assert_irq (struct domain *d,unsigned ioapic_gsi,unsigned pic_irq) {assert_gsi (d, ioapic_gsi);
xen/arch/x86/hvm/vpt.c +65 -32
152 lines not on this page · raw message
xen/include/asm-x86/hvm/irq.h +3 -0
@@ -207,6 +207,9 @@ int hvm_set_pci_link_route(struct domainint hvm_inject_msi (struct domain *d,uint64_t addr,uint32_t data); +/* Assert an IO APIC pin. */ +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level); +void hvm_maybe_deassert_evtchn_irq (void );void hvm_assert_evtchn_irq (struct vcpu *v);void hvm_set_callback_via (struct domain *d,uint64_t via);
xen/include/asm-x86/hvm/vpt.h +1 -0
@@ -44,6 +44,7 @@ struct periodic_time {bool_t warned_timeout_too_short;#define PTSRC_isa 1/* ISA time source */ #define PTSRC_lapic 2/* LAPIC time source */ +#define PTSRC_ioapic 3/* IOAPIC time source */ u8 source;/* PTSRC_ */ u8 irq;struct vcpu *vcpu;/* vcpu timer interrupt delivers to */
From 0ce5019f87abe20d1e714f8d983418ecfb0ad5df Mon Sep 17 00:00:00 2001
From: Xen Project Security Team <[email protected]>
Date: Mon, 23 Apr 2018 16:56:47 +0100
Subject: [PATCH] x86/vpt: add support for IO-APIC routed interrupts
And modify the HPET code to make use of it. Currently HPET interrupts are always treated as ISA and thus injected through the vPIC. This is wrong because HPET interrupts when not in legacy mode should be injected from the IO-APIC.
To make things worse, the supported interrupt routing values are set to [20..23], which clearly falls outside of the ISA range, thus leading to an ASSERT in debug builds or memory corruption in non-debug builds because the interrupt injection code will write out of the bounds of the arch.hvm_domain.vpic array.
Since the HPET interrupt source can change between ISA and IO-APIC always destroy the timer before changing the mode, or else Xen risks changing it while the timer is active.
Note that vpt interrupt injection is racy in the sense that the vIO-APIC RTE entry can be written by the guest in between the call to pt_irq_masked and hvm_ioapic_assert, or the call to pt_update_irq and pt_intr_post. Those are not deemed to be security issues, but rather quirks of the current implementation. In the worse case the guest might lose interrupts or get multiple interrupt vectors injected for the same timer source.
This is part of XSA-261.
Address actual and potential compiler warnings. Fix formatting.
--- xen/arch/x86/hvm/hpet.c | 7 ++++ xen/arch/x86/hvm/irq.c | 19 ++++++++++ xen/arch/x86/hvm/vpt.c | 85 ++++++++++++++++++++++++++++++------------- xen/include/asm-x86/hvm/irq.h | 3 ++ xen/include/asm-x86/hvm/vpt.h | 1 + 5 files changed, 89 insertions(+), 26 deletions(-)
xen/arch/x86/hvm/hpet.c +7 -0
@@ -264,13 +264,20 @@ static void hpet_set_timer(HPETState *h, unsigned int tn, diff = (timer_is_32bit (h, tn) && (-diff >HPET_TINY_TIME_SPAN )) ? (uint32_t )diff :0 ; +destroy_periodic_time (&h->pt[tn]);if ( (tn <=1 ) && (h->hpet.config &HPET_CFG_LEGACY ) ) + {/* if LegacyReplacementRoute bit is set, HPET specification requires timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC, timer1 be routed to IRQ8 in NON-APIC or IRQ8 in the I/O APIC. */ irq = (tn ==0 ) ?0 :8 ; + h->pt[tn].source = PTSRC_isa; + }else + { irq =timer_int_route (h, tn); + h->pt[tn].source = PTSRC_ioapic; + }/* * diff is the time from now when the timer should fire, for a periodic
xen/arch/x86/hvm/irq.c +19 -0
@@ -42,6 +42,25 @@ static void assert_gsi(struct domain *d, unsigned ioapic_gsi)vioapic_irq_positive_edge (d, ioapic_gsi); } +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool_t level) +{ +int vector; + +if ( gsi >=VIOAPIC_NUM_PINS ) + { +ASSERT_UNREACHABLE (); +return -1 ; + } + +spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !level || d->arch.hvm_domain.irq.gsi_assert_count[gsi]++ ==0 ) +assert_gsi (d, gsi); + vector =domain_vioapic (d)->redirtbl[gsi].fields.vector; +spin_unlock (&d->arch.hvm_domain.irq_lock); + +return vector; +} +static void assert_irq (struct domain *d,unsigned ioapic_gsi,unsigned pic_irq) {assert_gsi (d, ioapic_gsi);
xen/arch/x86/hvm/vpt.c +59 -26
131 lines not on this page · raw message
xen/include/asm-x86/hvm/irq.h +3 -0
@@ -103,4 +103,7 @@ struct hvm_intack hvm_vcpu_has_pending_irq(struct vcpu *v);struct hvm_intack hvm_vcpu_ack_pending_irq (struct vcpu *v,struct hvm_intack intack); +/* Assert an IO APIC pin. */ +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool_t level); +#endif /* __ASM_X86_HVM_IRQ_H__ */
xen/include/asm-x86/hvm/vpt.h +1 -0
@@ -45,6 +45,7 @@ struct periodic_time {bool_t warned_timeout_too_short;#define PTSRC_isa 1/* ISA time source */ #define PTSRC_lapic 2/* LAPIC time source */ +#define PTSRC_ioapic 3/* IOAPIC time source */ u8 source;/* PTSRC_ */ u8 irq;struct vcpu *vcpu;/* vcpu timer interrupt delivers to */
Signature · 1 line
2.1.4
From: Xen Project Security Team <[email protected]>
Subject: x86/vpt: add support for IO-APIC routed interrupts
And modify the HPET code to make use of it. Currently HPET interrupts are always treated as ISA and thus injected through the vPIC. This is wrong because HPET interrupts when not in legacy mode should be injected from the IO-APIC.
To make things worse, the supported interrupt routing values are set to [20..23], which clearly falls outside of the ISA range, thus leading to an ASSERT in debug builds or memory corruption in non-debug builds because the interrupt injection code will write out of the bounds of the arch.hvm_domain.vpic array.
Since the HPET interrupt source can change between ISA and IO-APIC always destroy the timer before changing the mode, or else Xen risks changing it while the timer is active.
Note that vpt interrupt injection is racy in the sense that the vIO-APIC RTE entry can be written by the guest in between the call to pt_irq_masked and hvm_ioapic_assert, or the call to pt_update_irq and pt_intr_post. Those are not deemed to be security issues, but rather quirks of the current implementation. In the worse case the guest might lose interrupts or get multiple interrupt vectors injected for the same timer source.
This is part of XSA-261.
Address actual and potential compiler warnings. Fix formatting.
xen/arch/x86/hvm/hpet.c +7 -0
@@ -264,13 +264,20 @@ static void hpet_set_timer(HPETState *h, diff = (timer_is_32bit (h, tn) && (-diff >HPET_TINY_TIME_SPAN )) ? (uint32_t )diff :0 ; +destroy_periodic_time (&h->pt[tn]);if ( (tn <=1 ) && (h->hpet.config &HPET_CFG_LEGACY ) ) + {/* if LegacyReplacementRoute bit is set, HPET specification requires timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC, timer1 be routed to IRQ8 in NON-APIC or IRQ8 in the I/O APIC. */ irq = (tn ==0 ) ?0 :8 ; + h->pt[tn].source = PTSRC_isa; + }else + { irq =timer_int_route (h, tn); + h->pt[tn].source = PTSRC_ioapic; + }/* * diff is the time from now when the timer should fire, for a periodic
xen/arch/x86/hvm/irq.c +19 -0
@@ -42,6 +42,25 @@ static void assert_gsi(struct domain *d,vioapic_irq_positive_edge (d, ioapic_gsi); } +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level) +{ +int vector; + +if ( gsi >=VIOAPIC_NUM_PINS ) + { +ASSERT_UNREACHABLE (); +return -1 ; + } + +spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !level || d->arch.hvm_domain.irq.gsi_assert_count[gsi]++ ==0 ) +assert_gsi (d, gsi); + vector =domain_vioapic (d)->redirtbl[gsi].fields.vector; +spin_unlock (&d->arch.hvm_domain.irq_lock); + +return vector; +} +static void assert_irq (struct domain *d,unsigned ioapic_gsi,unsigned pic_irq) {assert_gsi (d, ioapic_gsi);
xen/arch/x86/hvm/vpt.c +59 -26
131 lines not on this page · raw message
xen/include/asm-x86/hvm/irq.h +3 -0
@@ -103,4 +103,7 @@ struct hvm_intack hvm_vcpu_has_pending_istruct hvm_intack hvm_vcpu_ack_pending_irq (struct vcpu *v,struct hvm_intack intack); +/* Assert an IO APIC pin. */ +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level); +#endif /* __ASM_X86_HVM_IRQ_H__ */
xen/include/asm-x86/hvm/vpt.h +1 -0
@@ -45,6 +45,7 @@ struct periodic_time {bool_t warned_timeout_too_short;#define PTSRC_isa 1/* ISA time source */ #define PTSRC_lapic 2/* LAPIC time source */ +#define PTSRC_ioapic 3/* IOAPIC time source */ u8 source;/* PTSRC_ */ u8 irq;struct vcpu *vcpu;/* vcpu timer interrupt delivers to */
From: Xen Project Security Team <[email protected]>
Subject: x86/vpt: add support for IO-APIC routed interrupts
And modify the HPET code to make use of it. Currently HPET interrupts are always treated as ISA and thus injected through the vPIC. This is wrong because HPET interrupts when not in legacy mode should be injected from the IO-APIC.
To make things worse, the supported interrupt routing values are set to [20..23], which clearly falls outside of the ISA range, thus leading to an ASSERT in debug builds or memory corruption in non-debug builds because the interrupt injection code will write out of the bounds of the arch.hvm_domain.vpic array.
Since the HPET interrupt source can change between ISA and IO-APIC always destroy the timer before changing the mode, or else Xen risks changing it while the timer is active.
Note that vpt interrupt injection is racy in the sense that the vIO-APIC RTE entry can be written by the guest in between the call to pt_irq_masked and hvm_ioapic_assert, or the call to pt_update_irq and pt_intr_post. Those are not deemed to be security issues, but rather quirks of the current implementation. In the worse case the guest might lose interrupts or get multiple interrupt vectors injected for the same timer source.
This is part of XSA-261.
Address actual and potential compiler warnings. Fix formatting.
xen/arch/x86/hvm/hpet.c +7 -0
@@ -264,13 +264,20 @@ static void hpet_set_timer(HPETState *h, diff = (timer_is_32bit (h, tn) && (-diff >HPET_TINY_TIME_SPAN )) ? (uint32_t )diff :0 ; +destroy_periodic_time (&h->pt[tn]);if ( (tn <=1 ) && (h->hpet.config &HPET_CFG_LEGACY ) ) + {/* if LegacyReplacementRoute bit is set, HPET specification requires timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC, timer1 be routed to IRQ8 in NON-APIC or IRQ8 in the I/O APIC. */ irq = (tn ==0 ) ?0 :8 ; + h->pt[tn].source = PTSRC_isa; + }else + { irq =timer_int_route (h, tn); + h->pt[tn].source = PTSRC_ioapic; + }/* * diff is the time from now when the timer should fire, for a periodic
xen/arch/x86/hvm/irq.c +23 -0
@@ -41,6 +41,29 @@ static void assert_gsi(struct domain *d,vioapic_irq_positive_edge (d, ioapic_gsi); } +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); +const struct hvm_vioapic *vioapic; +unsigned int pin; +int vector; + +if ( gsi >= hvm_irq->nr_gsis ) + { +ASSERT_UNREACHABLE (); +return -1 ; + } + +spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !level || hvm_irq->gsi_assert_count[gsi]++ ==0 ) +assert_gsi (d, gsi); + vioapic =gsi_vioapic (d, gsi, &pin); + vector = vioapic ? vioapic->redirtbl[pin].fields.vector :-1 ; +spin_unlock (&d->arch.hvm_domain.irq_lock); + +return vector; +} +static void assert_irq (struct domain *d,unsigned ioapic_gsi,unsigned pic_irq) {assert_gsi (d, ioapic_gsi);
xen/arch/x86/hvm/vpt.c +73 -34
154 lines not on this page · raw message
xen/include/asm-x86/hvm/irq.h +3 -0
@@ -106,4 +106,7 @@ struct hvm_intack hvm_vcpu_has_pending_istruct hvm_intack hvm_vcpu_ack_pending_irq (struct vcpu *v,struct hvm_intack intack); +/* Assert an IO APIC pin. */ +int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level); +#endif /* __ASM_X86_HVM_IRQ_H__ */
xen/include/asm-x86/hvm/vpt.h +1 -0
@@ -44,6 +44,7 @@ struct periodic_time {bool_t warned_timeout_too_short;#define PTSRC_isa 1/* ISA time source */ #define PTSRC_lapic 2/* LAPIC time source */ +#define PTSRC_ioapic 3/* IOAPIC time source */ u8 source;/* PTSRC_ */ u8 irq;struct vcpu *vcpu;/* vcpu timer interrupt delivers to */
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel