Currently, standard ELF and ELF FDPIC loaders require a fixed, absolute path to the dynamic linker/interpreter (specified via PT_INTERP). This creates significant inflexibility for relocatable dynamic interpreters, where binaries are packaged independent of global system paths.
The primary goal of this patch series is to support relocatable binaries in Nix, where packages are stored in a read-only store (typically /nix/store). Allowing the ELF interpreter path to be resolved dynamically relative to the binary's location via $ORIGIN enables Nix packages to be relocated without needing patchelf or wrapper scripts. For details on the design and motivation for this in Nix, see: https://fzakaria.com/2026/06/21/nix-needs-relocatable-binaries This series introduces support for resolving the $ORIGIN placeholder in the ELF interpreter path, bringing the kernel's binary loading behavior in line with user-space dynamic linker origin resolution. To achieve this cleanly: - We introduce a shared 'resolve_elf_interpreter()' helper in the VFS exec subsystem to avoid code duplication across loader implementations. - For security, we restrict detection strictly to the prefix string "$ORIGIN" to prevent complex parsing exploits in kernel space. Testing & Verification: - Added a KUnit test case verifying path resolution logic. - Added a kselftests integration test checking that a dynamically linked binary with its interpreter set to '$ORIGIN/mock_interp' successfully loads the mock interpreter (built statically using nolibc to avoid glibc TLS setup constraints during interpreter load-time). - Verified end-to-end correct execution (PASS) using a minimal initramfs under QEMU. Farid Zakaria (2): fs: support $ORIGIN in ELF interpreter paths selftests/exec: add test suites for $ORIGIN interpreter resolution fs/binfmt_elf.c | 11 ++++- fs/binfmt_elf_fdpic.c | 15 ++++++- fs/exec.c | 42 +++++++++++++++++++ fs/tests/exec_kunit.c | 26 ++++++++++++ include/linux/binfmts.h | 2 + tools/testing/selftests/exec/Makefile | 12 ++++-- tools/testing/selftests/exec/mock_interp.c | 6 +++ tools/testing/selftests/exec/origin_interp.sh | 16 +++++++ tools/testing/selftests/exec/test_prog.c | 5 +++ 9 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/exec/mock_interp.c create mode 100755 tools/testing/selftests/exec/origin_interp.sh create mode 100644 tools/testing/selftests/exec/test_prog.c -- 2.51.2

