aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir@xen.org>2011-05-12 18:07:45 +0100
committerKeir Fraser <keir@xen.org>2011-05-12 18:07:45 +0100
commiteda571666d75d81efd5ef5efbb08d17c032fbbcb (patch)
tree18c102c98b4a66b1ec846cb5ff5c3820916f5100
parentc3ff6874136a037b9b76d7b2502294e3a2b6fea9 (diff)
downloadxen-eda571666d75d81efd5ef5efbb08d17c032fbbcb.tar.gz
xen-eda571666d75d81efd5ef5efbb08d17c032fbbcb.tar.bz2
xen-eda571666d75d81efd5ef5efbb08d17c032fbbcb.zip
x86, vtd: [CVE-2011-1898] Protect against malicious MSIs from untrusted devices.
In the absence of VT-d interrupt remapping support, a device can send arbitrary APIC messages to host CPUs. One class of attack that results is to confuse the hypervisor by delivering asynchronous interrupts to vectors that are expected to handle only synchronous traps/exceptions. We block this class of attack by: (1) setting APIC.TPR=0x10, to block all interrupts below vector 0x20. This blocks delivery to all architectural exception vectors. (2) checking APIC.ISR[vec] for vectors 0x80 (fast syscall) and 0x82 (hypercall). In these cases we BUG if we detect we are handling a hardware interrupt -- turning a potentially more severe infiltration into a straightforward system crash (i.e, DoS). Thanks to Invisible Things Lab <http://www.invisiblethingslab.com> for discovery and detailed investigation of this attack. Signed-off-by: Keir Fraser <keir@xen.org> xen-unstable changeset: 23337:cc91832a02c7 xen-unstable date: Thu May 12 16:39:31 2011 +0100
-rw-r--r--xen/arch/x86/apic.c13
-rw-r--r--xen/arch/x86/x86_64/compat/entry.S9
-rw-r--r--xen/arch/x86/x86_64/entry.S8
-rw-r--r--xen/drivers/passthrough/vtd/iommu.c11
4 files changed, 36 insertions, 5 deletions
diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c
index 3246baeb3c..fb8f083a9d 100644
--- a/xen/arch/x86/apic.c
+++ b/xen/arch/x86/apic.c
@@ -572,12 +572,9 @@ void __devinit setup_local_APIC(void)
init_apic_ldr();
/*
- * Set Task Priority to 'accept all'. We never change this
- * later on.
+ * Set Task Priority to reject any interrupts below FIRST_DYNAMIC_VECTOR.
*/
- value = apic_read(APIC_TASKPRI);
- value &= ~APIC_TPRI_MASK;
- apic_write_around(APIC_TASKPRI, value);
+ apic_write_around(APIC_TASKPRI, (FIRST_DYNAMIC_VECTOR & 0xF0) - 0x10);
/*
* After a crash, we no longer service the interrupts and a pending
@@ -1498,3 +1495,9 @@ int __init APIC_init_uniprocessor (void)
return 0;
}
+
+void check_for_unexpected_msi(unsigned int vector)
+{
+ unsigned long v = apic_read(APIC_ISR + ((vector & ~0x1f) >> 1));
+ BUG_ON(v & (1 << (vector & 0x1f)));
+}
diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index d313cd7388..094a74ddb3 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -27,6 +27,15 @@ ENTRY(compat_hypercall)
pushq $0
movl $TRAP_syscall,4(%rsp)
SAVE_ALL
+
+ cmpb $0,untrusted_msi(%rip)
+ je 1f
+ movl $0x82,%edi
+ call check_for_unexpected_msi
+ RESTORE_ALL
+ SAVE_ALL
+1:
+
GET_CURRENT(%rbx)
cmpl $NR_hypercalls,%eax
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 8d862d5f92..e6483f15db 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -310,6 +310,14 @@ ENTRY(int80_direct_trap)
pushq $0
SAVE_ALL
+ cmpb $0,untrusted_msi(%rip)
+ je 1f
+ movl $0x80,%edi
+ call check_for_unexpected_msi
+ RESTORE_ALL
+ SAVE_ALL
+1:
+
GET_CURRENT(%rbx)
/* Check that the callback is non-null. */
diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
index 7bae0d4d2c..52638101cd 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -42,6 +42,9 @@
#define nr_ioapics iosapic_get_nr_iosapics()
#endif
+/* Possible unfiltered LAPIC/MSI messages from untrusted sources? */
+bool_t __read_mostly untrusted_msi;
+
int nr_iommus;
static bool_t rwbf_quirk;
@@ -1566,6 +1569,14 @@ static int reassign_device_ownership(
if (!pdev)
return -ENODEV;
+ /*
+ * Devices assigned to untrusted domains (here assumed to be any domU)
+ * can attempt to send arbitrary LAPIC/MSI messages. We are unprotected
+ * by the root complex unless interrupt remapping is enabled.
+ */
+ if ( (target != dom0) && !iommu_intremap )
+ untrusted_msi = 1;
+
ret = domain_context_unmap(source, bus, devfn);
if ( ret )
return ret;