[PATCH v2] x86: apic: pv ipis out-of-bounds access testing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Wanpeng Li <wanpengli@xxxxxxxxxxx>

Dan Carpenter reported that the untrusted data returns from kvm_register_read()
results in the following static checker warning:
  arch/x86/kvm/lapic.c:576 kvm_pv_send_ipi()
  error: buffer underflow 'map->phys_map' 's32min-s32max'

KVM guest can easily trigger this by executing the following assembly sequence 
in Ring0:

mov $10, %rax
mov $0xFFFFFFFF, %rbx
mov $0xFFFFFFFF, %rdx
mov $0, %rsi
vmcall

As this will cause KVM to execute the following code-path:
vmx_handle_exit() -> handle_vmcall() -> kvm_emulate_hypercall() -> kvm_pv_send_ipi()
which will reach out-of-bounds access.

This patch adds the testcase to kvm-unit-tests.

Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Radim Krčmář <rkrcmar@xxxxxxxxxx>
Cc: Liran Alon <liran.alon@xxxxxxxxxx>
Reviewed-By: Liran Alon <liran.alon@xxxxxxxxxx>
Signed-off-by: Wanpeng Li <wanpengli@xxxxxxxxxxx>
---
v1 -> v2:
 * add more changelog
 * arguments are documented in Documentation/virtual/kvm/hypercalls.txt
 * Define KVM_HC_SEND_IPI instead of using hard-coded

 x86/apic.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/x86/apic.c b/x86/apic.c
index c976e8d..6c6ed20 100644
--- a/x86/apic.c
+++ b/x86/apic.c
@@ -566,6 +566,17 @@ static void test_apic_change_mode(void)
 	report("TMCCT should stay at zero", !apic_read(APIC_TMCCT));
 }
 
+#define KVM_HC_SEND_IPI 10
+
+void test_pv_ipi()
+{
+    int ret;
+    unsigned long a0 = 0xFFFFFFFF, a1 = 0, a2 = 0xFFFFFFFF, a3 = 0x0;
+
+    asm volatile("vmcall" : "=a"(ret) :"a"(KVM_HC_SEND_IPI), "b"(a0), "c"(a1), "d"(a2), "S"(a3));
+    report("PV IPIs testing", !ret);
+}
+
 int main(void)
 {
     setup_vm();
@@ -581,6 +592,7 @@ int main(void)
 
     test_self_ipi();
     test_physical_broadcast();
+    test_pv_ipi();
 
     test_sti_nmi();
     test_multiple_nmi();
-- 
2.7.4




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux