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 <yury.khrustalev@arm.com>
Tested-by: Yury Khrustalev <yury.khrustalev@arm.com>
This commit is contained in:
Adhemerval Zanella 2026-01-07 13:52:36 -03:00
parent ae62786747
commit 99207945fb
7 changed files with 46 additions and 1 deletions

View File

@ -93,7 +93,9 @@ tests += \
tst-bti-abort-static \ tst-bti-abort-static \
tst-bti-abort-transitive \ tst-bti-abort-transitive \
tst-bti-abort-unprot \ tst-bti-abort-unprot \
tst-bti-abort-unprot-preload \
tst-bti-dep-prot \ tst-bti-dep-prot \
tst-bti-dep-prot-preload \
tst-bti-dlopen-imm \ tst-bti-dlopen-imm \
tst-bti-dlopen-prot \ tst-bti-dlopen-prot \
tst-bti-dlopen-transitive \ tst-bti-dlopen-transitive \
@ -103,13 +105,16 @@ tests += \
tst-bti-ld-debug-shared \ tst-bti-ld-debug-shared \
tst-bti-permissive-dlopen \ tst-bti-permissive-dlopen \
tst-bti-permissive-imm \ tst-bti-permissive-imm \
tst-bti-permissive-preload \
tst-bti-permissive-transitive \ tst-bti-permissive-transitive \
# tests # tests
modules-names += \ modules-names += \
tst-bti-mod \ tst-bti-mod \
tst-bti-mod-prot \ tst-bti-mod-prot \
tst-bti-mod-prot-preload \
tst-bti-mod-unprot \ tst-bti-mod-unprot \
tst-bti-mod-unprot-preload \
# modules-names # modules-names
$(objpfx)tst-bti-abort-imm: $(objpfx)tst-bti-mod-unprot.so $(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-shared: $(objpfx)tst-bti-mod.so
$(objpfx)tst-bti-ld-debug-both: $(objpfx)tst-bti-mod-unprot.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-abort-unprot.o += -mbranch-protection=none
CFLAGS-tst-bti-ld-debug-exe.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-ld-debug-both.o += -mbranch-protection=none
CFLAGS-tst-bti-mod-unprot.os += -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-imm-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1
tst-bti-abort-transitive-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1 tst-bti-abort-transitive-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1

View File

@ -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;
}

View File

@ -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"

View File

@ -0,0 +1 @@
#include "tst-bti-mod-prot.c"

View File

@ -0,0 +1 @@
#include "tst-bti-mod-unprot.c"

View File

@ -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"

View File

@ -24,8 +24,12 @@
#include <support/check.h> #include <support/check.h>
#include <support/test-driver.h> #include <support/test-driver.h>
#ifndef FUN_ATTRIBUTE
# define FUN_ATTRIBUTE
#endif
/* Defined in tst-bti-mod.c file. */ /* Defined in tst-bti-mod.c file. */
extern int fun (void); extern int fun (void) FUN_ATTRIBUTE;
typedef int (*fun_t) (void); typedef int (*fun_t) (void);