[PATCH] CET: Correctly run dlopen tests with SHSTK enabled in hwcaps
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Nov 13 11:49:37 GMT 2026
On 11/11/26 09:14, Arjun Shankar wrote:
> The tst-cet-legacy-4* tests exercise dlopen with CET. However, since
> 55d63e731253de82e96ed4ddca2e294076cd0bc5, CET is not set active unless
> enabled in hwcaps. These tests were silently running and passing in
> non-SHSTK mode.
>
> 1. Enable SHSTK in hwcaps for these tests so that they are executed in
> the correct mode. Although tst-cet-legacy-4c runs in SHSTK 'off'
> mode, the hwcaps tunable is still set for consistency and will be
> overridden by the policy.
>
> 2. For tst-cet-legacy-4a and tst-cet-legacy-4b, assert that the test
> has SHSTK enabled before dlopen.
I am seeing these failures on a VM with CTE disabled, and I think it would
trigger on CPUs without CET, kernels without CONFIG_X86_USER_SHADOW_STACK:
FAIL: elf/tst-cet-legacy-4a
FAIL: elf/tst-cet-legacy-4b
Both passed before the patch. The sibling tests (tst-shstk-legacy-1b/1e/1g)
return EXIT_UNSUPPORTED when !CPU_FEATURE_ACTIVE (SHSTK); this patch should
do the same.
But I think there is a catch with the obvious fix:
if (!CPU_FEATURE_ACTIVE (SHSTK))
FAIL_UNSUPPORTED (...);
Where x86_cpu_cet_active reads %fs:72 with a non-volatile asm, so the
compiler may reuse the value across the dlopen call.
Making the asm in bits/platform/features.h volatile is probably worth a
separate fix, since CPU_FEATURE_ACTIVE (SHSTK) can change at run time.
Two more checks would make 4b and 4c test their policies:
- in 4b, SHSTK should still be enabled after the legacy object is
loaded;
- in 4c, glibc.cpu.x86_shstk=off should win over
glibc.cpu.hwcaps=SHSTK.
Without them, 4b only checks that dlopen does not fail, and the new
hwcaps setting has no visible effect in 4c.
> ---
> sysdeps/x86_64/Makefile | 7 ++++---
> sysdeps/x86_64/tst-cet-legacy-4.c | 4 ++++
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
> index dfb344d74a..32f71a2d92 100644
> --- a/sysdeps/x86_64/Makefile
> +++ b/sysdeps/x86_64/Makefile
> @@ -367,6 +367,7 @@ CFLAGS-tst-cet-legacy-3.c += -fcf-protection=none
> CFLAGS-tst-cet-legacy-4.c += -fcf-protection=none -fcf-protection=branch
> CPPFLAGS-tst-cet-legacy-4a.c += -DCET_IS_PERMISSIVE=1
> CFLAGS-tst-cet-legacy-4a.c += -fcf-protection
> +CPPFLAGS-tst-cet-legacy-4b.c += -DCET_IS_ALWAYS_ON=1
> CFLAGS-tst-cet-legacy-4b.c += -fcf-protection
> CFLAGS-tst-cet-legacy-mod-4.c += -fcf-protection=none
> CFLAGS-tst-cet-legacy-5a.c += -fcf-protection -mshstk
> @@ -425,11 +426,11 @@ $(objpfx)tst-cet-legacy-mod-6a.so: $(objpfx)tst-cet-legacy-mod-6c.so
> $(objpfx)tst-cet-legacy-mod-6b.so: $(objpfx)tst-cet-legacy-mod-6c.so
> LDFLAGS-tst-cet-legacy-mod-6c.so = -Wl,--enable-new-dtags,-z,nodelete
> $(objpfx)tst-cet-legacy-4a.out: $(objpfx)tst-cet-legacy-mod-4.so
> -tst-cet-legacy-4a-ENV = GLIBC_TUNABLES=glibc.cpu.x86_shstk=permissive
> +tst-cet-legacy-4a-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK:glibc.cpu.x86_shstk=permissive
> $(objpfx)tst-cet-legacy-4b.out: $(objpfx)tst-cet-legacy-mod-4.so
> -tst-cet-legacy-4b-ENV = GLIBC_TUNABLES=glibc.cpu.x86_shstk=on
> +tst-cet-legacy-4b-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK:glibc.cpu.x86_shstk=on
> $(objpfx)tst-cet-legacy-4c.out: $(objpfx)tst-cet-legacy-mod-4.so
> -tst-cet-legacy-4c-ENV = GLIBC_TUNABLES=glibc.cpu.x86_shstk=off
> +tst-cet-legacy-4c-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK:glibc.cpu.x86_shstk=off
> $(objpfx)tst-cet-legacy-5b.out: $(objpfx)tst-cet-legacy-mod-5a.so \
> $(objpfx)tst-cet-legacy-mod-5b.so
> tst-cet-legacy-5b-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
> diff --git a/sysdeps/x86_64/tst-cet-legacy-4.c b/sysdeps/x86_64/tst-cet-legacy-4.c
> index 73b0b0d7a3..d15679a163 100644
> --- a/sysdeps/x86_64/tst-cet-legacy-4.c
> +++ b/sysdeps/x86_64/tst-cet-legacy-4.c
> @@ -32,6 +32,10 @@ do_test (void)
> int (*fp) (void);
> void *h;
>
> +#if defined CET_IS_PERMISSIVE || defined CET_IS_ALWAYS_ON
> + TEST_VERIFY (CPU_FEATURE_ACTIVE (SHSTK));
> +#endif
> +
> h = dlopen (modname, RTLD_LAZY);
> if (h == NULL)
> {
More information about the Libc-alpha
mailing list