« All posts

Linux kernel edges toward $ORIGIN support via eBPF

How a Nix community effort led to a Linux kernel patch adding programmable $ORIGIN support via eBPF and binfmt_misc, without breaking process identity.

An effort to solve relocatable binaries in Nix has led to an unexpected kernel-side breakthrough. What began as a proposal to hardcode $ORIGIN support into the VFS subsystem turned, after constructive feedback from VFS maintainer Christian Brauner and Nix contributor John Ericson, into a far more flexible design: a programmable eBPF loader hooked into binfmt_misc via struct_ops.

The resulting eBPF program matches ELF binaries and dynamically determines the interpreter path at load time, enabling $ORIGIN support in both PT_INTERP and shebang lines. The same mechanism can replace traditional binfmt_misc registrations used by tools like QEMU. However, the classic binfmt_misc hand-off model has a side effect: the registered interpreter takes over the process's entire identity, breaking self-locating relocatable binaries that rely on argv[0] or /proc/self/exe.

Brauner's follow-up patch series addresses this by adding two new dispatch modes. The 'L' (loader substitution) mode is particularly notable: the kernel runs the matched binary natively as the main image and merely swaps out the PT_INTERP loader, leaving process identity intact. The patch series is expected to land in the -next branch soon. Once merged, a NixOS module is planned to enable this at boot, gated behind a new PT_INTERP_NIX segment so existing Nix binaries remain unaffected while opting-in binaries gain relocatable behavior.