]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
aarch64: Add LD_PRELOAD tests for BTI handling
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 Jan 2026 16:52:36 +0000 (13:52 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 14 Jan 2026 17:33:22 +0000 (14:33 -0300)
Add 3 new tests to check if LD_PRELOAD is correctly handled:

1. tst-bti-abort-unprot-preload: checks if the process is aborted if
   a LD_PRELOAD module without BTI marking is used and BTI is enforced.

2. tst-bti-dep-prot-preload: checks if the process works correctly if
   a LD_PRELOAD module with BTI marking is used and BTI is enforced.

3. tst-bti-permissive-preload: checks if the process works correctly
   if a LD_PRELOAD module with BTI marking is used and BTI is not
   enforced.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
Tested-by: Yury Khrustalev <yury.khrustalev@arm.com>
sysdeps/aarch64/Makefile
sysdeps/aarch64/tst-bti-abort-unprot-preload.c [new file with mode: 0644]
sysdeps/aarch64/tst-bti-dep-prot-preload.c [new file with mode: 0644]
sysdeps/aarch64/tst-bti-mod-prot-preload.c [new file with mode: 0644]
sysdeps/aarch64/tst-bti-mod-unprot-preload.c [new file with mode: 0644]
sysdeps/aarch64/tst-bti-permissive-preload.c [new file with mode: 0644]
sysdeps/aarch64/tst-bti-skeleton.c

index a87d02e64871dcc60474ec9c5ef1ad978ee1eeb5..00b7f7175286567f5a59432d7ce13dccace9ec50 100644 (file)
@@ -93,7 +93,9 @@ tests += \
   tst-bti-abort-static \
   tst-bti-abort-transitive \
   tst-bti-abort-unprot \
+  tst-bti-abort-unprot-preload \
   tst-bti-dep-prot \
+  tst-bti-dep-prot-preload \
   tst-bti-dlopen-imm \
   tst-bti-dlopen-prot \
   tst-bti-dlopen-transitive \
@@ -103,13 +105,16 @@ tests += \
   tst-bti-ld-debug-shared \
   tst-bti-permissive-dlopen \
   tst-bti-permissive-imm \
+  tst-bti-permissive-preload \
   tst-bti-permissive-transitive \
   # tests
 
 modules-names += \
   tst-bti-mod \
   tst-bti-mod-prot \
+  tst-bti-mod-prot-preload \
   tst-bti-mod-unprot \
+  tst-bti-mod-unprot-preload \
   # modules-names
 
 $(objpfx)tst-bti-abort-imm: $(objpfx)tst-bti-mod-unprot.so
@@ -122,10 +127,28 @@ $(objpfx)tst-bti-permissive-transitive: $(objpfx)tst-bti-mod.so
 $(objpfx)tst-bti-ld-debug-shared: $(objpfx)tst-bti-mod.so
 $(objpfx)tst-bti-ld-debug-both: $(objpfx)tst-bti-mod-unprot.so
 
+$(objpfx)tst-bti-abort-unprot-preload.out: $(objpfx)tst-bti-mod-unprot-preload.so
+tst-bti-abort-unprot-preload-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1 \
+  LD_PRELOAD=$(objpfx)tst-bti-mod-unprot-preload.so
+
+$(objpfx)tst-bti-dep-prot-preload.out: $(objpfx)tst-bti-mod-prot-preload.so
+# The 'fun' function will be provided by the preload library
+LDFLAGS-tst-bti-dep-prot-preload = -Wl,--unresolved-symbols=ignore-all
+tst-bti-dep-prot-preload-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_bti=0 \
+  LD_PRELOAD=$(objpfx)tst-bti-mod-prot-preload.so
+
+$(objpfx)tst-bti-permissive-preload.out: $(objpfx)tst-bti-mod-unprot-preload.so
+tst-bti-permissive-preload-ENV = \
+  GLIBC_TUNABLES=glibc.cpu.aarch64_bti=0 \
+  LD_PRELOAD=$(objpfx)tst-bti-mod-unprot-preload.so
+
 CFLAGS-tst-bti-abort-unprot.o += -mbranch-protection=none
 CFLAGS-tst-bti-ld-debug-exe.o += -mbranch-protection=none
 CFLAGS-tst-bti-ld-debug-both.o += -mbranch-protection=none
 CFLAGS-tst-bti-mod-unprot.os += -mbranch-protection=none
+CFLAGS-tst-bti-mod-unprot-preload.os += -mbranch-protection=none
 
 tst-bti-abort-imm-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1
 tst-bti-abort-transitive-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1
diff --git a/sysdeps/aarch64/tst-bti-abort-unprot-preload.c b/sysdeps/aarch64/tst-bti-abort-unprot-preload.c
new file mode 100644 (file)
index 0000000..108e42c
--- /dev/null
@@ -0,0 +1,8 @@
+/* This test checks if the process is aborted if LD_PRELOAD is used with a
+   module without BTI markings and BTI is enforced.  */
+#include "tst-bti-skeleton.c"
+
+int fun (void)
+{
+  return 0;
+}
diff --git a/sysdeps/aarch64/tst-bti-dep-prot-preload.c b/sysdeps/aarch64/tst-bti-dep-prot-preload.c
new file mode 100644 (file)
index 0000000..fbe0d97
--- /dev/null
@@ -0,0 +1,4 @@
+/* This test checks if the process works correctly with LD_PRELOAD module
+   with BTI marking and BTI is enforced.  */
+#define FUN_ATTRIBUTE __attribute__ ((weak))
+#include "tst-bti-skeleton.c"
diff --git a/sysdeps/aarch64/tst-bti-mod-prot-preload.c b/sysdeps/aarch64/tst-bti-mod-prot-preload.c
new file mode 100644 (file)
index 0000000..e727960
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-bti-mod-prot.c"
diff --git a/sysdeps/aarch64/tst-bti-mod-unprot-preload.c b/sysdeps/aarch64/tst-bti-mod-unprot-preload.c
new file mode 100644 (file)
index 0000000..c332023
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-bti-mod-unprot.c"
diff --git a/sysdeps/aarch64/tst-bti-permissive-preload.c b/sysdeps/aarch64/tst-bti-permissive-preload.c
new file mode 100644 (file)
index 0000000..db0cc1f
--- /dev/null
@@ -0,0 +1,4 @@
+/* This test checks if the process works correctly with a LD_PRELOAD module
+   with BTI marking and BTI is not enforced.  */
+#define FUN_ATTRIBUTE __attribute__ ((weak))
+#include "tst-bti-skeleton.c"
index 215cff46dcd87efc92b86bd6588339128f7bcc63..bf0e62706ff875937a7ebc85a27c0d357fbcd5b2 100644 (file)
 #include <support/check.h>
 #include <support/test-driver.h>
 
+#ifndef FUN_ATTRIBUTE
+# define FUN_ATTRIBUTE
+#endif
+
 /* Defined in tst-bti-mod.c file.  */
-extern int fun (void);
+extern int fun (void) FUN_ATTRIBUTE;
 
 typedef int (*fun_t) (void);