From patchwork Thu Jun 2 15:05:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1638391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=LF1XUXU1; dkim-atps=neutral Authentication-Results: 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=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDTrY3sXjz9s75 for ; Fri, 3 Jun 2022 01:07:09 +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 1nwmPg-0001MI-QF; Thu, 02 Jun 2022 15:07:04 +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 1nwmPf-0001LI-N7 for kernel-team@lists.ubuntu.com; Thu, 02 Jun 2022 15:07:03 +0000 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (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 366613F21D for ; Thu, 2 Jun 2022 15:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1654182423; bh=ZhYIS1OLGX7blXnD2JUpYiUBKE4SmlO7mkUzCfvyGJ4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LF1XUXU15wTS4e7SpdRswWlpfQJYyCffnX6pF389h2T33UkQPdmfs2ZJI0XhWMcdo Snu34Yk5Z+aiWqIP41py36Cvi28ub1qT85V7bec0JCkRNosEyQcoQ9Ut+Pe/RfPJ5r AMDhqmnxKo3kNeTXoJMMAT6H8YgL1iaLA05BGFkNVRPGA+b3QqhE3BMQCG833pGR79 QcvYP7kLvpnTFUzCiT3vLBh0oQkFq+UBSfex5+v+dyFERIPBy3oEom7dqaZKvgKEIG i38WwMfXumM9N3MQMJxOWAADX0g9o8mzt4Wheveu5+mUQxhyj1Fq6at48IEZniIZk1 KdeYghhExxF9g== Received: by mail-wm1-f72.google.com with SMTP id bg7-20020a05600c3c8700b0039468585269so2554785wmb.3 for ; Thu, 02 Jun 2022 08:07:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZhYIS1OLGX7blXnD2JUpYiUBKE4SmlO7mkUzCfvyGJ4=; b=XxP11QyGurWDdx1lUCvBeGcrLX2BU+ZLcMkb6SMkVP+cSOb8z095cBK4gY7b2C2zpV FVx9lmLLb+xlT53GezvN3sB/qMf3Vc9u2gRh3boWZ4PJSYidf/OkqL7USAtzF7b6/QSw VXvtgnTRySSUzWCXGiAcwIOI0+bnJ+XUq9auH28cT/9TVIifakQeyD0xtlf3U2rQy4bX JegPlG2DUa8sJ5YLtWXfGuG5BZ+y4VKqaITirCD3hZ/swVPqQC6lGTUNcYiQdgYG0bjB M71IESF2yUzKj+2ainjn6aWgwjhZu75ofu26gG2FXNNwVZ7wI2oZZuqv/US2T2xOhAcM p1Ww== X-Gm-Message-State: AOAM5328anyb+iEmQzP95iioAYSDkJ/G7pC2hwlJLK2B6Y6K3dloe71g d8emdtObJ23GuCEQ2GDk2a+buohhQIF8GQFgbipfF7k7JphX2WlC6GvDKH/KwTTMd6zd9XJb7fr KrykZ4i9N5Ns+Bxmr+GjHkSgoOp6mCOtbVJeK79tlSA== X-Received: by 2002:a5d:6583:0:b0:212:1125:1442 with SMTP id q3-20020a5d6583000000b0021211251442mr4291425wru.45.1654182422250; Thu, 02 Jun 2022 08:07:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu6hlDFOTxO+ufC3I/Pdx2ToywapNnaKrFttPl7jk4mhwtfxVxOlp7twPKe0gZ0EY8MZkSzg== X-Received: by 2002:a5d:6583:0:b0:212:1125:1442 with SMTP id q3-20020a5d6583000000b0021211251442mr4291400wru.45.1654182421935; Thu, 02 Jun 2022 08:07:01 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1560:8007::aac:c03c]) by smtp.gmail.com with ESMTPSA id az29-20020a05600c601d00b00398d2f6b5d8sm6118339wmb.4.2022.06.02.08.07.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 08:07:01 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/1] KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID Date: Thu, 2 Jun 2022 18:05:15 +0300 Message-Id: <20220602150513.494225-4-cengiz.can@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220602150513.494225-1-cengiz.can@canonical.com> References: <20220602150513.494225-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 CVE-2022-1789 With shadow paging enabled, the INVPCID instruction results in a call to kvm_mmu_invpcid_gva. If INVPCID is executed with CR0.PG=0, the invlpg callback is not set and the result is a NULL pointer dereference. Fix it trivially by checking for mmu->invlpg before every call. There are other possibilities: - check for CR0.PG, because KVM (like all Intel processors after P5) flushes guest TLB on CR0.PG changes so that INVPCID/INVLPG are a nop with paging disabled - check for EFER.LMA, because KVM syncs and flushes when switching MMU contexts outside of 64-bit mode All of these are tricky, go for the simple solution. This is CVE-2022-1789. Reported-by: Yongkang Jia Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini (backported from commit 9f46c187e2e680ecd9de7983e4d081c3391acc76) [cengizcan: use mmu->root_hpa instead of non-existing mmu->root.hpa] [cengizcan: adapted for 5.15 due to path and context differences] Signed-off-by: Cengiz Can --- arch/x86/kvm/mmu/mmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 34e828badc51..62addcb98be7 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5394,14 +5394,16 @@ void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid) uint i; if (pcid == kvm_get_active_pcid(vcpu)) { - mmu->invlpg(vcpu, gva, mmu->root_hpa); + if (mmu->invlpg) + mmu->invlpg(vcpu, gva, mmu->root_hpa); tlb_flush = true; } for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) { if (VALID_PAGE(mmu->prev_roots[i].hpa) && pcid == kvm_get_pcid(vcpu, mmu->prev_roots[i].pgd)) { - mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa); + if (mmu->invlpg) + mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa); tlb_flush = true; } }