]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/StuffRsb.inc
UefiCpuPkg/SmmCpuFeaturesLib: [CVE-2017-5715] Stuff RSB before RSM
[mirror_edk2.git] / UefiCpuPkg / Library / SmmCpuFeaturesLib / X64 / StuffRsb.inc
CommitLineData
0df50560
HW
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
4; This program and the accompanying materials\r
5; are licensed and made available under the terms and conditions of the BSD License\r
6; which accompanies this distribution. The full text of the license may be found at\r
7; http://opensource.org/licenses/bsd-license.php.\r
8;\r
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11;\r
12; Abstract:\r
13;\r
14; This file provides macro definitions for stuffing the Return Stack Buffer (RSB).\r
15;\r
16;------------------------------------------------------------------------------\r
17\r
18%define RSB_STUFF_ENTRIES 0x20\r
19\r
20;\r
21; parameters:\r
22; @param 1: register to use as counter (e.g. IA32:eax, X64:rax)\r
23; @param 2: stack pointer to restore (IA32:esp, X64:rsp)\r
24; @param 3: the size of a stack frame (IA32:4, X64:8)\r
25;\r
26%macro StuffRsb 3\r
27 mov %1, RSB_STUFF_ENTRIES / 2\r
28 %%Unroll1:\r
29 call %%Unroll2\r
30 %%SpecTrap1:\r
31 pause\r
32 lfence\r
33 jmp %%SpecTrap1\r
34 %%Unroll2:\r
35 call %%StuffLoop\r
36 %%SpecTrap2:\r
37 pause\r
38 lfence\r
39 jmp %%SpecTrap2\r
40 %%StuffLoop:\r
41 dec %1\r
42 jnz %%Unroll1\r
43 add %2, RSB_STUFF_ENTRIES * %3 ; Restore the stack pointer\r
44%endmacro\r
45\r
46;\r
47; RSB stuffing macros for IA32 and X64\r
48;\r
49%macro StuffRsb32 0\r
50 StuffRsb eax, esp, 4\r
51%endmacro\r
52\r
53%macro StuffRsb64 0\r
54 StuffRsb rax, rsp, 8\r
55%endmacro\r