KVM: x86: Emulator fixes for eip canonical checks on near branches
authorNadav Amit <namit@cs.technion.ac.il>
Thu, 18 Sep 2014 19:39:38 +0000 (22:39 +0300)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 5 Nov 2014 20:27:48 +0000 (20:27 +0000)
commit71ca9dc31fd6cd39ade2b3b6f1fa8fe4f2a915fa
treef9a6660d091a95f4aa716470ca3fedf8ba513ca7
parentea8064a24d587a95e3018f4aa5e218902a6d1734
KVM: x86: Emulator fixes for eip canonical checks on near branches

commit 234f3ce485d54017f15cf5e0699cff4100121601 upstream.

Before changing rip (during jmp, call, ret, etc.) the target should be asserted
to be canonical one, as real CPUs do.  During sysret, both target rsp and rip
should be canonical. If any of these values is noncanonical, a #GP exception
should occur.  The exception to this rule are syscall and sysenter instructions
in which the assigned rip is checked during the assignment to the relevant
MSRs.

This patch fixes the emulator to behave as real CPUs do for near branches.
Far branches are handled by the next patch.

This fixes CVE-2014-3647.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[bwh: Backported to 3.2:
 - Adjust context
 - Use ctxt->regs[] instead of reg_read(), reg_write(), reg_rmw()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/x86/kvm/emulate.c