From patchwork Thu Jun 2 15:05:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1638393 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=UajWeP3V; 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 4LDTs21mhyz9s75 for ; Fri, 3 Jun 2022 01:07:34 +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 1nwmQ5-0001i5-BD; Thu, 02 Jun 2022 15:07:29 +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 1nwmQ3-0001hl-Qg for kernel-team@lists.ubuntu.com; Thu, 02 Jun 2022 15:07:27 +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 8A0FA3FC08 for ; Thu, 2 Jun 2022 15:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1654182447; bh=2Mj36s2uMzHLcRIZS8BTJsLnJ3GFKzDJ1ckVIn4bOVg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UajWeP3V0pBESSzka3bk5pL/r0DeGNctTrMdmjNb/GSxP7U1ILXK7neNMxa8Q8ZqY 27et4AmJvpVbCgvnDjy1/8zR3EiFavS5TuDndl6itOw4qkDW4/zDjkV/hWRnBiMlL+ q0ew2g4hbRuk67ea/2CMFhFimtQgb1L+m07WDNatiYqeorqBw8l6FBee4asfqMYSBe jcp+1HN5epb0hS6sUqFhKPNrnQLhlwQuxiAKfcD5jEONOpUgCl4F0wPnOn8P3BEoe0 EBcBq2K67bIvng/z6f98ctFaJtcaeUnnq9qvi/KjVRrGyJ1IdWXXmGBpvvFxDubfd8 +lYWmRTXNJ1QQ== Received: by mail-wr1-f70.google.com with SMTP id i10-20020a5d55ca000000b002103d76ffcaso799296wrw.17 for ; Thu, 02 Jun 2022 08:07:27 -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=2Mj36s2uMzHLcRIZS8BTJsLnJ3GFKzDJ1ckVIn4bOVg=; b=G5vsfx2e+ydf6plLwO7fLg7LnjFfJHzwadZkZNXH4VgwSYDPYSFBt6aIzqtsDQmOJJ lKUTiWO0In70w2LybkkQZMQKPp0+1S198/2Pv2jf4wjVOBXhxA6pHXThj21sEHnrnIhE BtCLEu8uxTrxGG22dxgOIUORdy22ubm6ONghx0HABtuY3ytp9kRdlJzBmrbfSCYQX6O2 XKvyJEm9hoGymHWdDaSSgin99++t+l3MwNbKxnrnqPuR+M4j9GrXlqkJ5QtMifjt+JyK DuL3jjCZ8s/WQ6bAn4wYa8OHCebjrJq9JSugpmvhGtkvC/SyE6AJuBLcwO36rR0jaWLY 58Cw== X-Gm-Message-State: AOAM533/t2TMqC/zLrqKAkXuddSSIX2ey5plohALHb09iPFAcQwcUQjR Uv3oi0jxEmaRSIt3KbRkKHQlWX1GqRd9Mzrdi+4xcuSwNQKYoQ/BSXBk07KZ1IY0CmIa5Uv0/TL QXuHiAruJeLm/LqXIzMx40/bVIxg1O+iIYF8ZfMhyyQ== X-Received: by 2002:a5d:65c1:0:b0:210:33b7:4525 with SMTP id e1-20020a5d65c1000000b0021033b74525mr4080345wrw.494.1654182446948; Thu, 02 Jun 2022 08:07:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7RIPzarRQXUYJjEFzzTzqo4qfzOd8q3kpuaV5rDJWS4j9h3S83LFPR+j7GmAsi7jLVDHJ/w== X-Received: by 2002:a5d:65c1:0:b0:210:33b7:4525 with SMTP id e1-20020a5d65c1000000b0021033b74525mr4080332wrw.494.1654182446718; Thu, 02 Jun 2022 08:07:26 -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.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 08:07:26 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU][oem-5.17][PATCH 1/1] KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID Date: Thu, 2 Jun 2022 18:05:19 +0300 Message-Id: <20220602150513.494225-6-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 oem-5.17 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 5628d0ba637e..944f0ee8072a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5414,14 +5414,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; } }