[PATCH] CET: Correctly run dlopen tests with SHSTK enabled in hwcaps

Arjun Shankar arjun@redhat.com
Wed Nov 11 12:14:34 GMT 2026


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.
---
 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)
     {
-- 
2.56.0



More information about the Libc-alpha mailing list