Today I Learned: Binfmt_misc

dfir.ch

69 points by malmoeb 7 days ago


dandersch - 11 hours ago

Before knowing about binfmt, I always wondered how wine is able is able to execute .exe files directly, i.e. ./prog.exe instead of wine ./prog.exe. Turns out the wine package (at least on Arch) comes with a handler for them and the Arch wiki mentions that you may want to remove it for security reasons.

throwawayqqq11 - 8 hours ago

Why can you register interpreters as non-root and why do these custom interpreters take precedence?

EDIT: Checked on may dated ubuntu laptop, /proc/sys/fs/binfmt_misc/register is root:root owned with --w-------. An important detail that the article omits and that changes this "vulnerability".

Brian_K_White - 4 hours ago

I used to run sco xenix and unix binaries on linux via ibcs. That worked by registering a binfmt-something-else not -misc, because it didn't load an interpreter like qemu or wine, the kernel ran the binary directly, so the binfmt was something like -sysv or -ibcs2 or something. Not for real / production, just for fun. I got it go but no situation ever arised that wasn't better solved some other way. And good thing because I don't think that has worked for many years.

DominoTree - 12 hours ago

Traditionally I've seen these adapters primarily used to pass binaries for other architectures to QEMU and similar.

Years ago on FreeBSD I created a "Volkswagen mode" by using the similar `imgact_binmisc` kernel module to register a handler for binaries with the system's native ELF headers. It took a bit of hacking to make it all work with the native architecture, but when it was done, the handler would simply execute the binary, drop its return code, and return 0 instead - effectively making the system think that every command was "successful"

The system failed to boot when I finally got it all working (which was expected) but it was a fun adventure to do something so pointless and silly.

It would be a similarly clever place to maintain persistence and transparently inject bytecode or do other rude things on FreeBSD as well

Valodim - 6 hours ago

https://search.nixos.org/options?show=boot.binfmt.emulatedSy...

Set this one line setting on a nixos system, and it can run foreign binaries. Magic.

dathinab - 6 hours ago

binfmt_misc helped me out a lot some years ago

I had a build system which was able to cross compile.

And a test system which wasn't able to handle cross compiled/emulated/remote code but needed to run test on cross compiled code.

In the end with binfmt the test system never knew it was running the code with qemu instead of native and "just worked".

muppetman - 6 hours ago

Another reason I compile my own kernels and disable features like this. I also disable loadable kernel modules. Of course this makes standard support channels... Difficult.