x86/cet: Sync with Linux kernel 6.6 shadow stack interface
commitedb5e0c8f915a798629717b5680a852c8bb3db25
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 29 Dec 2023 16:43:49 +0000 (29 08:43 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 1 Jan 2024 13:22:48 +0000 (1 05:22 -0800)
tree8b68e53c8d498b8b0ba3a37e02d8c995ec872210
parent6b32696116e0097f5dd578ec087bcbef483f2a07
x86/cet: Sync with Linux kernel 6.6 shadow stack interface

Sync with Linux kernel 6.6 shadow stack interface.  Since only x86-64 is
supported, i386 shadow stack codes are unchanged and CET shouldn't be
enabled for i386.

1. When the shadow stack base in TCB is unset, the default shadow stack
is in use.  Use the current shadow stack pointer as the marker for the
default shadow stack. It is used to identify if the current shadow stack
is the same as the target shadow stack when switching ucontexts.  If yes,
INCSSP will be used to unwind shadow stack.  Otherwise, shadow stack
restore token will be used.
2. Allocate shadow stack with the map_shadow_stack syscall.  Since there
is no function to explicitly release ucontext, there is no place to
release shadow stack allocated by map_shadow_stack in ucontext functions.
Such shadow stacks will be leaked.
3. Rename arch_prctl CET commands to ARCH_SHSTK_XXX.
4. Rewrite the CET control functions with the current kernel shadow stack
interface.

Since CET is no longer enabled by kernel, a separate patch will enable
shadow stack during startup.
15 files changed:
sysdeps/unix/sysv/linux/x86/bits/mman.h
sysdeps/unix/sysv/linux/x86/cpu-features.c
sysdeps/unix/sysv/linux/x86/dl-cet.h
sysdeps/unix/sysv/linux/x86/include/asm/prctl.h
sysdeps/unix/sysv/linux/x86/tst-cet-setcontext-1.c
sysdeps/unix/sysv/linux/x86_64/Makefile
sysdeps/unix/sysv/linux/x86_64/__start_context.S
sysdeps/unix/sysv/linux/x86_64/allocate-shadow-stack.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/x86_64/allocate-shadow-stack.h [copied from sysdeps/unix/sysv/linux/x86/dl-cet.h with 58% similarity]
sysdeps/unix/sysv/linux/x86_64/getcontext.S
sysdeps/unix/sysv/linux/x86_64/makecontext.c
sysdeps/unix/sysv/linux/x86_64/swapcontext.S
sysdeps/x86/cpu-features.c
sysdeps/x86/dl-cet.c
sysdeps/x86_64/nptl/tls.h