Researchers from the Google Project Zero team have identified a vulnerability (CVE-2021-29657) in the KVM hypervisor included in the Linux kernel, which allows for bypassing the isolation of the guest system and executing code on the host environment. The issue is present in the code used on systems with AMD processors (kvm-amd.ko module) and does not appear for Intel processors.
The researchers have prepared a working exploit prototype that allows launching a root shell from the guest environment in the host environment on a system with an AMD Epyc 7351P processor and Linux kernel 5.10. This is noted as the first guest-to-host breach within the hypervisor itself, KVM, unrelated to errors in user space components like QEMU. The fix was merged into the kernel at the end of March. The problem manifests starting with Linux kernel 5.10-rc1 and ending with v5.12-rc6, thus affecting only kernels 5.10 and 5.11 (most stable branches of distributions are not affected by this issue).
The problem exists in the nested_svm_vmrun mechanism, implemented using the AMD SVM (Secure Virtual Machine) extension, which allows for nested execution of guest systems. For this functionality to be implemented correctly, the hypervisor must intercept all SVM instructions executed in the guest systems, emulate their behavior, and synchronize the state with the hardware, which is a quite complex task. Upon analyzing the KVM implementation, researchers found a logical error that allows affecting the contents of the host's MSR (Model-Specific Register) registers from the guest system, which can be exploited to execute code at the host level.
In particular, executing the VMRUN operation from a second-level nested guest system (L2, launched from another guest system) leads to a second call of nested_svm_vmrun and corrupts the structure svm->nested.hsave, onto which data from the L2 guest vmcb is imposed. As a result, it creates a situation where memory in the structure svm->nested.msrpm, which holds the MSR bit, can be freed at the L2 guest level, despite it still being in use, thereby gaining access to the MSR of the host environment.
Source: opennet.ru
