From: Adhemerval Zanella Date: Wed, 7 Jan 2026 16:52:38 +0000 (-0300) Subject: aarch64: Add LD_PRELOAD tests for GCS handling X-Git-Tag: glibc-2.43~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e304c9cbf779ea49d6cd6e815c4e76fd4e727ef8;p=thirdparty%2Fglibc.git aarch64: Add LD_PRELOAD tests for GCS handling 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 Tested-by: Yury Khrustalev --- diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile index a8477087d9..da8bb2de3d 100644 --- a/sysdeps/unix/sysv/linux/aarch64/Makefile +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile @@ -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 index 0000000000..3c05fb9a56 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-disabled.c @@ -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 index 0000000000..4c73f127fe --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-enforced-abort.c @@ -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 index 0000000000..9f6c1517c1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-optional.c @@ -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 index 0000000000..8ccb389d17 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-preload-override.c @@ -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"