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 4FB342AF00 for ; Sat, 4 Oct 2025 15:16:59 +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=1759591020; cv=none; b=Y+UoKgVCnc7lK/3fUz6PgODvVOzXK0URYVRr4z8gJTq1lfUu+dQcZnPoXBqI3CcAahSbUHPpMjMcmIqovVofLoLZ/n+PAzN5sp2f4mBswPAloVVDj2UZbVBZXCa8dsg/4zCuBPSlAhe1Tm7Tcsxg+qCQh94cmpoYd9kxn6tNOVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759591020; c=relaxed/simple; bh=qDdRB2g8LLBQskHEZRMT4dHFpcxs73afKcMGUU6t9Sg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZnTLWKtK5cInuhRkHcTPAIwD17/aqz7h2hmayjqGkyr7erz3MMdmnyQcjNGSVH1rwVUmfqlckVTkx2KK9H+OwphZ27dyUlXRc/G+5Dm3xViHTRZYJw4AJ8baHBCDw8Tot8VTxviaGXB1JeHhbcSgZ9LsCiH3TnTst/NSljI1HzY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GRbk5DGc; 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="GRbk5DGc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 695B3C4CEF1; Sat, 4 Oct 2025 15:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759591019; bh=qDdRB2g8LLBQskHEZRMT4dHFpcxs73afKcMGUU6t9Sg=; h=From:To:Cc:Subject:Date:Reply-to:From; b=GRbk5DGcSbI1qWU0cWG2u4jF2iSqVE/keM9OD2im5s4hCcRSwrMz0rJ686qJbPqkQ aQLy69kQjnUkf4+2uSMWpb71hhiRoLCr16JYG9JT0R/Jee3Ox2aDZfwO382e2Ot7dC MUOz+i8Z+RdkxFrZhArmuM+rjWDxMMpYlOA6Irmw= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50471: xen/gntdev: Accommodate VMA splitting Date: Sat, 4 Oct 2025 17:16:30 +0200 Message-ID: <2025100436-CVE-2022-50471-a799@gregkh> X-Mailer: git-send-email 2.51.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=6103; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=OuinLh8Qr/uD1TZnFU4WCrU+S4ZyGs1FoKmtaPCpOfA=; b=owGbwMvMwCRo6H6F97bub03G02pJDBkPrUImix2Qv867xNvF5eGb2RxJFxY7nP/75MZhwz+2B scVItZzdsSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEAtIY5vufCzjKuifOtV5O q/SWI++9YAmPIwzz7MVeb47pmjPdbXXE4i3rVSatv/ryDwA= 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: xen/gntdev: Accommodate VMA splitting Prior to this commit, the gntdev driver code did not handle the following scenario correctly with paravirtualized (PV) Xen domains: * User process sets up a gntdev mapping composed of two grant mappings (i.e., two pages shared by another Xen domain). * User process munmap()s one of the pages. * User process munmap()s the remaining page. * User process exits. In the scenario above, the user process would cause the kernel to log the following messages in dmesg for the first munmap(), and the second munmap() call would result in similar log messages: BUG: Bad page map in process doublemap.test pte:... pmd:... page:0000000057c97bff refcount:1 mapcount:-1 \ mapping:0000000000000000 index:0x0 pfn:... ... page dumped because: bad pte ... file:gntdev fault:0x0 mmap:gntdev_mmap [xen_gntdev] readpage:0x0 ... Call Trace: dump_stack_lvl+0x46/0x5e print_bad_pte.cold+0x66/0xb6 unmap_page_range+0x7e5/0xdc0 unmap_vmas+0x78/0xf0 unmap_region+0xa8/0x110 __do_munmap+0x1ea/0x4e0 __vm_munmap+0x75/0x120 __x64_sys_munmap+0x28/0x40 do_syscall_64+0x38/0x90 entry_SYSCALL_64_after_hwframe+0x61/0xcb ... For each munmap() call, the Xen hypervisor (if built with CONFIG_DEBUG) would print out the following and trigger a general protection fault in the affected Xen PV domain: (XEN) d0v... Attempt to implicitly unmap d0's grant PTE ... (XEN) d0v... Attempt to implicitly unmap d0's grant PTE ... As of this writing, gntdev_grant_map structure's vma field (referred to as map->vma below) is mainly used for checking the start and end addresses of mappings. However, with split VMAs, these may change, and there could be more than one VMA associated with a gntdev mapping. Hence, remove the use of map->vma and rely on map->pages_vm_start for the original start address and on (map->count << PAGE_SHIFT) for the original mapping size. Let the invalidate() and find_special_page() hooks use these. Also, given that there can be multiple VMAs associated with a gntdev mapping, move the "mmu_interval_notifier_remove(&map->notifier)" call to the end of gntdev_put_map, so that the MMU notifier is only removed after the closing of the last remaining VMA. Finally, use an atomic to prevent inadvertent gntdev mapping re-use, instead of using the map->live_grants atomic counter and/or the map->vma pointer (the latter of which is now removed). This prevents the userspace from mmap()'ing (with MAP_FIXED) a gntdev mapping over the same address range as a previously set up gntdev mapping. This scenario can be summarized with the following call-trace, which was valid prior to this commit: mmap gntdev_mmap mmap (repeat mmap with MAP_FIXED over the same address range) gntdev_invalidate unmap_grant_pages (sets 'being_removed' entries to true) gnttab_unmap_refs_async unmap_single_vma gntdev_mmap (maps the shared pages again) munmap gntdev_invalidate unmap_grant_pages (no-op because 'being_removed' entries are true) unmap_single_vma (For PV domains, Xen reports that a granted page is being unmapped and triggers a general protection fault in the affected domain, if Xen was built with CONFIG_DEBUG) The fix for this last scenario could be worth its own commit, but we opted for a single commit, because removing the gntdev_grant_map structure's vma field requires guarding the entry to gntdev_mmap(), and the live_grants atomic counter is not sufficient on its own to prevent the mmap() over a pre-existing mapping. The Linux kernel CVE team has assigned CVE-2022-50471 to this issue. Affected and fixed versions =========================== Issue introduced in 2.6.38 with commit ab31523c2fcac557226bac72cbdf5fafe01f9a26 and fixed in 5.10.152 with commit 3c6a888e352283a14f37b9b433cd598a1a3a7dd0 Issue introduced in 2.6.38 with commit ab31523c2fcac557226bac72cbdf5fafe01f9a26 and fixed in 5.15.75 with commit 7c16d0a4e6a436b4e7c92bead3fab55aaa4c1141 Issue introduced in 2.6.38 with commit ab31523c2fcac557226bac72cbdf5fafe01f9a26 and fixed in 5.19.17 with commit 4fb4053d90caa9985b87ec0e0c32c66a55bdfa3a Issue introduced in 2.6.38 with commit ab31523c2fcac557226bac72cbdf5fafe01f9a26 and fixed in 6.0.3 with commit cdafa219ace013c594e2491158ad1b51f9923dde Issue introduced in 2.6.38 with commit ab31523c2fcac557226bac72cbdf5fafe01f9a26 and fixed in 6.1 with commit 5c13a4a0291b30191eff9ead8d010e1ca43a4d0c 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-50471 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: drivers/xen/gntdev-common.h drivers/xen/gntdev.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/3c6a888e352283a14f37b9b433cd598a1a3a7dd0 https://git.kernel.org/stable/c/7c16d0a4e6a436b4e7c92bead3fab55aaa4c1141 https://git.kernel.org/stable/c/4fb4053d90caa9985b87ec0e0c32c66a55bdfa3a https://git.kernel.org/stable/c/cdafa219ace013c594e2491158ad1b51f9923dde https://git.kernel.org/stable/c/5c13a4a0291b30191eff9ead8d010e1ca43a4d0c