]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
aarch64: Add LD_PRELOAD tests for GCS handling
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 Jan 2026 16:52:38 +0000 (13:52 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 14 Jan 2026 17:33:27 +0000 (14:33 -0300)
There are modeled after the 'shared' tests subset and it adds 4 new
tests:

1. tst-gcs-preload-disabled: checks if GCS is disabled when a LD_PRELOAD
   module is used without GCS marking with default GCS support.

2. tst-gcs-preload-enforced-abort: chekcs if loader aborts startup when
   a LD_PRELOAD is used without GCS marking and GCS is enforced.

3. tst-gcs-preload-optional: checks if GCS is disabled when a LD_PRELOAD
   is used without GCS marking and GCS is optional.

4. tst-gcs-preload-override: checks if GCS is enabled when a LD_PRELOAD
   is used without GCS marking and GCS is overrided.

Checked on aarch64-linux-gnu with Linux 6.18 on Apple M4 emulated (for
BTI support) and on qemu 10.1.50 simulated (for GCS).

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
Tested-by: Yury Khrustalev <yury.khrustalev@arm.com>
sysdeps/unix/sysv/linux/aarch64/Makefile
sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-disabled.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-enforced-abort.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-optional.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-override.c [new file with mode: 0644]

index a8477087d998c57b9f0cb56744b67f125a745123..da8bb2de3d6a4b52550a02acaf72e76ff9c1686b 100644 (file)
@@ -35,6 +35,10 @@ gcs-tests-dynamic = \
   tst-gcs-noreturn \
   tst-gcs-optional-off \
   tst-gcs-optional-on \
+  tst-gcs-preload-disabled \
+  tst-gcs-preload-enforced-abort \
+  tst-gcs-preload-optional \
+  tst-gcs-preload-override \
   tst-gcs-override \
   tst-gcs-shared-disabled \
   tst-gcs-shared-enforced-abort \
@@ -159,6 +163,29 @@ $(objpfx)tst-gcs-ld-debug-%.out: $(..)elf/tst-dl-debug-protect.sh $(objpfx)tst-g
          'security: not compatible with AArch64 GCS: $(objpfx)' \
          $(objpfx)tst-gcs-ld-debug-$* > $@; $(evaluate-test)
 
+LDFLAGS-tst-gcs-preload-disabled += -Wl,-z,gcs=always
+LDFLAGS-tst-gcs-preload-enforced-abort = -Wl,-z,gcs=always
+LDFLAGS-tst-gcs-preload-optional = -Wl,-z,gcs=always
+LDFLAGS-tst-gcs-preload-override = -Wl,-z,gcs=always
+
+$(objpfx)tst-gcs-preload-disable: $(objpfx)tst-gcs-mod1.so
+$(objpfx)tst-gcs-preload-enforced-abort: $(objpfx)tst-gcs-mod1.so
+$(objpfx)tst-gcs-preload-optional: $(objpfx)tst-gcs-mod1.so
+$(objpfx)tst-gcs-preload-override: $(objpfx)tst-gcs-mod1.so
+
+tst-gcs-preload-disabled-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0 \
+  LD_PRELOAD=$(objpfx)tst-gcs-mod1.so
+tst-gcs-preload-enforced-abort-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1 \
+  LD_PRELOAD=$(objpfx)tst-gcs-mod1.so
+tst-gcs-preload-optional-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2 \
+  LD_PRELOAD=$(objpfx)tst-gcs-mod1.so
+tst-gcs-preload-override-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3 \
+  LD_PRELOAD=$(objpfx)tst-gcs-mod1.so
+
 endif # ifeq ($(have-test-gcs),yes)
 
 endif # ifeq ($(subdir),misc)
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-disabled.c
new file mode 100644 (file)
index 0000000..3c05fb9
--- /dev/null
@@ -0,0 +1,4 @@
+/* Checks if GCS is disabled when a LD_PRELOAD module is used without GCS
+   marking with default GCS support.  */
+#define TEST_GCS_EXPECT_ENABLED 0
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-enforced-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-enforced-abort.c
new file mode 100644 (file)
index 0000000..4c73f12
--- /dev/null
@@ -0,0 +1,4 @@
+/* Checks if loader aborts startup when a LD_PRELOAD is used without GCS
+   marking and GCS is enforced.  */
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-optional.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-optional.c
new file mode 100644 (file)
index 0000000..9f6c151
--- /dev/null
@@ -0,0 +1,4 @@
+/* Checks if GCS is disabled when a LD_PRELOADA is used without GCS marking
+   and GCS is optional.  */
+#define TEST_GCS_EXPECT_ENABLED 0
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-override.c
new file mode 100644 (file)
index 0000000..8ccb389
--- /dev/null
@@ -0,0 +1,4 @@
+/* Checks if GCS is enabled when a LD_PRELOAD is used without GCS marking and
+   GCS is overrided.  */
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-skeleton.c"