Inferring Fine-grained Control Flow Inside SGX Enclaves with Branch Shadowing - Lee, Sangho; Shih, Ming-Wei; Gera, Prasun; Kim, Taesoo; Kim, Hyesoon; Peinado, Marcus (26th USENIX Security Symposium (USENIX Security 17), 2017)
Intel has introduced a hardware-based trusted execution environment, Intel Software Guard Extensions (SGX), that provides a secure, isolated execution environment, or enclave, for a user program without trusting any underlying software (e.g., an operating system) or firmware. Researchers have demonstrated that SGX is vulnerable to a page-fault-based attack. However, the attack only reveals page-level memory accesses within an enclave. In this paper, we explore a new, yet critical, side channel attack, branch shadowing, that reveals fine grained control flows (branch granularity) in an enclave. The root cause of this attack is that SGX does not clear branch history when switching from enclave to non-enclave mode, leaving fine-grained traces for the outside world to observe, which gives rise to a branch-prediction side channel. However, exploiting this channel in practice is challenging because 1) measuring branch execution time is too noisy for distinguishing fine-grained control flow changes and 2) pausing an enclave right after it has executed the code block we target requires a sophisticated control. To overcome these challenges, we develop two novel exploitation techniques: 1) a last branch record (LBR)-based history-inferring technique and 2) an advanced programmable interrupt controller (APIC)-based technique to control the execution of an enclave in a fine grained manner. An evaluation against RSA shows that our attack infers each private key bit with 99.8% accuracy. Finally, we thoroughly study the feasibility of hardware based solutions (i.e., branch history flushing) and propose a software-based approach that mitigates the attack.