From: Sean Christopherson Date: Thu, 16 Feb 2023 20:22:54 +0000 (-0800) Subject: KVM: x86: Assert that the emulator doesn't load CS with garbage in !RM X-Git-Tag: v6.6.7~2927^2~5^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65966aaca18a5cbf42ac22234cb9cbbf60a4d33c;p=platform%2Fkernel%2Flinux-starfive.git 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 Link: https://lore.kernel.org/r/20230216202254.671772-1-seanjc@google.com Signed-off-by: Sean Christopherson --- diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index a20bec9..936a397 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -1640,6 +1640,14 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt, goto exception; break; case VCPU_SREG_CS: + /* + * KVM uses "none" when loading CS as part of emulating Real + * Mode exceptions and IRET (handled above). In all other + * cases, loading CS without a control transfer is a KVM bug. + */ + if (WARN_ON_ONCE(transfer == X86_TRANSFER_NONE)) + goto exception; + if (!(seg_desc.type & 8)) goto exception;