linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] KVM: x86: support setting the CPL independent of CS
@ 2014-05-13 14:55 Paolo Bonzini
  2014-05-13 14:55 ` [PATCH 1/5] KVM: x86: support KVM_ENABLE_CAP on vm file descriptors Paolo Bonzini
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Paolo Bonzini @ 2014-05-13 14:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: jan.kiszka, kvm, gleb, avi.kivity

Until now, KVM used to assume that CS.RPL could always be used as the CPL
value when KVM_SET_SREGS is called.  Unfortunately this is not the case.
If userspace decides to call KVM_GET_SREGS/KVM_SET_SREGS exactly after
CR0.PE has been set to 1, but before the long jump that reloads CS, the
CPL will be reset to bits 0-1 of CS (aka CS.RPL).  This can work or not,
depending on the placement of the code that transitions to protected
mode.  If CS.RPL != 0 the emulator will see CS.RPL != CS.DPL (the DPL
will always be zero) and fail to fetch the next instruction of the
transition code.

The same bug exists with SVM, where you don't have the emulator but the
guest will triple fault.  Strangely, it doesn't occur with Intel's
unrestricted guest mode.

To trigger this using QEMU, it is enough to send "info cpus" continuously
while running iPXE (which places its code for real->protected mode in
the EBDA).  iPXE does a lot of transitions, and the guest will crash
very quickly.

Avi or Gleb, this is a bit tricky.  Can you review it please?

Paolo Bonzini (5):
  KVM: x86: support KVM_ENABLE_CAP on vm file descriptors
  KVM: x86: get CPL in KVM_GET_SREGS, prepare to be able to set it
  KVM: vmx: always compute the CPL on KVM_SET_SREGS
  KVM: vmx: force CPL=0 on real->protected mode transition
  KVM: x86: add capability to get/set CPL

 arch/x86/include/asm/kvm_host.h |  4 ++-
 arch/x86/include/uapi/asm/kvm.h |  5 +++-
 arch/x86/kvm/svm.c              | 13 +++++++--
 arch/x86/kvm/vmx.c              | 62 ++++++++++++++++++++++++++---------------
 arch/x86/kvm/x86.c              | 53 +++++++++++++++++++++++++++--------
 include/uapi/linux/kvm.h        |  1 +
 6 files changed, 98 insertions(+), 40 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-05-14  7:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-13 14:55 [PATCH 0/5] KVM: x86: support setting the CPL independent of CS Paolo Bonzini
2014-05-13 14:55 ` [PATCH 1/5] KVM: x86: support KVM_ENABLE_CAP on vm file descriptors Paolo Bonzini
2014-05-13 14:55 ` [PATCH 2/5] KVM: x86: retrieve CPL in KVM_GET_SREGS, prepare to be able to set it Paolo Bonzini
2014-05-13 14:55 ` [PATCH 3/5] KVM: vmx: always compute the CPL on KVM_SET_SREGS Paolo Bonzini
2014-05-13 14:55 ` [PATCH 4/5] KVM: vmx: force CPL=0 on real->protected mode transition Paolo Bonzini
2014-05-13 14:55 ` [PATCH 5/5] KVM: x86: add capability to get/set CPL Paolo Bonzini
2014-05-14  7:47 ` [PATCH 0/5] KVM: x86: support setting the CPL independent of CS Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).