Skip to content

Commit 65966aa

Browse files
committed
KVM: x86: Assert that the emulator doesn't load CS with garbage in !RM
Yell loudly if KVM attempts to load CS outside of Real Mode without an accompanying control transfer type, i.e. on X86_TRANSFER_NONE. KVM uses X86_TRANSFER_NONE when emulating IRET and exceptions/interrupts for Real Mode, but IRET emulation for Protected Mode is non-existent. WARN instead of trying to pass in a less-wrong type, e.g. X86_TRANSFER_RET, as emulating IRET goes even beyond emulating FAR RET (which KVM also doesn't fully support). Reported-by: Hou Wenlong <houwenlong.hwl@antgroup.com> Link: https://lore.kernel.org/r/20230216202254.671772-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3d8f61b commit 65966aa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/kvm/emulate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,14 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
16401640
goto exception;
16411641
break;
16421642
case VCPU_SREG_CS:
1643+
/*
1644+
* KVM uses "none" when loading CS as part of emulating Real
1645+
* Mode exceptions and IRET (handled above). In all other
1646+
* cases, loading CS without a control transfer is a KVM bug.
1647+
*/
1648+
if (WARN_ON_ONCE(transfer == X86_TRANSFER_NONE))
1649+
goto exception;
1650+
16431651
if (!(seg_desc.type & 8))
16441652
goto exception;
16451653

0 commit comments

Comments
 (0)