7.1high
kvm: avoid speculation-based attacks from out-of-range memslot accesses
- Severity
- 7.1high CVSS:3.1 by NVD
- Exploit likelihood
- 0.26% (higher than 18% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- Linux
Description
In the Linux kernel, the following vulnerability has been resolved: kvm: avoid speculation-based attacks from out-of-range memslot accesses KVM's mechanism for accessing guest memory translates a guest physical address (gpa) to a host virtual address using the right-shifted gpa (also known as gfn) and a struct kvm_memory_slot. The translation is performed in __gfn_to_hva_memslot using the following formula: hva = slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE It is expected that gfn falls within the boundaries of the guest's physical memory. However, a guest can access invalid physical addresses in such a way that the gfn is invalid. __gfn_to_hva_memslot is called from kvm_vcpu_gfn_to_hva_prot, which first retrieves a memslot through __gfn_to_memslot. While __gfn_to_memslot does check that the gfn falls within the boundaries of the guest's physical memory or not, a CPU can speculate the result of the check and continue execution speculatively using an illegal gfn. The speculation can result in calculating an out-of-bounds hva. If the resulting host virtual address is used to load another guest physical address, this is effectively a Spectre gadget consisting of two consecutive reads, the second of which is data dependent on the first. Right now it's not clear if there are any cases in which this is exploitable. One interesting case was reported by the original author of this patch, and involves visiting guest page tables on x86. Right now these are not vulnerable because the hva read goes through get_user(), which contains an LFENCE speculation barrier. However, there are patches in progress for x86 uaccess.h to mask kernel addresses instead of using LFENCE; once these land, a guest could use speculation to read from the VMM's ring 3 address space. Other architectures such as ARM already use the address masking method, and would be susceptible to this same kind of data-dependent access gadgets. Therefore, this patch proactively protects from these attacks by masking out-of-bounds gfns in __gfn_to_hva_memslot, which blocks speculation of invalid hvas. Sean Christopherson noted that this patch does not cover kvm_read_guest_offset_cached. This however is limited to a few bytes past the end of the cache, and therefore it is unlikely to be useful in the context of building a chain of data dependent accesses.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| Linux Linux | from 8a7ae055f3533b520401c170ac55e30628b34df5 before 3098b86390a6b9ea52657689f08410baf130ceff, from 8a7ae055f3533b520401c170ac55e30628b34df5 before 740621309b25bbf619b8a0ba5fd50a8e58989441, from 8a7ae055f3533b520401c170ac55e30628b34df5 before 361ce3b917aff93123e9e966d8608655c967f438, from 8a7ae055f3533b520401c170ac55e30628b34df5 before 22b87fb17a28d37331bb9c1110737627b17f6781, from 8a7ae055f3533b520401c170ac55e30628b34df5 before bff1fbf0cf0712686f1df59a83fba6e31d2746a0, from 8a7ae055f3533b520401c170ac55e30628b34df5 before 7af299b97734c7e7f465b42a2139ce4d77246975, from 8a7ae055f3533b520401c170ac55e30628b34df5 before ed0e2a893092c7fcb4ff7ba74e5efce53a6f5940, from 8a7ae055f3533b520401c170ac55e30628b34df5 before da27a83fd6cc7780fea190e1f5c19e87019da65c and 1 more Not affected: before 2.6.25, from 4.4.273 up to 4.4.*, from 4.9.273 up to 4.9.*, from 4.14.237 up to 4.14.*, from 4.19.195 up to 4.19.*, from 5.4.126 up to 5.4.* | CVE List |
| linux linux_kernel | before 4.4.273, from 4.5 before 4.9.273, from 4.10 before 4.14.237, from 4.15 before 4.19.195, from 4.20 before 5.4.126, from 5.5 before 5.10.44, from 5.11 before 5.12.11, 5.13 | NVD |
Classification
SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.
What each source says
CVE List
In the Linux kernel, the following vulnerability has been resolved: kvm: avoid speculation-based attacks from out-of-range memslot accesses KVM's mechanism for accessing guest memory translates a guest physical address (gpa) to a host virtual address using the right-shifted gpa (also known as gfn) and a struct kvm_memory_slot. The translation is performed in __gfn_to_hva_memslot using the following formula: hva = slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE It is expected that gfn falls within the boundaries of the guest's physical memory. However, a guest can access invalid physical addresses in such a way that the gfn is invalid. __gfn_to_hva_memslot is called from kvm_vcpu_gfn_to_hva_prot, which first retrieves a memslot through __gfn_to_memslot. While __gfn_to_memslot does check that the gfn falls within the boundaries of the guest's physical memory or not, a CPU can speculate the result of the check and continue execution speculatively using an illegal gfn. The speculation can result in calculating an out-of-bounds hva. If the resulting host virtual address is used to load another guest physical address, this is effectively a Spectre gadget consisting of two consecutive reads, the second of which is data dependent on the first. Right now it's not clear if there are any cases in which this is exploitable. One interesting case was reported by the original author of this patch, and involves visiting guest page tables on x86. Right now these are not vulnerable because the hva read goes through get_user(), which contains an LFENCE speculation barrier. However, there are patches in progress for x86 uaccess.h to mask kernel addresses instead of using LFENCE; once these land, a guest could use speculation to read from the VMM's ring 3 address space. Other architectures such as ARM already use the address masking method, and would be susceptible to this same kind of data-dependent access gadgets. Therefore, this patch proactively protects from these attacks by masking out-of-bounds gfns in __gfn_to_hva_memslot, which blocks speculation of invalid hvas. Sean Christopherson noted that this patch does not cover kvm_read_guest_offset_cached. This however is limited to a few bytes past the end of the cache, and therefore it is unlikely to be useful in the context of building a chain of data dependent accesses.
NVD (es)
En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: kvm: evite ataques basados en especulacion desde accesos a memslot fuera de rango. El mecanismo de KVM para acceder a la memoria del invitado traduce una dirección física del invitado (gpa) a una dirección virtual del host usando el botón derecho. gpa desplazado (también conocido como gfn) y una estructura kvm_memory_slot. La traducción se realiza en __gfn_to_hva_memslot usando la siguiente fórmula: hva = slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE Se espera que gfn esté dentro de los límites de la memoria física del huésped. Sin embargo, un invitado puede acceder a direcciones físicas no válidas de tal manera que el gfn no sea válido. __gfn_to_hva_memslot se llama desde kvm_vcpu_gfn_to_hva_prot, que primero recupera un memslot a través de __gfn_to_memslot. Si bien __gfn_to_memslot verifica que el gfn esté dentro de los límites de la memoria física del huésped o no, una CPU puede especular el resultado de la verificación y continuar la ejecución de manera especulativa usando un gfn ilegal. La especulación puede resultar en el cálculo de un hva fuera de los límites. Si la dirección virtual del host resultante se utiliza para cargar otra dirección física de invitado, se trata efectivamente de un dispositivo Spectre que consta de dos lecturas consecutivas, la segunda de las cuales depende de los datos de la primera. En este momento no está claro si hay casos en los que esto sea explotable. El autor original de este parche informó un caso interesante que implica visitar tablas de páginas de invitados en x86. En este momento, estos no son vulnerables porque la lectura de hva pasa por get_user(), que contiene una barrera de especulación LFENCE. Sin embargo, hay parches en progreso para x86 uaccess.h para enmascarar las direcciones del kernel en lugar de usar LFENCE; Una vez que aterrizan, un invitado podría usar la especulación para leer desde el espacio de direcciones del anillo 3 del VMM. Otras arquitecturas, como ARM, ya utilizan el método de enmascaramiento de direcciones y serían susceptibles a este mismo tipo de dispositivos de acceso dependientes de datos. Por lo tanto, este parche protege proactivamente contra estos ataques al enmascarar gfns fuera de los límites en __gfn_to_hva_memslot, lo que bloquea la especulación sobre hvas no válidos. Sean Christopherson señaló que este parche no cubre kvm_read_guest_offset_cached. Sin embargo, esto se limita a unos pocos bytes después del final de la caché y, por lo tanto, es poco probable que sea útil en el contexto de la construcción de una cadena de accesos dependientes de datos.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-47277 changed 2026-05-11 | CVE Terms of Use |
| NVD | CVE-2021-47277 changed 2026-06-17 | Public domain |