]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/StuffRsb.inc
UefiCpuPkg/SmmCpuFeaturesLib: [CVE-2017-5715] Stuff RSB before RSM
[mirror_edk2.git] / UefiCpuPkg / Library / SmmCpuFeaturesLib / Ia32 / StuffRsb.inc
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/StuffRsb.inc b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/StuffRsb.inc
new file mode 100644 (file)
index 0000000..14267c3
--- /dev/null
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+; Abstract:\r
+;\r
+;   This file provides macro definitions for stuffing the Return Stack Buffer (RSB).\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+%define RSB_STUFF_ENTRIES 0x20\r
+\r
+;\r
+; parameters:\r
+; @param 1: register to use as counter (e.g. IA32:eax, X64:rax)\r
+; @param 2: stack pointer to restore   (IA32:esp, X64:rsp)\r
+; @param 3: the size of a stack frame  (IA32:4, X64:8)\r
+;\r
+%macro StuffRsb 3\r
+      mov     %1, RSB_STUFF_ENTRIES / 2\r
+  %%Unroll1:\r
+      call    %%Unroll2\r
+  %%SpecTrap1:\r
+      pause\r
+      lfence\r
+      jmp     %%SpecTrap1\r
+  %%Unroll2:\r
+      call    %%StuffLoop\r
+  %%SpecTrap2:\r
+      pause\r
+      lfence\r
+      jmp     %%SpecTrap2\r
+  %%StuffLoop:\r
+      dec     %1\r
+      jnz     %%Unroll1\r
+      add     %2, RSB_STUFF_ENTRIES * %3 ; Restore the stack pointer\r
+%endmacro\r
+\r
+;\r
+; RSB stuffing macros for IA32 and X64\r
+;\r
+%macro StuffRsb32 0\r
+      StuffRsb     eax, esp, 4\r
+%endmacro\r
+\r
+%macro StuffRsb64 0\r
+      StuffRsb     rax, rsp, 8\r
+%endmacro\r