[PATCH 3/6] cet: Correctly run dlopen tests with SHSTK enabled in hwcaps
Arjun Shankar
arjun@redhat.com
Mon Nov 23 12:46:57 GMT 2026
The tst-cet-legacy-{4,5,6}* tests exercise dlopen with CET. However,
since 55d63e731253de82e96ed4ddca2e294076cd0bc5, CET is not set active
unless enabled in hwcaps. Some of the 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. The tst-cet-legacy-6-ENV entry was
spurious (the test is only run in its 'a' or 'b' variants), so drop
it.
2. For tst-cet-legacy-4a and tst-cet-legacy-4b, check that the test
has SHSTK enabled before dlopen, otherwise mark it UNSUPPORTED.
3. Adjust tst-cet-legacy-4 to assert dlopen result and SHSTK status for
all derived tests.
---
sysdeps/x86_64/Makefile | 10 ++++++----
sysdeps/x86_64/tst-cet-legacy-4.c | 23 ++++++++++++++++-------
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
index dfb344d74a..5abed12bf2 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
@@ -394,7 +395,8 @@ CFLAGS-tst-cet-legacy-10a.c += -fcf-protection=none -mshstk
CFLAGS-tst-cet-legacy-10a-static.c += -fcf-protection=none -mshstk
tst-cet-legacy-4-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
-tst-cet-legacy-6-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
+tst-cet-legacy-5a-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
+tst-cet-legacy-6a-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
tst-cet-legacy-10-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
tst-cet-legacy-10-static-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
tst-cet-legacy-10a-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
@@ -425,11 +427,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..9378cd4bf3 100644
--- a/sysdeps/x86_64/tst-cet-legacy-4.c
+++ b/sysdeps/x86_64/tst-cet-legacy-4.c
@@ -32,16 +32,25 @@ do_test (void)
int (*fp) (void);
void *h;
+#if defined CET_IS_PERMISSIVE || defined CET_IS_ALWAYS_ON
+ if (!CPU_FEATURE_ACTIVE (SHSTK))
+ /* We are probably running on a CPU/system that does not support CET. */
+ FAIL_UNSUPPORTED ("SHSTK not supported");
+#endif
+
h = dlopen (modname, RTLD_LAZY);
- if (h == NULL)
- {
- const char *err = dlerror ();
- if (!strstr (err, "rebuild shared object with IBT support enabled"))
- FAIL_EXIT1 ("incorrect dlopen '%s' error: %s\n", modname, err);
- return 0;
- }
#ifdef CET_IS_PERMISSIVE
+ /* Load the legacy object and transition to non-SHSTK mode. */
+ TEST_VERIFY_EXIT (h != NULL);
+ TEST_VERIFY (!CPU_FEATURE_ACTIVE (IBT) && !CPU_FEATURE_ACTIVE (SHSTK));
+#elif defined CET_IS_ALWAYS_ON
+ /* Load the legacy object and stay in SHSTK mode. */
+ TEST_VERIFY_EXIT (h != NULL);
+ TEST_VERIFY (CPU_FEATURE_ACTIVE (SHSTK));
+#else
+ /* We were never in SHSTK mode. */
+ TEST_VERIFY_EXIT (h != NULL);
TEST_VERIFY (!CPU_FEATURE_ACTIVE (IBT) && !CPU_FEATURE_ACTIVE (SHSTK));
#endif
--
2.56.0
More information about the Libc-alpha
mailing list