android_kernel_samsung_msm8976/arch
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
..
alpha vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
arc ARC: dw2 unwind: Remove falllback linear search thru FDE entries 2016-03-03 15:06:21 -08:00
arm ARM: 8517/1: ICST: avoid arithmetic overflow in icst_hz() 2016-02-25 11:57:48 -08:00
arm64 arm64: mm: ensure that the zero page is visible to the page table walker 2016-01-28 21:49:36 -08:00
avr32 vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
blackfin
c6x C6x: time: Ensure consistency in __init 2015-05-06 21:56:28 +02:00
cris vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
frv vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
h8300
hexagon arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
ia64 vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
m32r m32r: fix m32104ut_defconfig build fail 2016-02-25 11:57:49 -08:00
m68k m68k/uaccess: Fix asm constraints for userspace access 2015-10-27 09:44:49 +09:00
metag vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
microblaze vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
mips MIPS: KVM: Uninit VCPU in vcpu_create error path 2016-03-03 15:06:20 -08:00
mn10300 mn10300: Select CONFIG_HAVE_UID16 to fix build failure 2016-01-28 21:49:37 -08:00
openrisc openrisc: fix CONFIG_UID16 setting 2016-01-28 21:49:36 -08:00
parisc parisc: Fix __ARCH_SI_PREAMBLE_SIZE 2016-02-19 14:22:38 -08:00
powerpc powerpc: Make {cmp}xchg* and their atomic_ versions fully ordered 2016-01-28 21:49:35 -08:00
s390 s390: fix normalization bug in exception table sorting 2016-03-03 15:06:22 -08:00
score vm: add VM_FAULT_SIGSEGV handling support 2015-04-29 10:34:00 +02:00
sh sh64: fix __NR_fgetxattr 2016-02-19 14:22:38 -08:00
sparc sparc64: fix incorrect sign extension in sys_sparc64_personality 2016-03-03 15:06:23 -08:00
tile tile: use free_bootmem_late() for initrd 2015-08-10 12:20:30 -07:00
um uml: flush stdout before forking 2016-03-03 15:06:23 -08:00
unicore32 nosave: consolidate __nosave_{begin,end} in <asm/sections.h> 2015-05-06 21:56:28 +02:00
x86 KVM: VMX: disable PEBS before a guest entry 2016-03-16 08:41:35 -07:00
xtensa xtensa: don't use echo -e needlessly 2015-09-21 10:00:10 -07:00
.gitignore
Kconfig