x86: Add ENDBR at function entries
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 18 Feb 2020 22:05:39 +0000 (14:05 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 26 Mar 2020 23:38:46 +0000 (16:38 -0700)
Intel Control-flow Enforcement Technology (CET):

https://software.intel.com/en-us/articles/intel-sdm

contains shadow stack (SHSTK) and indirect branch tracking (IBT).
When IBT is enabled, all indirect branch targets must start with
ENDBR instruction which is a NOP on non-CET processors.

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2538
Acked-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Ben Widawsky <ben.widawsky@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3865>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3865>

src/mapi/entry_x86-64_tls.h
src/mapi/entry_x86_tls.h
src/mapi/entry_x86_tsd.h

index 1e29bde516c356c3eb8480ee26691a5a1e679044..aebe4cf4a3f29cebdd81a631de6ba649a079ed4f 100644 (file)
  *    Chia-I Wu <olv@lunarg.com>
  */
 
+#ifdef __CET__
+#define ENDBR "endbr64\n\t"
+#else
+#define ENDBR
+#endif
+
 #ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
 #define HIDDEN __attribute__((visibility("hidden")))
 #else
@@ -44,6 +50,7 @@ __asm__(".text\n"
 #ifndef __ILP32__
 
 #define STUB_ASM_CODE(slot)                              \
+   ENDBR                                                 \
    "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
    "movq %fs:(%rax), %r11\n\t"                           \
    "jmp *(8 * " slot ")(%r11)"
@@ -51,6 +58,7 @@ __asm__(".text\n"
 #else
 
 #define STUB_ASM_CODE(slot)                              \
+   ENDBR                                                 \
    "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
    "movl %fs:(%rax), %r11d\n\t"                          \
    "movl 4*" slot "(%r11d), %r11d\n\t"                   \
index 58a27cef18ed539d41e2790af45531c93aafa2d9..bdaa97374ba6bc4a8715f60f499a2910d19256ff 100644 (file)
 
 #include <string.h>
 
+#ifdef __CET__
+#define ENDBR "endbr32\n\t"
+#else
+#define ENDBR
+#endif
+
 #ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
 #define HIDDEN __attribute__((visibility("hidden")))
 #else
@@ -59,6 +65,7 @@ __asm__(".balign 16\n"
    func ":"
 
 #define STUB_ASM_CODE(slot)                                 \
+   ENDBR                                                    \
    "call 1f\n"                                              \
    "1:\n\t"                                                 \
    "popl %eax\n\t"                                          \
index 9526cdcef1a83ef3440f1cfcd7adab6e530b3dd5..1cf3ea2964eaa23f8b9e7d4f787686ff1716f70c 100644 (file)
  *    Chia-I Wu <olv@lunarg.com>
  */
 
+#ifdef __CET__
+#define ENDBR "endbr32\n\t"
+#else
+#define ENDBR
+#endif
+
 #ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
 #define HIDDEN __attribute__((visibility("hidden")))
 #else
@@ -44,6 +50,7 @@ __asm__(".text\n"
    func ":"
 
 #define STUB_ASM_CODE(slot)         \
+   ENDBR                            \
    "call 1f\n\t"                    \
    "1:\n\t"                         \
    "popl %ecx\n\t"                  \