From patchwork Thu Apr 27 02:21:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1774319 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=YjIb+sNo; 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 4Q6KJb34zfz23vL for ; Thu, 27 Apr 2023 12:22:39 +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 1prrHF-0005vN-VT; Thu, 27 Apr 2023 02:22:33 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1prrHC-0005u8-DM for kernel-team@lists.ubuntu.com; Thu, 27 Apr 2023 02:22:30 +0000 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) (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-1.canonical.com (Postfix) with ESMTPS id 837693F229 for ; Thu, 27 Apr 2023 02:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1682562149; bh=6xrtt5DGtHjXu4ACmramSB5VOx10Avo9F+bkvhdIBqY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YjIb+sNokLptjfd2fClgXbSVf39g4QDOa2FVNYhlhen0QDoar5h/fGPm1AgF7PpOa 8yLuR1Y8WXM7LF/vpngGDTxdA5DWOP5kNwOI+iMtLJ6qmxjkrfs6iCjRvrNwTgm8yp 2uO/t8FEeHYkpbt+kPO9XFa2PZSviDXtBrgSZz0djhy3qc6TUiRHJX0cHJuwWpUGrP 4367sZrBhxFvNM/NlnrBlneVl+DtTBBGBr1WiZMt3fgj7Tgwrf409/HZiCXhi87E1Q dxlwmtlfRPViT+WD0ZHkRTR/0izES9WEH7vvBRojLJls7Tfu9MuGB/8OW8kyQ1rjRn spMI4AaIYTdow== Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-6a5ff9cefbeso6447063a34.3 for ; Wed, 26 Apr 2023 19:22:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682562148; x=1685154148; 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=6xrtt5DGtHjXu4ACmramSB5VOx10Avo9F+bkvhdIBqY=; b=AX1emtOtX5AALqTBL0EdW9IzkPTcD0OF5+4L5EpRVdA34QaARZzxchlruUrkCTc1VC SrzpsCoW7To4Aq8DauN6O64uVJBopZDNezd8tub8R22IdZY4r2gkJ1ZZYi1kBAax3F5W k9z8LIAXvoOzUTri6xxzGctSV9CJIiF8o4jOyTb3l8Pi9mzn5tEefVRV/eYraAQzQuCU oBD5atBBNr8YGvvPABeL42W6nBDZbziACFqpRe53IRLvSBJNdwPGW/XU1Aa8AjYFvFgJ nsPqAav5qWwLZ2sYVDUHK2i0EBS1qfhD/ou9m/p/+t9YwE7gf/j7MDZ0fa4g9Oc4gDvF iE0w== X-Gm-Message-State: AAQBX9frlVOzPchsLgFpW+uLvBLwyuNLpNmGH+9Wlw84mWxklO31Ywmi UMiK0qO3VyaksgD+i3P+jJe1aJGJ0WEWUkvovhQK3v9bOQORuG47+wUy6EkTiEOZI2aloqpk8uA mpEnMhZ3RnEOmeWYwwPGfWMXkP+25pQMfXLXCBK59oX+KOK8Nfa3GGug= X-Received: by 2002:a9d:6b98:0:b0:6a4:2df4:761e with SMTP id b24-20020a9d6b98000000b006a42df4761emr11551543otq.25.1682562148036; Wed, 26 Apr 2023 19:22:28 -0700 (PDT) X-Google-Smtp-Source: AKy350bdJ7KmWVcRdfO4b0NXJqEtZzx7o/uvHB3MYcxbyglPYGNV2iww7srEVDfDNhoab3kaHcMG4w== X-Received: by 2002:a9d:6b98:0:b0:6a4:2df4:761e with SMTP id b24-20020a9d6b98000000b006a42df4761emr11551538otq.25.1682562147710; Wed, 26 Apr 2023 19:22:27 -0700 (PDT) Received: from localhost ([2001:67c:1560:8007::aac:c03c]) by smtp.gmail.com with ESMTPSA id i14-20020a056830010e00b006a5e22458e9sm7541695otp.80.2023.04.26.19.22.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 19:22:27 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Jammy, OEM-5.17, OEM-6.0 1/1] KVM: nVMX: add missing consistency checks for CR0 and CR4 Date: Thu, 27 Apr 2023 05:21:10 +0300 Message-Id: <20230427022110.544535-2-cengiz.can@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230427022110.544535-1-cengiz.can@canonical.com> References: <20230427022110.544535-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 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 CVE-2023-28464 (cherry picked from commit 112e66017bff7f2837030f34c2bc19501e9212d5) 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 f3c136548af6..e4e4c1d3aa17 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2991,7 +2991,7 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, enum vm_entry_failure_code *entry_failure_code) { - bool ia32e; + bool ia32e = !!(vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE); *entry_failure_code = ENTRY_FAIL_DEFAULT; @@ -3017,6 +3017,13 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, vmcs12->guest_ia32_perf_global_ctrl))) 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: @@ -3028,7 +3035,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) &&