[php-src] PR #14027: Fix Intel CET / SHSTK support in fibers
| From: | arnaud-lb | Date: | Sun, 21 Apr 2024 12:37:06 +0000 |
| Subject: | [php-src] PR #14027: Fix Intel CET / SHSTK support in fibers | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-25866@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/14027
Author: arnaud-lb
This fixes SHSTK support in fibers:
* The syscall number for map_shadow_stack has changed since initial support was added. I update the
syscall number and use the SYS_map_shadow_stack macro instead of the hard coded number when
possible. Note: when the configure check is broken, SHSTK is _not_ disabled. Instead, SHSTK handling
is not added, causing fibers to crash. So this configure check is not a security risk.
* make_fcontext/jump_fcontext was broken due to accidental duplication of shadow stack handling
* Set the the shadow stack size to the same size as the normal stack, as in the worse case the
shadow stack needs as much space. This matches [what the kernel
does](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kernel/shstk.c?id=977b1ef51866aa7170409af80740788d4f9c4841#n132)
for the main stack.
* Enable SHSTK in CI. For now this should only check that we can build with -fcf-protection, and
that the linker adds the SHSTK flag on the binary (cet-report=error). The glibc version used in CI
will not enable SHSTK, but I believe it will in Ubuntu 24.
See https://docs.kernel.org/next/x86/shstk.html
This can be tested with a kernel >= 6.6 and glibc >= 2.39, when compiling with
CFLAGS=-fcf-protection=full LDFLAGS=-Wl,-z,cet-report=error, and running with
GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK.