The relative RPATH ("./") supplied to linker options in CFLAGS is resolved
relative to current working directory and not the executable directory,
which will lead in incorrect resolution when the test executables are run
from elsewhere. Changing it to $ORIGIN makes it resolve relative
to the directory in which the executables reside, which is supposedly
the desired behaviour. This patch also moves these CFLAGS to lib.mk,
so the RPATH is provided for all selftest binaries, which is arguably
a useful default.
Discovered by the check-rpaths script[1][2] that checks for insecure
RPATH/RUNPATH[3], such as relative directories, during an attempt
to package BPF selftests for later use in CI:
ERROR 0004: file '/usr/libexec/kselftests/bpf/urandom_read' contains an insecure runpath '.' in [.]
[1] https://github.com/rpm-software-management/rpm/blob/master/scripts/check-rpaths
[2] https://github.com/rpm-software-management/rpm/blob/master/scripts/check-rpaths-worker
[3] https://cwe.mitre.org/data/definitions/426.html
Signed-off-by: Eugene Syromiatnikov <esyr@xxxxxxxxxx>
---
v2:
- Consolidated the updated -L/-Wl,-rpath setting into lib.mk
- Described the testing done in the commit message
v1: https://lore.kernel.org/lkml/20240808145639.GA20510@xxxxxxxxxxxxxxxxx/
https://lore.kernel.org/lkml/20240808151335.GA5495@xxxxxxxxxxxxxxxxx/
https://lore.kernel.org/lkml/20240808151621.GA10025@xxxxxxxxxxxxxxxxx/
https://lore.kernel.org/lkml/20240808151621.GA10025@xxxxxxxxxxxxxxxxx/
---
tools/testing/selftests/alsa/Makefile | 1 -
tools/testing/selftests/bpf/Makefile | 5 ++---
tools/testing/selftests/lib.mk | 3 +++
tools/testing/selftests/rseq/Makefile | 2 +-
tools/testing/selftests/sched/Makefile | 3 +--
5 files changed, 7 insertions(+), 7 deletions(-)