Retbleed — a new attack on the speculative execution mechanism of Intel and AMD CPUs.

A group of researchers from the Swiss Federal Institute of Technology Zurich has identified a new variant of attack on the speculative execution mechanism of indirect branches in CPUs, allowing the extraction of information from kernel memory or organizing attacks on the host system from virtual machines. The vulnerabilities have been codenamed Retbleed (CVE-2022-29900, CVE-2022-29901) and are conceptually similar to Spectre-v2 attacks. The difference lies in organizing speculative execution of arbitrary code when processing the 'ret' (return) instruction, which retrieves the address for branching from the stack, instead of an indirect branch using the 'jmp' instruction that loads the address from memory or the CPU register.

An attacker can create conditions for incorrect branch prediction and orchestrate a targeted speculative jump to a block of code not intended by the program's execution logic. Ultimately, the processor will determine that the branch prediction was incorrect and roll back the operation to its initial state, but the data processed during speculative execution will reside in the cache and microarchitectural buffers. If the incorrectly executed block accesses memory, its speculative execution will result in data being cached from memory.

To identify data left in the cache after speculative execution of operations, an attacker can use methods to determine residual data through side channels, for example, by analyzing access time changes to cached and non-cached data. For targeted information extraction from areas with different privilege levels (such as kernel memory), 'gadgets' are used—specific sequences of commands present in the kernel that are suitable for speculatively reading data from memory based on external conditions that can be influenced by the attacker.

To defend against classic Spectre-class attacks that use conditional and indirect jump instructions, most operating systems employ a technique called 'retpoline.' This technique replaces indirect jump operations with the 'ret' instruction, for which a separate stack state prediction block is used in processors, avoiding the jump prediction block. When retpoline was introduced in 2018, it was believed that address manipulation similar to Spectre was not practically applicable for speculative jumps using the 'ret' instruction.

Researchers who developed the Retbleed attack method demonstrated the ability to create microarchitectural conditions for initiating speculative jumps using the 'ret' instruction. They published a toolkit for detecting exploitable instruction sequence (gadget) vulnerabilities in the Linux kernel where such conditions occur.

During the research, a working exploit was prepared, allowing systems with Intel CPUs to extract arbitrary data from kernel memory at a rate of 219 bytes per second and with 98% accuracy from an unprivileged user space process. On AMD processors, the exploit is significantly more effective, achieving a leak rate of 3.9 KB per second. As a practical example, the exploit was used to determine the contents of the file /etc/shadow. On systems with Intel CPUs, the attack to determine the root user password hash took 28 minutes, while on systems with AMD CPUs, it took 6 minutes.

Play video

The possibility of conducting the attack has been confirmed for Intel processors of the 6th to 8th generations produced before the third quarter of 2019 (including Skylake) and AMD processors based on Zen 1, Zen 1+, and Zen 2 microarchitectures produced before the second quarter of 2021. In newer processor models, such as AMD Zen3 and Intel Alder Lake, as well as ARM processors, the issue is mitigated by existing protection mechanisms. For instance, the use of IBRS (Indirect Branch Restricted Speculation) instructions helps defend against the attack.

A set of changes has been prepared for the Linux kernel and the Xen hypervisor, targeting old CPUs to block the issue programmatically. The proposed patch for the Linux kernel modifies 68 files, adds 1,783 lines, and removes 387 lines. Unfortunately, the protection incurs significant overhead—performance tests on AMD and Intel processors show a decrease ranging from 14% to 39%. A more preferable option is to utilize protection based on IBRS instructions, available in new generations of Intel CPUs and supported from Linux kernel 4.19 onward.

On Intel processors, the address for speculative indirect jumps is substituted due to a feature that manifests during underflow in the Return Stack Buffer. Under such conditions, the logic for selecting the address for the 'ret' instruction applies, similar to that used for regular indirect jumps. More than a thousand instances have been found in the Linux kernel that can initiate such reverse underflows and are accessible via system calls.

On AMD processors, the speculative execution of the 'ret' instruction occurs without being tied to a stack-specific buffer (Return Address Stack), and the jump predictor treats the 'ret' instruction not as a return of control but as an indirect jump, thus utilizing data for indirect jumps in its predictions. Under these conditions, effectively any 'ret' operation reachable through a system call can be exploited.

Additionally, another issue (CVE-2022-23825, Branch Type Confusion) has been identified in AMD CPUs relating to the execution of fictitious jumps—conditions for jump prediction can arise even without the necessary branching instructions, allowing influence on the jump prediction buffer without a 'ret' instruction. This attribute significantly complicates the implementation of protections and requires more active clearing of the jump prediction buffer. It is anticipated that the addition of comprehensive protection in the kernel will lead to a 209% increase in overhead.

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers šŸ”„ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster