Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57DFF194124 for ; Thu, 1 May 2025 14:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746109011; cv=none; b=SEgM8UFhRdTONFJyeoVCwbQ0mqFd5r6OlB90w6004sn/gvGpFGMwP2gW1P+0Sdw8BjdWSelf3ZseK7EGecMXrKJGTlVD51HboyHGOqurgEUEZCGYqJT7cLfYld30BgMhR9MjDbuTypB8y7bEpGvipH1QDX6nyGo6pnICUdc/JxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746109011; c=relaxed/simple; bh=LN1GDo4G7iyiuxWvWPHa5lol3NK8D94aBoSF8PItO84=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hhuEs3/Iba4JHx5EEr45ng24xo97b37BIq6VyJsI+EMfEQQsgn0gghxgaWvDkZszXO3bVHijEKEDmr4Q7mR9MOcVhT5UZ/XnX0LkMA+tNwiKZUzkwMg0RWHzhcsunl6S8cd9i2DkOWV3qE8LeTHB6WPbBt6eiI5rm4GS5G6h2H4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eyuK/bGk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="eyuK/bGk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3E7DC4CEEF; Thu, 1 May 2025 14:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1746109011; bh=LN1GDo4G7iyiuxWvWPHa5lol3NK8D94aBoSF8PItO84=; h=From:To:Cc:Subject:Date:Reply-to:From; b=eyuK/bGkzteaVvH88cLRGFKOn1pUOcexLkQtwMwwG7ZupuAGM7qHR3xaOT/68dTrS S3rYwudioAR1h1nPweskGl1TCHrb6sc8S7OYpEbOiapvAbXucXkg9Kq+lhZ6z2KCWy DBDatB/TtYThEfEDcyPnb7msO4h5FfqmlYcObGN8= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49882: KVM: Reject attempts to consume or refresh inactive gfn_to_pfn_cache Date: Thu, 1 May 2025 16:11:12 +0200 Message-ID: <2025050155-CVE-2022-49882-6046@gregkh> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=4148; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=jZOXZtbc/R1OFwLZxPaLEO2c/l/1RkQfWyvw/8q4MBA=; b=owGbwMvMwCRo6H6F97bub03G02pJDBnCDZufT5JssHHesUXQp2/hTumki2evzBMTn31/rUHxD IX56rcVOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAi6/0YFmyKvj2paP8Ubc6L 6fHx2/xvsvxs+84wi4nTeuKeixGKutYHJnPKffzXlX9lHwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: KVM: Reject attempts to consume or refresh inactive gfn_to_pfn_cache Reject kvm_gpc_check() and kvm_gpc_refresh() if the cache is inactive. Not checking the active flag during refresh is particularly egregious, as KVM can end up with a valid, inactive cache, which can lead to a variety of use-after-free bugs, e.g. consuming a NULL kernel pointer or missing an mmu_notifier invalidation due to the cache not being on the list of gfns to invalidate. Note, "active" needs to be set if and only if the cache is on the list of caches, i.e. is reachable via mmu_notifier events. If a relevant mmu_notifier event occurs while the cache is "active" but not on the list, KVM will not acquire the cache's lock and so will not serailize the mmu_notifier event with active users and/or kvm_gpc_refresh(). A race between KVM_XEN_ATTR_TYPE_SHARED_INFO and KVM_XEN_HVM_EVTCHN_SEND can be exploited to trigger the bug. 1. Deactivate shinfo cache: kvm_xen_hvm_set_attr case KVM_XEN_ATTR_TYPE_SHARED_INFO kvm_gpc_deactivate kvm_gpc_unmap gpc->valid = false gpc->khva = NULL gpc->active = false Result: active = false, valid = false 2. Cause cache refresh: kvm_arch_vm_ioctl case KVM_XEN_HVM_EVTCHN_SEND kvm_xen_hvm_evtchn_send kvm_xen_set_evtchn kvm_xen_set_evtchn_fast kvm_gpc_check return -EWOULDBLOCK because !gpc->valid kvm_xen_set_evtchn_fast return -EWOULDBLOCK kvm_gpc_refresh hva_to_pfn_retry gpc->valid = true gpc->khva = not NULL Result: active = false, valid = true 3. Race ioctl KVM_XEN_HVM_EVTCHN_SEND against ioctl KVM_XEN_ATTR_TYPE_SHARED_INFO: kvm_arch_vm_ioctl case KVM_XEN_HVM_EVTCHN_SEND kvm_xen_hvm_evtchn_send kvm_xen_set_evtchn kvm_xen_set_evtchn_fast read_lock gpc->lock kvm_xen_hvm_set_attr case KVM_XEN_ATTR_TYPE_SHARED_INFO mutex_lock kvm->lock kvm_xen_shared_info_init kvm_gpc_activate gpc->khva = NULL kvm_gpc_check [ Check passes because gpc->valid is still true, even though gpc->khva is already NULL. ] shinfo = gpc->khva pending_bits = shinfo->evtchn_pending CRASH: test_and_set_bit(..., pending_bits) The Linux kernel CVE team has assigned CVE-2022-49882 to this issue. Affected and fixed versions =========================== Issue introduced in 5.17 with commit 982ed0de4753ed6e71dbd40f82a5a066baf133ed and fixed in 6.0.8 with commit bfa9672f8fc9eb118124bab61899d2dd497f95ba Issue introduced in 5.17 with commit 982ed0de4753ed6e71dbd40f82a5a066baf133ed and fixed in 6.1 with commit ecbcf030b45666ad11bc98565e71dfbcb7be4393 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-49882 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: virt/kvm/pfncache.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/bfa9672f8fc9eb118124bab61899d2dd497f95ba https://git.kernel.org/stable/c/ecbcf030b45666ad11bc98565e71dfbcb7be4393