From: Farid Zakaria <farid.m.zakaria@gmail.com>
To: kees@kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk
Cc: jack@suse.cz, shuah@kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Farid Zakaria <farid.m.zakaria@gmail.com>
Subject: [PATCH 0/2] fs: support $ORIGIN in ELF interpreter paths
Date: Sun, 21 Jun 2026 21:39:32 -0700 [thread overview]
Message-ID: <20260622043934.179879-1-farid.m.zakaria@gmail.com> (raw)
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
next reply other threads:[~2026-06-22 4:39 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 4:39 Farid Zakaria [this message]
2026-06-22 4:39 ` [PATCH 1/2] " Farid Zakaria
2026-06-22 9:53 ` Jori Koolstra
2026-06-23 20:14 ` Kees Cook
2026-06-23 20:35 ` Farid Zakaria
2026-06-22 4:39 ` [PATCH 2/2] selftests/exec: add test suites for $ORIGIN interpreter resolution Farid Zakaria
2026-06-22 10:39 ` [PATCH 0/2] fs: support $ORIGIN in ELF interpreter paths Jan Kara
2026-06-22 17:15 ` Farid Zakaria
2026-06-22 21:08 ` John Ericson
2026-06-25 8:50 ` Christian Brauner
2026-06-25 19:34 ` John Ericson
2026-06-26 12:39 ` Jann Horn
2026-06-26 13:26 ` David Laight
2026-06-26 13:34 ` Jann Horn
2026-06-26 16:28 ` David Laight
2026-06-28 12:36 ` Christian Brauner
2026-06-28 13:20 ` Christian Brauner
2026-06-28 18:44 ` David Laight
2026-06-30 16:58 ` Farid Zakaria
2026-07-02 6:47 ` Christian Brauner
2026-06-30 17:59 ` David Laight
2026-07-02 21:42 ` [RFC PATCH] fs: introduce pluggable ELF interpreter loader registry Farid Zakaria
2026-07-03 9:22 ` Christian Brauner
2026-07-03 18:32 ` Farid Zakaria
2026-07-04 8:15 ` Christian Brauner
2026-07-04 21:14 ` [RFC PATCH] fs: binfmt_misc: introduce eBPF-based matching and interpreter selection Farid Zakaria
2026-07-06 16:01 ` Christian Brauner
2026-07-06 16:47 ` Farid Zakaria
2026-07-07 11:34 ` Christian Brauner
2026-07-07 19:45 ` Christian Brauner
2026-07-07 22:44 ` Farid Zakaria
2026-07-08 9:14 ` Christian Brauner
2026-07-08 16:47 ` Christian Brauner
2026-07-09 4:07 ` Farid Zakaria
2026-07-09 8:46 ` Christian Brauner
2026-07-21 23:18 ` Alessandro Di Federico
2026-07-22 13:33 ` Christian Brauner
2026-07-30 22:46 ` Alessandro Di Federico
2026-07-31 9:41 ` Christian Brauner
2026-08-02 22:54 ` Farid Zakaria
2026-08-05 7:56 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260622043934.179879-1-farid.m.zakaria@gmail.com \
--to=farid.m.zakaria@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®