From patchwork Thu Apr 27 13:27:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1774454 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=eo5Qd88d; 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 4Q6c4s4PDBz23v8 for ; Thu, 27 Apr 2023 23:28:29 +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 1ps1fc-0002ww-Sk; Thu, 27 Apr 2023 13:28:24 +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 1ps1fb-0002wX-0n for kernel-team@lists.ubuntu.com; Thu, 27 Apr 2023 13:28:23 +0000 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.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-0.canonical.com (Postfix) with ESMTPS id C34A73F18A for ; Thu, 27 Apr 2023 13:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1682602102; bh=k+XiesUgqzXKlpV7nvf2FKNvM8sv63pdJW/tzKa5HjQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eo5Qd88dUlgo1XoQY3vvpGU1s/zXDzbv8ic3N2K5R4YifhGkcLd1855Q5n7PLkgdn jUs9xYkogacljXFQ0s8bz01Xen0Z8anXhwtiNNgfwcnj7czD2dsg+6B62MFdtkBD/Y 5G5kye5YTwvAo4yRY9sfpQUwjgd3fv8KItgPXJZuQ9Cc5ngZtL/fHfsHe82W5Xde0w rXWj6SUQtd4L/mAD80LQ+/AKLO9oeMu4vrhVSa28finkv8dGwaG5WQHqgJbEYixfzC QHk47GmRX33HwFzdEyNnXHVsX1te+ggEyWlTP6kvDxPBkT3RyaJ1hRS1w4CSLL6ORb w2lGm5dNMpoyg== Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-2f831f6e175so4765745f8f.2 for ; Thu, 27 Apr 2023 06:28:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682602102; x=1685194102; 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=k+XiesUgqzXKlpV7nvf2FKNvM8sv63pdJW/tzKa5HjQ=; b=NkRw5w6Vxs+ZI+fYpOekipO96YMLXefaxqySjOqrGP37li7wxUDPy7+BcxGlN0EHHV KlDJVjddZLwl8O38b5cp8Mk+lTUkr7dN9tRI6dkTqFrH9gwngeTzASRPf1uhJKLqgdXw oVeOlJAD5/Ro4CbRgDlDlNYThv7K3S9FcLLwIlWYwM5rb3VtZXuuM44FKuXckrnb8Ohy ZtHacIpmF49n5X5VE4lP64Z4eAqpO0oHPa1U9fZe2d0dJJRPtDdxxroTJ9vyhMd1lnzY AWNLiBG4BElDYVDW13UIjTZroQ4SRu0GxTgQYjX1WXYR1v4ThIy+XnUKL9Bvb1La9zn5 uo+g== X-Gm-Message-State: AC+VfDwLLgZeUR9Kk85v9GtUBKTqjaC2G9iP2/6hSIuwVuApeTChqRZY fCLv6fioandZYjg1U4PKGCkazt4HkSd/4Bqp2PMksY0XIADM8KpCnnd3e3YekwaDmO4IDpvNc8r TOVGXwKH32XamV+Ni9Xdum0D9foQSW2fVJVG7DOrnQd4DWNY6PN6AnJo= X-Received: by 2002:a05:6000:1b8b:b0:2f9:9911:93d1 with SMTP id r11-20020a0560001b8b00b002f9991193d1mr1270736wru.24.1682602102165; Thu, 27 Apr 2023 06:28:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53nkXOxj54S7RQZgEsGvqZgaUrVoQA0+5cLcK+GfGPO0OIbkGoYCaEf+XObCR3RL/Qz7pzNg== X-Received: by 2002:a05:6000:1b8b:b0:2f9:9911:93d1 with SMTP id r11-20020a0560001b8b00b002f9991193d1mr1270723wru.24.1682602101819; Thu, 27 Apr 2023 06:28:21 -0700 (PDT) Received: from localhost ([176.234.90.117]) by smtp.gmail.com with ESMTPSA id h16-20020a5d5490000000b00304b5b2f5ffsm313985wrv.53.2023.04.27.06.28.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 06:28:21 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Jammy, OEM-5.17, Kinetic, OEM-6.0 PATCH v2 1/1] KVM: nVMX: add missing consistency checks for CR0 and CR4 Date: Thu, 27 Apr 2023 16:27:44 +0300 Message-Id: <20230427132744.555509-2-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 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-30456 (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) &&