From patchwork Thu Apr 27 13:27:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1774455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=ND9Jfn5b; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q6c500Pdbz23v8 for ; Thu, 27 Apr 2023 23:28:36 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ps1fj-00031N-26; Thu, 27 Apr 2023 13:28:31 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ps1fh-0002yo-3K for kernel-team@lists.ubuntu.com; Thu, 27 Apr 2023 13:28:29 +0000 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id D642B3F18A for ; Thu, 27 Apr 2023 13:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1682602108; bh=pYz7fsfLpCd1s5I1BLlnMQdAPBxphq8CQ27PEntokHs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ND9Jfn5bFrrM66TpOdxQ6AJb8yolI2nyrj5uqmDcQCmi//3Cp9LaUKiroEzDZ70Cx 5OpXssUnUKtR3D+1IlFU8eEv7vwZEukzy1P8ghG4wmG2XCdTDUZr+UgUNwmHDFQx3u mLwMhP1DtaOgtVkCmP7E2YXZnEl7+Vise+UIopGCald94ypi7kHdeC8JvPNekXa4ji hCR9kE05W2jxtwB8FyAP1lHg/qyDn6dp0neG8JM/DK01Lr1PpmNNzICE5r3w2v3Lhn TQ694iwN2skc74u9byTnd7UJv7ShaKS8gdDSdQLbg+wxjOLKsxVnOCmz20qio71ct9 8aP+s4q8WyCLg== Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-30479b764f9so1880926f8f.0 for ; Thu, 27 Apr 2023 06:28:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682602107; x=1685194107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pYz7fsfLpCd1s5I1BLlnMQdAPBxphq8CQ27PEntokHs=; b=Y2ENKLniSlVZICDMCNopPcsyYwGYH6JbFkvLSKEMpHCqz+MD8fror30Uu8PL4w2KsI 11AhD/4+EhNJjB3SWODAIHt+syE39zwLFem3CBKglngQHZbnF7V+Jdyx6iXMBtiIJ9R6 rVI+q2+MADtco8C8WyuyL8jqtCgiNOp8J6oHkH95b1meoBDxlatJqXPyjISzua/AR0Qu QLQWW2GxTJWK4yeuyMK5N8Ikn5MMCb7bdJ/qqEecvBj+pGCzCMK5Lp3t/1TZagxao5RE Ld8ocqbpnbLcu9O9prbX3sY4EhqD8+CvMNq7TWKKasF7ToY8EidUtB7ARiF1l4gDAj4H ST1A== X-Gm-Message-State: AC+VfDxydgpuyZ2A9w49S3XKeAP2H2By99punjRKViJyGDP1FejoY3rl 1F+2NEeboWsYI3Q6/wGNclyPjzcJ9WQyoUTDqk5mvFwjFmVHVYLYTbLujMbxLHWvkCZjZ2aTClq hnbB+SXi7wAA3s4CHJx9CE1+e5sYOMvD+GcMVCipDtmk7TCup5p6RidY= X-Received: by 2002:adf:f787:0:b0:2ce:a0e1:f2bb with SMTP id q7-20020adff787000000b002cea0e1f2bbmr1335004wrp.22.1682602107769; Thu, 27 Apr 2023 06:28:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+S6MIROdhTOc3mc6Y10MOU8vj5OFV7SRAr2bt2WXjh70Jw5dcEPaA8CZElGU0XUC1yDexCA== X-Received: by 2002:adf:f787:0:b0:2ce:a0e1:f2bb with SMTP id q7-20020adff787000000b002cea0e1f2bbmr1334990wrp.22.1682602107479; Thu, 27 Apr 2023 06:28:27 -0700 (PDT) Received: from localhost ([176.234.90.117]) by smtp.gmail.com with ESMTPSA id u6-20020adff886000000b002f7780eee10sm18607162wrp.59.2023.04.27.06.28.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 06:28:27 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Focal PATCH v2 1/1] KVM: nVMX: add missing consistency checks for CR0 and CR4 Date: Thu, 27 Apr 2023 16:27:46 +0300 Message-Id: <20230427132744.555509-3-cengiz.can@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230427132744.555509-1-cengiz.can@canonical.com> References: <20230427132744.555509-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Paolo Bonzini commit 112e66017bff7f2837030f34c2bc19501e9212d5 upstream. The effective values of the guest CR0 and CR4 registers may differ from those included in the VMCS12. In particular, disabling EPT forces CR4.PAE=1 and disabling unrestricted guest mode forces CR0.PG=CR0.PE=1. Therefore, checks on these bits cannot be delegated to the processor and must be performed by KVM. Reported-by: Reima ISHII Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman CVE-2023-30456 (cherry picked from commit 65e4c9a6d0c9a8c81ce75576869d46fff5d7964f linux-5.4.y) Signed-off-by: Cengiz Can --- arch/x86/kvm/vmx/nested.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 2551582f4cbd..eeba6a9d56a6 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2779,7 +2779,7 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, u32 *exit_qual) { - bool ia32e; + bool ia32e = !!(vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE); *exit_qual = ENTRY_FAIL_DEFAULT; @@ -2796,6 +2796,13 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, return -EINVAL; } + if (CC((vmcs12->guest_cr0 & (X86_CR0_PG | X86_CR0_PE)) == X86_CR0_PG)) + return -EINVAL; + + if (CC(ia32e && !(vmcs12->guest_cr4 & X86_CR4_PAE)) || + CC(ia32e && !(vmcs12->guest_cr0 & X86_CR0_PG))) + return -EINVAL; + /* * If the load IA32_EFER VM-entry control is 1, the following checks * are performed on the field for the IA32_EFER MSR: @@ -2807,7 +2814,6 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, */ if (to_vmx(vcpu)->nested.nested_run_pending && (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_EFER)) { - ia32e = (vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) != 0; if (CC(!kvm_valid_efer(vcpu, vmcs12->guest_ia32_efer)) || CC(ia32e != !!(vmcs12->guest_ia32_efer & EFER_LMA)) || CC(((vmcs12->guest_cr0 & X86_CR0_PG) &&