android_kernel_samsung_msm8976/arch/x86/kvm
Radim Krčmář 618fedd40d KVM: VMX: disable PEBS before a guest entry
commit 7099e2e1f4d9051f31bbfa5803adf954bb5d76ef upstream.

Linux guests on Haswell (and also SandyBridge and Broadwell, at least)
would crash if you decided to run a host command that uses PEBS, like
  perf record -e 'cpu/mem-stores/pp' -a

This happens because KVM is using VMX MSR switching to disable PEBS, but
SDM [2015-12] 18.4.4.4 Re-configuring PEBS Facilities explains why it
isn't safe:
  When software needs to reconfigure PEBS facilities, it should allow a
  quiescent period between stopping the prior event counting and setting
  up a new PEBS event. The quiescent period is to allow any latent
  residual PEBS records to complete its capture at their previously
  specified buffer address (provided by IA32_DS_AREA).

There might not be a quiescent period after the MSR switch, so a CPU
ends up using host's MSR_IA32_DS_AREA to access an area in guest's
memory.  (Or MSR switching is just buggy on some models.)

The guest can learn something about the host this way:
If the guest doesn't map address pointed by MSR_IA32_DS_AREA, it results
in #PF where we leak host's MSR_IA32_DS_AREA through CR2.

After that, a malicious guest can map and configure memory where
MSR_IA32_DS_AREA is pointing and can therefore get an output from
host's tracing.

This is not a critical leak as the host must initiate with PEBS tracing
and I have not been able to get a record from more than one instruction
before vmentry in vmx_vcpu_run() (that place has most registers already
overwritten with guest's).

We could disable PEBS just few instructions before vmentry, but
disabling it earlier shouldn't affect host tracing too much.
We also don't need to switch MSR_IA32_PEBS_ENABLE on VMENTRY, but that
optimization isn't worth its code, IMO.

(If you are implementing PEBS for guests, be sure to handle the case
 where both host and guest enable PEBS, because this patch doesn't.)

Fixes: 26a4f3c08d ("perf/x86: disable PEBS on a guest entry.")
Reported-by: Jiří Olša <jolsa@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-16 08:41:35 -07:00
..
cpuid.c KVM: x86: Make register state after reset conform to specification 2012-12-05 18:00:07 +02:00
cpuid.h Merge tag 'kvm-3.8-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm 2012-12-13 15:31:08 -08:00
emulate.c KVM: x86: SYSENTER emulation is broken 2015-04-29 10:33:59 +02:00
i8254.c KVM: x86: make vapics_in_nmi_mode atomic 2015-07-10 10:40:22 -07:00
i8254.h KVM: fold kvm_pit_timer into kvm_kpit_state 2012-08-01 00:21:07 -03:00
i8259.c KVM: inject ExtINT interrupt before APIC interrupts 2012-12-13 23:05:21 -02:00
irq.c KVM: nVMX: fix "acknowledge interrupt on exit" when APICv is in use 2014-09-05 16:28:35 -07:00
irq.h
Kconfig kvm: Allow build-time configuration of KVM device assignment 2013-04-28 12:58:56 +03:00
kvm_cache_regs.h
lapic.c KVM: x86: make vapics_in_nmi_mode atomic 2015-07-10 10:40:22 -07:00
lapic.h kvm: x86: fix kvm_apic_has_events to check for NULL pointer 2015-08-16 20:51:43 -07:00
Makefile kvm: Allow build-time configuration of KVM device assignment 2013-04-28 12:58:56 +03:00
mmu.c KVM: MMU: fix CR4.SMEP=1, CR0.WP=0 with shadow pages 2015-06-05 23:19:54 -07:00
mmu.h KVM: MMU: Rename kvm_mmu_free_some_pages() to make_mmu_pages_available() 2013-03-21 19:45:01 -03:00
mmu_audit.c KVM: do not release the error pfn 2012-08-06 16:04:57 +03:00
mmutrace.h KVM: mmu: remove unused trace event 2013-01-07 19:54:50 -02:00
paging_tmpl.h KVM: x86: handle invalid root_hpa everywhere 2014-03-31 09:58:14 -07:00
pmu.c pmu: prepare for migration support 2013-04-02 17:42:44 +03:00
svm.c Use WARN_ON_ONCE for missing X86_FEATURE_NRIPS 2015-10-22 14:37:49 -07:00
trace.h KVM: x86: require matched TSC offsets for master clock 2012-11-27 23:29:15 -02:00
tss.h
vmx.c KVM: VMX: disable PEBS before a guest entry 2016-03-16 08:41:35 -07:00
x86.c KVM: x86: update masterclock values on TSC writes 2015-03-06 14:40:52 -08:00
x86.h kvm: x86: fix stale mmio cache bug 2014-10-30 09:35:09 -07:00