CVE-2021-46978·Kernel vulnerability
In the Linux kernel, the following vulnerability has been resolved: KVM: nVMX: Always make an attempt to map eVMCS after migration When enlightened VMCS is in use and nested state is migrated with vmx_get_nested_state()/vmx_set_nested_state() KVM can't map evmcs page right away: evmcs gpa is not 'struct kvm_vmx_nested_state_hdr' and we can't read it from VP assist page because userspace may decide to restore HV_X64_MSR_VP_ASSIST_PAGE after restoring nested state (and QEMU, for example, does exactly that). To make sure eVMCS is mapped /vmx_set_nested_state() raises KVM_REQ_GET_NESTED_STATE_PAGES request. Commit f2c7ef3ba955 ("KVM: nSVM: cancel KVM_REQ_GET_NESTED_STATE_PAGES on nested vmexit") added KVM_REQ_GET_NESTED_STATE_PAGES clearing to nested_vmx_vmexit() to make sure MSR permission bitmap is not switched when an immediate exit from L2 to L1 happens right after migration (caused by a pending event, for example). Unfortunately, in the exact same situation we still need to have eVMCS mapped so nested_sync_vmcs12_to_shadow() reflects changes in VMCS12 to eVMCS. As a band-aid, restore nested_get_evmcs_page() when clearing KVM_REQ_GET_NESTED_STATE_PAGES in nested_vmx_vmexit(). The 'fix' is far from being ideal as we can't easily propagate possible failures and even if we could, this is most likely already too late to do so. The whole 'KVM_REQ_GET_NESTED_STATE_PAGES' idea for mapping eVMCS after migration seems to be fragile as we diverge too much from the 'native' path when vmptr loading happens on vmx_set_nested_state().
- Severity
- high
- Software
- Kernel
- Fixed in
- 5.12.5
- Published
- 2024-02-28
Affected versions
From: 5.12
Until: 5.12.5
Fixed in: 5.12.5
How to fix this CVE
Update your Linux kernel to version 5.12.5 or later to resolve a critical nested virtualization issue affecting enlightened VMCS (eVMCS) mapping during VM migration. This vulnerability can cause incorrect VMCS12 state synchronization in nested hypervisor environments, leading to privilege escalation or data corruption. Apply the kernel update immediately on systems running KVM with nested virtualization enabled.
sudo dnf update kernelDefensia detects this vulnerability
How to check if you are affected
- Step 1: Check your current kernel version with `uname -r` and compare against 5.12.5 — if below 5.12.5 and kernel version is between 5.12.0-5.12.4, the system is vulnerable.
- Step 2: Verify if KVM nested virtualization is enabled by running `cat /sys/module/kvm_intel/parameters/nested` or `cat /sys/module/kvm_amd/parameters/nesting` — if either returns 'Y', the vulnerability is exploitable.
- Step 3: Check for active nested VM migrations in /var/log/libvirt/qemu/*.log or journalctl for errors related to 'vmx_set_nested_state', 'eVMCS', or 'KVM_REQ_GET_NESTED_STATE_PAGES' which may indicate exploitation attempts.
- Step 4: After patching, run `uname -r` again to confirm kernel version is 5.12.5 or later, then reboot if necessary and re-verify nested VM functionality with a test migration.
FAQ
What is CVE-2021-46978?
CVE-2021-46978 is a kernel vulnerability affecting nested KVM virtualization where enlightened VMCS (eVMCS) fails to map correctly after VM migration, potentially allowing VMCS state desynchronization between nested guests and the hypervisor.
Is CVE-2021-46978 being actively exploited?
No, CVE-2021-46978 is not listed in CISA's known exploited vulnerabilities catalog and no public exploits are available. However, it poses a significant risk in production hypervisor environments due to its high CVSS score of 7.8.
What versions of Kernel are affected by CVE-2021-46978?
Kernel versions 5.12.0 through 5.12.4 are vulnerable. The fix is included in kernel 5.12.5 and all subsequent releases.
How do I check if my server is vulnerable to CVE-2021-46978?
Run `uname -r` to check your kernel version — if it shows 5.12.0 to 5.12.4, you are vulnerable. Additionally, confirm nested KVM is enabled with `cat /sys/module/kvm_intel/parameters/nested` returning 'Y'.
Does Defensia detect CVE-2021-46978?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If the Linux kernel is installed on a monitored server, CVE-2021-46978 will appear in your dashboard with remediation steps.
Related Kernel CVEs
References
- https://git.kernel.org/stable/c/200a45649ab7361bc80c70aebf7165b64f9a6c9f
- https://git.kernel.org/stable/c/bd0e8455b85b651a4c77de9616e307129b15aaa7
- https://git.kernel.org/stable/c/c8bf64e3fb77cc19bad146fbe26651985b117194
- https://git.kernel.org/stable/c/f5c7e8425f18fdb9bdb7d13340651d7876890329
- https://git.kernel.org/stable/c/200a45649ab7361bc80c70aebf7165b64f9a6c9f
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2021-46978. Free for 1 server.
Get started free