[PATCH 4/6] cet: Add new legacy shared library dlopen test

Arjun Shankar arjun@redhat.com
Mon Nov 23 12:46:58 GMT 2026


None of the current legacy dlopen tests for CET test the default
behaviour (i.e. reject legacy dlopen when running in SHSTK mode).
tst-cet-legacy-4 is IBT-only, and 4a, 4b, and 4c explicitly set the
policy (via glibc.cpu.x86_shstk tunable) to permissive, on, or off.

Add a new test (-4d) that does not set glibc.cpu.x86_shstk, allowing
dlopen to reject a legacy object load based on its ELF property in the
"--enable-cet" build configuration.  Adjust tst-cet-legacy-4.c to add
relevant asserts for this case.
---
 sysdeps/x86_64/Makefile            | 9 +++++++++
 sysdeps/x86_64/tst-cet-legacy-4.c  | 9 ++++++++-
 sysdeps/x86_64/tst-cet-legacy-4d.c | 1 +
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/x86_64/tst-cet-legacy-4d.c

diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
index 5abed12bf2..ddbf05effa 100644
--- a/sysdeps/x86_64/Makefile
+++ b/sysdeps/x86_64/Makefile
@@ -344,6 +344,7 @@ tests += \
   tst-cet-legacy-4a \
   tst-cet-legacy-4b \
   tst-cet-legacy-4c \
+  tst-cet-legacy-4d \
   tst-cet-legacy-5b \
   tst-cet-legacy-6b \
 # tests
@@ -369,6 +370,12 @@ 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
+ifeq ($(enable-cet),permissive)
+CPPFLAGS-tst-cet-legacy-4d.c += -DCET_IS_PERMISSIVE=1
+else
+CPPFLAGS-tst-cet-legacy-4d.c += -DCET_IS_DEFAULT=1
+endif
+CFLAGS-tst-cet-legacy-4d.c += -fcf-protection
 CFLAGS-tst-cet-legacy-mod-4.c += -fcf-protection=none
 CFLAGS-tst-cet-legacy-5a.c += -fcf-protection -mshstk
 ifeq ($(enable-cet),permissive)
@@ -432,6 +439,8 @@ $(objpfx)tst-cet-legacy-4b.out: $(objpfx)tst-cet-legacy-mod-4.so
 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.hwcaps=SHSTK:glibc.cpu.x86_shstk=off
+$(objpfx)tst-cet-legacy-4d.out: $(objpfx)tst-cet-legacy-mod-4.so
+tst-cet-legacy-4d-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK
 $(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 9378cd4bf3..3ef2743c5c 100644
--- a/sysdeps/x86_64/tst-cet-legacy-4.c
+++ b/sysdeps/x86_64/tst-cet-legacy-4.c
@@ -32,7 +32,7 @@ do_test (void)
   int (*fp) (void);
   void *h;
 
-#if defined CET_IS_PERMISSIVE || defined CET_IS_ALWAYS_ON
+#if defined CET_IS_PERMISSIVE || defined CET_IS_ALWAYS_ON || defined CET_IS_DEFAULT
   if (!CPU_FEATURE_ACTIVE (SHSTK))
     /* We are probably running on a CPU/system that does not support CET.  */
     FAIL_UNSUPPORTED ("SHSTK not supported");
@@ -48,6 +48,13 @@ do_test (void)
   /* Load the legacy object and stay in SHSTK mode.  */
   TEST_VERIFY_EXIT (h != NULL);
   TEST_VERIFY (CPU_FEATURE_ACTIVE (SHSTK));
+#elif defined CET_IS_DEFAULT
+  /* Refuse to load legacy object.  */
+  TEST_VERIFY_EXIT (h == NULL);
+  const char *err = dlerror ();
+  if (!strstr (err, "rebuild shared object with SHSTK support enabled"))
+    FAIL_EXIT1 ("incorrect dlopen '%s' error: %s\n", modname, err);
+  return 0;
 #else
   /* We were never in SHSTK mode.  */
   TEST_VERIFY_EXIT (h != NULL);
diff --git a/sysdeps/x86_64/tst-cet-legacy-4d.c b/sysdeps/x86_64/tst-cet-legacy-4d.c
new file mode 100644
index 0000000000..b9bb18c36b
--- /dev/null
+++ b/sysdeps/x86_64/tst-cet-legacy-4d.c
@@ -0,0 +1 @@
+#include "tst-cet-legacy-4.c"
-- 
2.56.0



More information about the Libc-alpha mailing list