From patchwork Thu Apr 27 13:27:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1774456 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=Xk8vY6vz; 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 4Q6c552TxFz23v8 for ; Thu, 27 Apr 2023 23:28:41 +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 1ps1fo-00035n-8R; Thu, 27 Apr 2023 13:28:36 +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 1ps1fm-00034n-MM for kernel-team@lists.ubuntu.com; Thu, 27 Apr 2023 13:28:34 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.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 72EDD3F18A for ; Thu, 27 Apr 2023 13:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1682602114; bh=A2WqOJco5TuOTH3314SyaXNdU51uA1w7yFrybuCkdZo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xk8vY6vzxX6XnXX/H5l8hmzCx0bhmV0tL5q9KXvbC5gfAHuD+F+ijoE0Ik/Rt6OQb dUq48j7LS1jninBB5zNGABYtZJSInK7Ro5fpMZUdc8diZnFbfK5/f7BqefWj96ItPq EgCQT3SClX1HiKpmuADXIoq9ZdjC40dO2HNMu7Zkwl32zFc8uQD0koRJUqur1fILNl KtZnbBPA6E9qmnoHpfs+UA8Wxnz4lpTlmjYjfwHijgjLAwioeRgtBbPbe2O2JfjIyz mmPJbYUmU0aS2auOAlPS61t66fZR4GW/leVAO6SX6L4Ev9hF2h6UJazVHCkl/yJQrb QgRwetMfDzX1g== Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f195129aa4so43299855e9.2 for ; Thu, 27 Apr 2023 06:28:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682602114; x=1685194114; 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=A2WqOJco5TuOTH3314SyaXNdU51uA1w7yFrybuCkdZo=; b=YOJC53fU2VNiL2v71C8Qa4WEMBpSoixVIBndSsBgHbVRkJCFA2Gsza0JW3yPOqTcy3 1hLEK7/MD/ifYlldkFIsFSaMixqU9o5WMlVkgiPSR8Me3o/JBByKMFuAObEdJdVU9wFs GNFNeETIaQ/ZN6tKyvdURSTgqURlr98nHlbuD2QTzQdoVNTJyDy9Y9qnNW0O7xRMWrC1 Y+TKzBuafZut4po/qIEOM01DMKSwV9i/c7iDFNOKxN0I5+TEMBb3hnio4NX8V8tBAkjA eiBY2qzqZMBeqlmzfgHM6QsGOLoZFYxzToXRep24zChyd3v6oothUT7Ia6AGfrTZrnhQ 3OCQ== X-Gm-Message-State: AC+VfDxau8YzYmBrMaWuxYV9cjflKCei0JhXfs+vIFswoh0U05jAKk1Y 44ViS+YAbNj0lAcmwu6001EQvw3YchTRF1zBoaRBnXbd5K3qlHEFFDntRjV0IYQxcRdOTSs1yok wslG7iC/CPn2qHdqGEqUHdM64cBUFLC9uwKgrnhmuE7eMZOFFRHbct0w= X-Received: by 2002:a05:600c:2941:b0:3f2:5777:27d4 with SMTP id n1-20020a05600c294100b003f2577727d4mr1351794wmd.25.1682602113896; Thu, 27 Apr 2023 06:28:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7i+nTgNqx2MA0naYRhaH8xYUNyERI8aepoHh+6qUjJJEYwJzg7G7l9xfeNXa5Z94WryVqncg== X-Received: by 2002:a05:600c:2941:b0:3f2:5777:27d4 with SMTP id n1-20020a05600c294100b003f2577727d4mr1351783wmd.25.1682602113567; Thu, 27 Apr 2023 06:28:33 -0700 (PDT) Received: from localhost ([176.234.90.117]) by smtp.gmail.com with ESMTPSA id n3-20020a7bcbc3000000b003f175b360e5sm21475838wmi.0.2023.04.27.06.28.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 06:28:33 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Bionic PATCH v2 1/1] KVM: nVMX: add missing consistency checks for CR0 and CR4 Date: Thu, 27 Apr 2023 16:27:48 +0300 Message-Id: <20230427132744.555509-4-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 [OP: drop CC() macro calls, as tracing is not implemented in 4.19] [OP: adjust "return -EINVAL" -> "return 1" to match current return logic] Signed-off-by: Ovidiu Panait Signed-off-by: Greg Kroah-Hartman CVE-2023-30456 (cherry picked from commit 495adb06518bb10f50e1aa1a1dbd5daa47d118f2 linux-4.19.y) Signed-off-by: Cengiz Can --- arch/x86/kvm/vmx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 005295f63559..da1ed6d5c04d 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11479,7 +11479,7 @@ static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) static int check_vmentry_postreqs(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; @@ -11493,6 +11493,13 @@ static int check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, return 1; } + if ((vmcs12->guest_cr0 & (X86_CR0_PG | X86_CR0_PE)) == X86_CR0_PG) + return 1; + + if ((ia32e && !(vmcs12->guest_cr4 & X86_CR4_PAE)) || + (ia32e && !(vmcs12->guest_cr0 & X86_CR0_PG))) + return 1; + /* * If the load IA32_EFER VM-entry control is 1, the following checks * are performed on the field for the IA32_EFER MSR: @@ -11504,7 +11511,6 @@ static int check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, */ 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 (!kvm_valid_efer(vcpu, vmcs12->guest_ia32_efer) || ia32e != !!(vmcs12->guest_ia32_efer & EFER_LMA) || ((vmcs12->guest_cr0 & X86_CR0_PG) &&