x86: Add indirect branch tracking support (#540)
authorhjl-tools <hjl.tools@gmail.com>
Sat, 22 Feb 2020 03:08:06 +0000 (19:08 -0800)
committerGitHub <noreply@github.com>
Sat, 22 Feb 2020 03:08:06 +0000 (22:08 -0500)
commit7855656148b96c7070ec362d2a73af840025a2b7
tree8a22c616b7e88ea007d8c454f94f7a70f2aa1565
parent4d6d2866ae43e55325e8ee96561221804602cd7a
x86: Add indirect branch tracking support (#540)

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
CET is enabled, ELF object files must be marked with .note.gnu.property
section.  When Intel CET is enabled, include <cet.h> in assembly codes
to mark Intel CET support.

Also when IBT is enabled, all indirect branch targets must start with
ENDBR instruction and notrack prefix can be used to disable IBT on
indirect branch.  <cet.h> defines _CET_ENDBR which can be used in
assembly codes for ENDBR instruction.  If <cet.h> isn't included,
define _CET_ENDBR as empty so that _CET_ENDBR can be used in assembly
codes.

Trampoline must be enlarged to add ENDBR instruction unconditionally,
which is NOP on non-CET processors.  This is required regardless if
libffi is enabled with CET since libffi.so will be marked in legacy
bitmap, but trampoline won't.  Update library version for larger
FFI_TRAMPOLINE_SIZE.

This fixed:

https://github.com/libffi/libffi/issues/474

Tested with

$ CC="gcc -Wl,-z,cet-report=error -fcf-protection" CXX="g++ -Wl,-z,cet-report=error -fcf-protection" .../configure

on Linux CET machines in i686, x32 and x86-64 modes.
Makefile.am
libtool-version
src/x86/ffi.c
src/x86/ffi64.c
src/x86/ffitarget.h
src/x86/ffiw64.c
src/x86/sysv.S
src/x86/unix64.S
src/x86/win64.S