x86: Add ENDBR at function entries

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>
This commit is contained in:
H.J. Lu 2020-02-18 14:05:39 -08:00
parent 9899a8e26c
commit e352e7e792
3 changed files with 22 additions and 0 deletions

View file

@ -25,6 +25,12 @@
* 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" \

View file

@ -27,6 +27,12 @@
#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" \

View file

@ -25,6 +25,12 @@
* 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" \