glibc/sysdeps
H.J. Lu 5d844e1b72 i386: Enable CET support in ucontext functions
1. getcontext and swapcontext are updated to save the caller's shadow
stack pointer and return address.
2. setcontext and swapcontext are updated to restore shadow stack and
jump to new context directly.
3. makecontext is updated to allocate a new shadow stack and set the
caller's return address to the helper code, L(exitcode).
4. Since we no longer save and restore EAX, ECX and EDX in getcontext,
setcontext and swapcontext, we can use them as scratch register slots
to enable CET in ucontext functions.

Since makecontext allocates a new shadow stack when making a new
context and kernel allocates a new shadow stack for clone/fork/vfork
syscalls, we track the current shadow stack base.  In setcontext and
swapcontext, if the target shadow stack base is the same as the current
shadow stack base, we unwind the shadow stack.  Otherwise it is a stack
switch and we look for a restore token.

We enable shadow stack at run-time only if program and all used shared
objects, including dlopened ones, are shadow stack enabled, which means
that they must be compiled with GCC 8 or above and glibc 2.28 or above.
We need to save and restore shadow stack only if shadow stack is enabled.
When caller of getcontext, setcontext, swapcontext and makecontext is
compiled with smaller ucontext_t, shadow stack won't be enabled at
run-time.  We check if shadow stack is enabled before accessing the
extended field in ucontext_t.

Tested on i386 CET/non-CET machines.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-02-14 15:15:25 -08:00
..
aarch64 nptl: add missing pthread-offsets.h 2020-02-10 17:01:21 +01:00
alpha nptl: add missing pthread-offsets.h 2020-02-10 17:01:21 +01:00
arm Add libm_alias_finite for _finite symbols 2020-01-03 10:02:04 -03:00
csky Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
generic powerpc: Move cache line size to rtld_global_ro 2020-01-17 09:05:03 -03:00
gnu Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
hppa Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
htl htl C11 threads: Avoid pthread_ symbols visibility in static library 2020-02-10 23:45:23 +00:00
hurd C11 threads: Move implementation to sysdeps/pthread 2020-02-09 13:56:48 +01:00
i386 i386: Use ENTRY/END in assembly codes 2020-02-01 05:44:55 -08:00
ia64 nptl: add missing pthread-offsets.h 2020-02-10 17:01:21 +01:00
ieee754 ldbl-128ibm-compat: Provide a scalb implementation 2020-02-14 08:24:56 -06:00
init_array Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
m68k Add a generic scalb implementation 2020-02-14 08:24:56 -06:00
mach io: Implement lchmod using fchmodat [BZ #14578] 2020-02-12 08:43:59 +01:00
microblaze Linux: Use system call tables during build 2020-01-02 10:18:23 +01:00
mips MIPS: Fix circular definition of __LDBL_MANT_DIG__ in ieee754.h 2020-01-08 14:28:23 -05:00
nios2 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
nptl nptl: update default pthread-offsets.h 2020-02-10 17:01:21 +01:00
posix nss: Add function types and NSS_DECLARE_MODULE_FUNCTIONS macro to <nss.h> 2020-02-13 09:14:40 +01:00
powerpc Fix array overflow in backtrace on PowerPC (bug 25423) 2020-01-21 15:26:57 +01:00
pthread pthread: Move some join tests from nptl to sysdeps/pthread 2020-02-10 01:21:46 +00:00
riscv nptl: add missing pthread-offsets.h 2020-02-10 17:01:21 +01:00
s390 S390: Fix non-ascii character in fenv.h. 2020-02-12 09:10:56 +01:00
sh Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
sparc nptl: add missing pthread-offsets.h 2020-02-10 17:01:21 +01:00
unix i386: Enable CET support in ucontext functions 2020-02-14 15:15:25 -08:00
wordsize-32 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
wordsize-64 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
x86 x86: Remove <bits/select.h> and use the generic version 2020-02-09 14:02:27 +01:00
x86_64 Add libm_alias_finite for _finite symbols 2020-01-03 10:02:04 -03:00