Binfmt misc


binfmt_misc is a capability of the Linux kernel which allows arbitrary executable file formats to be recognized and passed to certain user space applications, such as emulators and virtual machines. It is one of a number of binary format handlers in the kernel that are involved in preparing a user-space program to run.
The executable formats are registered through the special purpose file system binfmt_misc file-system interface. This is either done directly by sending special sequences to the register procfs file or using a wrapper like Debian-based distributions binfmt-support package or systemd's systemd-binfmt.service.

Registration

According to the a executable file type can be added by writing a line to the register file, of the form:
:name:type:offset:magic:mask:interpreter:flags, name is the name of the binary format.type is either E or M
  • * If it is E, the executable file format is identified by its filename extension: magic is the file extension to be associated with the binary format; offset and mask are ignored.
  • * If it is M, the format is identified by magic number at an absolute offset in the file and mask is a bitmask indicating which bits in the number are significant.interpreter is a program that is to be run with the matching file as an argument.flags is a string of letters, each controlling a certain aspect of interpreter invocation:
  • * P to preserve the original program name typed by user in command line — by adding that name to argv; the interpreter has to be aware of this so it can correctly pass that additional parameter to the interpreted program as its argv.
  • * O to open the program file and pass its file descriptor to the interpreter so it could read an otherwise unreadable file.
  • * C to determine new process credentials based on program file rather than interpreter file ; implies O flag.
  • * F to make the kernel open the binary at configuration time instead of lazily at startup time, so that it is available inside other mount namespaces and chroots as well.
Each format has a corresponding file entry in the /proc/sys/fs/binfmt_misc directory which can be read to get information about a given file format, or written to disable, enable or deregister it.

Common usage