From nobody Thu Sep 11 18:26:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67588C636CC for ; Thu, 16 Feb 2023 20:23:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbjBPUXA (ORCPT ); Thu, 16 Feb 2023 15:23:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjBPUW5 (ORCPT ); Thu, 16 Feb 2023 15:22:57 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E568C2A6C2 for ; Thu, 16 Feb 2023 12:22:56 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id y15-20020a1709029b8f00b00198e0564d73so1590736plp.22 for ; Thu, 16 Feb 2023 12:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=vCcncjl9vBVTEjELfag9S1oLRHyPwIXh9OBkmmp9fyQ=; b=NTpw1IWK3yxfTwGuflws4m5YpI8z8UgmraB7YS1w/S3ByOhCFacaKx7rycLIedDkCn jJUHfxI3ogukVrFzv/nYaeBLtbKVDtyHlsfZmhX1EjbJZut+AbB4u1qMweHYauWd3FiB jptZBQsHE5XmbvRFBawO9ymKexULzaGA4+zGWMmM5XiMuqMu08n3kCGlociec9zueD5e n0YMjDPMCINMWK/CU3c9sxnop9ActkMTr8nIypll3yp9JGWRwdYNCq/CnmGL41wLnkwn uCQivV48xRDy0XYjNZwOOrzU3QYfg+iHNfMGK8xR6iu/h2bmUy0twRglIkpI3AgKfu8O 06mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vCcncjl9vBVTEjELfag9S1oLRHyPwIXh9OBkmmp9fyQ=; b=TTRVXJ+IQ1w6FuNC4sKAJ6uI6Hm961sd0FaNl4JuwJ6hxfDlttWDOfe+wLmMZzbKou 1T2CXvvWGqckzYu1E2BQqu8iRwn2z6GnqpimPogHZkxf/KkShUW59W/42eAPjZJX9Vsf Rc4bCjJKlG/SHqVry5KrsKmI/CgMHgy/rhq/oFqecpBnlVE9ZizDcP9YnRwCh2vx9GFs bfNhx/R4mUsPjSTeZHzWW7d7JR7TbYSiQ+P6FuSsiyl6X50sGAevXDW+ALXeTMQ8GX4X jJvELjgs/xH9WoAFjNJMPzwpS5HY8zc+2aygiMCKKw9So7Xa6Kg1Hj5rOLTEdq2QFgmh 9M1A== X-Gm-Message-State: AO0yUKXd8xFQsfgSxp53sCQuj4L6z+xtaLfQCtkY7NQbMEpVX1UfSioY QKXmfMtYnxcABIDp8En++VVWTP+LsK0= X-Google-Smtp-Source: AK7set/C3eyoe44sPAK5448q8AkTUZPYBdSEOdPc/EdG3pQncPT5DGKzeV84EYJMZ2sfGXKPDmrwVbH11QQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:755d:0:b0:4fc:8b10:870 with SMTP id f29-20020a63755d000000b004fc8b100870mr35550pgn.5.1676578976283; Thu, 16 Feb 2023 12:22:56 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 16 Feb 2023 12:22:54 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230216202254.671772-1-seanjc@google.com> Subject: [PATCH] KVM: x86: Assert that the emulator doesn't load CS with garbage in !RM From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Hou Wenlong Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index baf97c56aefa..07e5f473f6fe 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -1640,6 +1640,14 @@ static int __load_segment_descriptor(struct x86_emul= ate_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 =3D=3D X86_TRANSFER_NONE)) + goto exception; + if (!(seg_desc.type & 8)) goto exception; =20 base-commit: 62ef199250cd46fb66fe98267137b7f64e0b41b4 --=20 2.39.2.637.g21b0678d19-goog