CVE-2021-47277
kvm: avoid speculation-based attacks from out-of-range memslot accesses
Check your servers for CVE-2021-47277
The Vulnpocalypse collector sends the package list of each Linux server and of its container images once a day. Vulnpocalypse shows every server where CVE-2021-47277 affects the running kernel, with the command that installs the fix. The free plan covers one server and one domain and does not need a credit card.
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.
Exploitation
EPSS 0.26%: the probability of exploitation activity in the next 30 days, from the EPSS model of FIRST. The score is higher than 18.8% of all scored CVEs. Scores of 1 Dec 2026.
The assessment of CISA (SSVC, 23 May 2024):
- Exploitation
- none: CISA did not find evidence of exploitation or a public proof of concept
- Automatable
- no: each attack takes manual steps
- Technical impact
- partial: limited control or limited data
Affected products
As the CNA lists them.
| Product | Versions |
|---|---|
| Linux |
affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before 3098b86390a6b9ea52657689f08410baf130ceff affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before 740621309b25bbf619b8a0ba5fd50a8e58989441 affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before 361ce3b917aff93123e9e966d8608655c967f438 affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before 22b87fb17a28d37331bb9c1110737627b17f6781 affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before bff1fbf0cf0712686f1df59a83fba6e31d2746a0 affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before 7af299b97734c7e7f465b42a2139ce4d77246975 affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before ed0e2a893092c7fcb4ff7ba74e5efce53a6f5940 affected from 8a7ae055f3533b520401c170ac55e30628b34df5, before da27a83fd6cc7780fea190e1f5c19e87019da65c
Other versions: unaffected
|
| Linux |
affected 2.6.25 unaffected before 2.6.25 unaffected from 4.4.273 up to and including 4.4.* unaffected from 4.9.273 up to and including 4.9.* unaffected from 4.14.237 up to and including 4.14.* unaffected from 4.19.195 up to and including 4.19.* unaffected from 5.4.126 up to and including 5.4.* unaffected from 5.10.44 up to and including 5.10.* unaffected from 5.12.11 up to and including 5.12.* unaffected 5.13 and later
Other versions: affected
|
Is my server affected?
This CVE is in the Linux kernel. Compare the running kernel with the fixed kernel version of your distribution, and reboot after a kernel update:
uname -r
# Debian, Ubuntu: does the changelog of the running kernel name the CVE?
zgrep -l CVE-2021-47277 /usr/share/doc/linux-image-$(uname -r)/changelog.Debian.gz
# RHEL, Rocky, Alma
rpm -q --changelog kernel | grep CVE-2021-47277
With Trivy, on the host and for a container image. When a package is affected, it prints the installed and the fixed version:
trivy rootfs --scanners vuln / | grep CVE-2021-47277
trivy image --scanners vuln IMAGE | grep CVE-2021-47277
Vulnpocalypse makes this comparison every day for the package lists of your servers and container images, including language packages (npm, PyPI, Go, Maven and others), and sends the command that installs the fix. Start free with one server and one domain or read how to install the collector.
References
Other references
- https://git.kernel.org/stable/c/3098b86390a6b9ea52657689f08410baf130ceff git.kernel.org
- https://git.kernel.org/stable/c/740621309b25bbf619b8a0ba5fd50a8e58989441 git.kernel.org
- https://git.kernel.org/stable/c/361ce3b917aff93123e9e966d8608655c967f438 git.kernel.org
- https://git.kernel.org/stable/c/22b87fb17a28d37331bb9c1110737627b17f6781 git.kernel.org
- https://git.kernel.org/stable/c/bff1fbf0cf0712686f1df59a83fba6e31d2746a0 git.kernel.org
- https://git.kernel.org/stable/c/7af299b97734c7e7f465b42a2139ce4d77246975 git.kernel.org
- https://git.kernel.org/stable/c/ed0e2a893092c7fcb4ff7ba74e5efce53a6f5940 git.kernel.org
- https://git.kernel.org/stable/c/da27a83fd6cc7780fea190e1f5c19e87019da65c git.kernel.org
Source: the record CVE-2021-47277 of the CVE List (CVE Program), CVE Terms of Use; the CISA KEV catalog and the CISA ADP container; EPSS of FIRST. The text of the record is shown as published. Data sources and licences.
Vulnpocalypse