A group of researchers from the Free University of Amsterdam has identified a new attack method called 'Native BHI' (CVE-2024-2201), which allows the contents of the Linux kernel memory to be determined on systems with Intel processors when an exploit is run in user space. In the case of virtualization systems, an attacker from the guest system can identify the contents of the memory of the host environment or other guest systems.
The Native BHI method offers a different technique for exploiting the BHI (Branch History Injection, CVE-2022-0001) vulnerability, bypassing previously implemented protections. The attack method introduced in 2022 exploited the vulnerability within the same privilege level, using an exploit based on the execution of an eBPF program loaded by the user into the kernel. To block the vulnerability, it was enough to restrict access to execute eBPF code for regular users.
The new Native BHI method does not require access to eBPF and allows an unprivileged user to carry out an attack from user space. The method relies on utilizing existing gadgets in the kernel code—sequences of commands that lead to speculative execution of instructions. To find suitable gadgets in the kernel, a specialized tool called InSpectre Gadget was developed, which, when analyzing kernel 6.6-rc4, identified 1511 Spectre gadgets and 2105 auxiliary dispatch gadgets.

Based on the identified gadgets, the researchers prepared an exploit that enables extraction of the password hash string for the root user from the kernel buffers, loaded from the file /etc/shadow. The speed of data extraction from kernel memory is approximately 3.5 KB per second.

The BHI method is an extended variant of the Spectre-v2 attack, where to bypass the added protections (Intel eIBRS and Arm CSV2) and facilitate data leakage, values are substituted into the Branch History Buffer, used in CPUs to improve the accuracy of branch prediction by considering the history of past transitions. During the attack, manipulations with the transition history create conditions for incorrect branch prediction and speculative execution of necessary instructions, the results of which settle in the cache.
The differences from the Spectre-v2 attack come down to using a Branch History Buffer instead of a Branch Target Buffer. To extract data from memory, the attacker must create conditions under which, during speculative operations, the address will be taken from the area that needs to be determined. After performing a speculative indirect branch, the address read from memory remains in the cache, after which one of the methods for determining the cache content can be applied based on analyzing changes in access time to cached and uncached data.
The Native BHI attack is not mitigated by using Intel IBT (Indirect Branch Tracking) instructions and the hybrid mechanism implemented in the Linux kernel, FineIBT, which combines the use of hardware IBT instructions with software kCFI (kernel Control Flow Integrity) protection to block violations of the normal execution order (control flow). FineIBT allows execution through an indirect branch only if it branches to an instruction ENDBR, which is placed at the very beginning of the function. Additionally, a hash check is performed to guarantee the immutability of the pointers.
To protect against the new variant of the attack, an update has been added to the Linux kernel implementing an additional protection mode that utilizes the hardware protections proposed by Intel (BHI_DIS_S) or an alternative software protection implemented for hypervisor protection. KVMXen hypervisor developers have also released a patch based on using the BHI_DIS_S mode, which restricts predictions based on branch history. Support for BHI_DIS_S is available in processors starting from Intel Alder Lake, as well as in server CPUs starting from Intel Sapphire Rapids. A software protection mode is also available, based on using sequences to clear the history buffer, but it results in a more noticeable reduction in performance.
Source: opennet.ru
