From: Adhemerval Zanella Date: Wed, 7 Jan 2026 16:52:36 +0000 (-0300) Subject: aarch64: Add LD_PRELOAD tests for BTI handling X-Git-Tag: glibc-2.43~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99207945fb60e251c62343c7bd2cb5677e7e71e6;p=thirdparty%2Fglibc.git aarch64: Add LD_PRELOAD tests for BTI handling 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 Tested-by: Yury Khrustalev --- diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index a87d02e648..00b7f71752 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -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 index 0000000000..108e42c8bf --- /dev/null +++ b/sysdeps/aarch64/tst-bti-abort-unprot-preload.c @@ -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 index 0000000000..fbe0d978b6 --- /dev/null +++ b/sysdeps/aarch64/tst-bti-dep-prot-preload.c @@ -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 index 0000000000..e727960c53 --- /dev/null +++ b/sysdeps/aarch64/tst-bti-mod-prot-preload.c @@ -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 index 0000000000..c332023018 --- /dev/null +++ b/sysdeps/aarch64/tst-bti-mod-unprot-preload.c @@ -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 index 0000000000..db0cc1faf5 --- /dev/null +++ b/sysdeps/aarch64/tst-bti-permissive-preload.c @@ -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" diff --git a/sysdeps/aarch64/tst-bti-skeleton.c b/sysdeps/aarch64/tst-bti-skeleton.c index 215cff46dc..bf0e62706f 100644 --- a/sysdeps/aarch64/tst-bti-skeleton.c +++ b/sysdeps/aarch64/tst-bti-skeleton.c @@ -24,8 +24,12 @@ #include #include +#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);