From patchwork Thu Jun 2 15:05:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1638389 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=VS57T0FK; 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 4LDTqz2gVpz9s75 for ; Fri, 3 Jun 2022 01:06: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 1nwmPC-00014Q-DH; Thu, 02 Jun 2022 15:06:34 +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 1nwmP9-000136-PN for kernel-team@lists.ubuntu.com; Thu, 02 Jun 2022 15:06:31 +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-1.canonical.com (Postfix) with ESMTPS id 794203FBF6 for ; Thu, 2 Jun 2022 15:06:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1654182391; bh=DHnnWC4yQnEmkQJI2BvTnlRT/RN/J60Wdnvrqk1WYyM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VS57T0FKpi2DMNdxMqwApqQ7IZP2PknuxQ9+8Ni0GWTlQz+ZlsQ5HG4GurLdPnWcY +xjHoyky5uZWwjpFelp/DkXjcDnOnfASfgYMv5tVEOEoT42Nfy5gf6O00SC8gg5FN5 VmQODCY6O6RFjoioz3EMKkCk4mDEbeCJDWs9/3gL9Ymh360rxnYN75WEIP50aP0kYT dAd7qc3uaBLkim7Kgl54Vb/AAeYXYryqiMdZzXQ8AjgfeHcN7IpuW916h8LzpIDUAh aQd0eUcds8lRGxILMUUXM7cHsAPzmmaocq3Tnjos3NR5GK+GVDgP+L7+405ENbRsTc Wd/BxvD8suxjg== Received: by mail-wm1-f70.google.com with SMTP id k5-20020a05600c1c8500b003974c5d636dso2982388wms.1 for ; Thu, 02 Jun 2022 08:06:31 -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=DHnnWC4yQnEmkQJI2BvTnlRT/RN/J60Wdnvrqk1WYyM=; b=cojrMbDyuegj3uMry+I7sygVuOAgRWrK65CRkvKaY6CK3ZkxGYKB4yfTqDNQrOeEPF jjcBcyv+UZ1mQkAraQ1fyk4yQQJZ3oy8aPgJJWj80Oq2GuQV2AYTwOKXZcOch/e1w70/ 9JcbIwi+NXuXU74Qw44nfC1m3XKo5o4IxylCnVjEzVqDVVLn0QjPFJSxzEej+VVtemSl YaFbDl8gZlJDyQzG7IR4j2/mkmZf/OCSXAfR1WKsN3kG/61a0J69u+1+PMl+BCo1VvRX WiYM95QA6u80dttDZlhwpNPN4P8Zyz75DV3SzX/VaJozmXJ1Sjo+d684z/J+gbg5o9p2 51Mw== X-Gm-Message-State: AOAM530mXYAJnV04f5wAbprAIZ7UlJQHcoOI06gs7sKb2v5HE9y9Wg1M d/ZWkrGvCZh1jPQqIFasN80P9PbF5yPTUzekwOVFB7sFVQYdv/TY9oe+RM3XTBm8xfh6l1nPXQY 7ga60+6qN3CH90DPzJ0ubOavkYep3929GfTSzlebGjg== X-Received: by 2002:a5d:64a9:0:b0:210:3d60:f2b4 with SMTP id m9-20020a5d64a9000000b002103d60f2b4mr4124884wrp.432.1654182390910; Thu, 02 Jun 2022 08:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUaJhjEoE+A4Pa+kGTGB2CnRoxMHhO9HAZdOAHcJQFMyRKPhO6LEtHtchgv1ozyEXD6gTLPg== X-Received: by 2002:a5d:64a9:0:b0:210:3d60:f2b4 with SMTP id m9-20020a5d64a9000000b002103d60f2b4mr4124863wrp.432.1654182390660; Thu, 02 Jun 2022 08:06:30 -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.06.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 08:06:30 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 1/1] KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID Date: Thu, 2 Jun 2022 18:05:11 +0300 Message-Id: <20220602150513.494225-2-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.4 due to path and context differences] Signed-off-by: Cengiz Can --- arch/x86/kvm/mmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index d3877dd713ae..fd1748ea4e44 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5636,14 +5636,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].cr3)) { - mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa); + if (mmu->invlpg) + mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa); tlb_flush = true; } }