Linux 7.3 brings 'More powerful binfmt_misc for sophisticated distros' (eg NixOS)

Just stumbled upon this great piece of news at Linux_7.3 - Linux Kernel Newbies :

This release extends the binfmt_misc format registry so a binary type can be matched programmatically and its interpreter computed per exec instead of being a fixed string recorded at registration time. This allows Nix and others to e.g., implement relocatable binaries without patchelf tricks or wrapper scripts, because the interpreter/dynamic loader can be determined programatically, say found relative to the binary. The mechanism is flexible and can support other policies

47 Likes

Nix might have had something to do with it.

18 Likes

$ORIGIN support in PT_INTERP is a neat idea, but I’m going to be very unhappy if I can’t continue to disable eBPF at kernel build time. I hope we can get a version of the feature that doesn’t depend on that.

5 Likes

It may be worth advocating for that on the mailing list, IIRC that was @fzakaria’s original idea but they walked it back for (possibly) compat reasons.

2 Likes

I think @Ericson2314 also inspired https://kernelnewbies.org/Linux_7.3#New_sandboxing_technique_with_failfs_.2B-_fchroot.282.29

6 Likes

Oh wow, I need no idea that eventually got merged! Yay!!

2 Likes

Wait, so we may be able to just slough off patchelf?

Sorry, which mailing list are you thinking of?

Farid wrote about the LKML thread here: Linux kernel will support $ORIGIN, sort of | Farid Zakaria’s Blog

I’m making the assumption that they didn’t want to add direct $ORIGIN support for compat reasons – literal $ORIGIN in a binary would have not worked before, and now would, which is a userspace behavior change that would not have been opt-in. (Perhaps if we wanted it without eBPF, it could be an opt-in config option?)

Anyway, it is an assumption, @fzakaria participated directly in the thread and I’m curious what the reasoning boiled down to.

1 Like

I’m pragmatic;

I want to see this relocatable binaries for a long time – so when someone gives you a path to get there (olive branch), you accept it :slight_smile:

All the reasons are in the thread and @numinit summary is pretty spot on.
We could do this at NixOS ourselves, but this will move the whole Linux landscape forward.

4 Likes