KVM: x86: fix singlestepping over syscall
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 7 Jun 2017 13:13:14 +0000 (15:13 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 28 Sep 2017 17:27:56 +0000 (18:27 +0100)
commit803b67e4c1114e7f99c27077ddce806b4cf9f000
tree912a00d9ab74a050baddfb2cce1c377c51f1214d
parent910fbd40b6d251a2e79fadd5eeb162e03787e317
KVM: x86: fix singlestepping over syscall

TF is handled a bit differently for syscall and sysret, compared
to the other instructions: TF is checked after the instruction completes,
so that the OS can disable #DB at a syscall by adding TF to FMASK.
When the sysret is executed the #DB is taken "as if" the syscall insn
just completed.

KVM emulates syscall so that it can trap 32-bit syscall on Intel processors.
Fix the behavior, otherwise you could get #DB on a user stack which is not
nice.  This does not affect Linux guests, as they use an IST or task gate
for #DB.

This fixes CVE-2017-7518.

Cc: stable@vger.kernel.org
Reported-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
[bwh: Backported to 4.9:
 - kvm_vcpu_check_singlestep() sets some flags differently
 - Drop changes to kvm_skip_emulated_instruction()]

Gbp-Pq: Topic bugfix/x86
Gbp-Pq: Name kvm-x86-fix-singlestepping-over-syscall.patch
arch/x86/include/asm/kvm_emulate.h
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c