sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget+/translations/zh_CN/admin-guide/binfmt-miscmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget+/translations/zh_TW/admin-guide/binfmt-miscmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget+/translations/it_IT/admin-guide/binfmt-miscmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget+/translations/ja_JP/admin-guide/binfmt-miscmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget+/translations/ko_KR/admin-guide/binfmt-miscmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget+/translations/pt_BR/admin-guide/binfmt-miscmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget+/translations/sp_SP/admin-guide/binfmt-miscmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(h=Kernel Support for miscellaneous Binary Formats (binfmt_misc)h]h=Kernel Support for miscellaneous Binary Formats (binfmt_misc)}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhE/var/lib/git/docbuild/linux/Documentation/admin-guide/binfmt-misc.rsthKubh paragraph)}(hThis Kernel feature allows you to invoke almost (for restrictions see below) every program by simply typing its name in the shell. This includes for example compiled Java(TM), Python or Emacs programs.h]hThis Kernel feature allows you to invoke almost (for restrictions see below) every program by simply typing its name in the shell. This includes for example compiled Java(TM), Python or Emacs programs.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXTTo achieve this you must tell binfmt_misc which interpreter has to be invoked with which binary. Binfmt_misc recognises the binary-type by matching some bytes at the beginning of the file with a magic byte sequence (masking out specified bits) you have supplied. Binfmt_misc can also recognise a filename extension aka ``.com`` or ``.exe``.h](hX?To achieve this you must tell binfmt_misc which interpreter has to be invoked with which binary. Binfmt_misc recognises the binary-type by matching some bytes at the beginning of the file with a magic byte sequence (masking out specified bits) you have supplied. Binfmt_misc can also recognise a filename extension aka }(hhhhhNhNubhliteral)}(h``.com``h]h.com}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh or }(hhhhhNhNubh)}(h``.exe``h]h.exe}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h"First you must mount binfmt_misc::h]h!First you must mount binfmt_misc:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh literal_block)}(h9mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misch]h9mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhKhhhhubh)}(hTo actually register a new binary type, you have to set up a string looking like ``:name:type:offset:magic:mask:interpreter:flags`` (where you can choose the ``:`` upon your needs) and echo it to ``/proc/sys/fs/binfmt_misc/register``.h](hQTo actually register a new binary type, you have to set up a string looking like }(hj/hhhNhNubh)}(h2``:name:type:offset:magic:mask:interpreter:flags``h]h.:name:type:offset:magic:mask:interpreter:flags}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj/ubh (where you can choose the }(hj/hhhNhNubh)}(h``:``h]h:}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj/ubh! upon your needs) and echo it to }(hj/hhhNhNubh)}(h%``/proc/sys/fs/binfmt_misc/register``h]h!/proc/sys/fs/binfmt_misc/register}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj/ubh.}(hj/hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hHere is what the fields mean:h]hHere is what the fields mean:}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh bullet_list)}(hhh](h list_item)}(h``name`` is an identifier string. A new /proc file will be created with this name below ``/proc/sys/fs/binfmt_misc``; cannot contain slashes ``/`` for obvious reasons.h]hdefinition_list)}(hhh]hdefinition_list_item)}(h``name`` is an identifier string. A new /proc file will be created with this name below ``/proc/sys/fs/binfmt_misc``; cannot contain slashes ``/`` for obvious reasons.h](hterm)}(h``name``h]h)}(hjh]hname}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh definition)}(hhh]h)}(his an identifier string. A new /proc file will be created with this name below ``/proc/sys/fs/binfmt_misc``; cannot contain slashes ``/`` for obvious reasons.h](hOis an identifier string. A new /proc file will be created with this name below }(hjhhhNhNubh)}(h``/proc/sys/fs/binfmt_misc``h]h/proc/sys/fs/binfmt_misc}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh; cannot contain slashes }(hjhhhNhNubh)}(h``/``h]h/}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh for obvious reasons.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(h``type`` is the type of recognition. Give ``M`` for magic, ``E`` for extension and ``B`` for a bpf-backed handler (see below).h]j)}(hhh]j)}(h~``type`` is the type of recognition. Give ``M`` for magic, ``E`` for extension and ``B`` for a bpf-backed handler (see below).h](j)}(h``type``h]h)}(hj h]htype}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]uh1jhhhKhjubj)}(hhh]h)}(huis the type of recognition. Give ``M`` for magic, ``E`` for extension and ``B`` for a bpf-backed handler (see below).h](h!is the type of recognition. Give }(hj$hhhNhNubh)}(h``M``h]hM}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$ubh for magic, }(hj$hhhNhNubh)}(h``E``h]hE}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$ubh for extension and }(hj$hhhNhNubh)}(h``B``h]hB}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$ubh& for a bpf-backed handler (see below).}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj!ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(h``offset`` is the offset of the magic/mask in the file, counted in bytes. This defaults to 0 if you omit it (i.e. you write ``:name:type::magic...``). Ignored when using filename extension matching.h]j)}(hhh]j)}(h``offset`` is the offset of the magic/mask in the file, counted in bytes. This defaults to 0 if you omit it (i.e. you write ``:name:type::magic...``). Ignored when using filename extension matching.h](j)}(h ``offset``h]h)}(hjh]hoffset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhhhK!hjubj)}(hhh]h)}(his the offset of the magic/mask in the file, counted in bytes. This defaults to 0 if you omit it (i.e. you write ``:name:type::magic...``). Ignored when using filename extension matching.h](hqis the offset of the magic/mask in the file, counted in bytes. This defaults to 0 if you omit it (i.e. you write }(hjhhhNhNubh)}(h``:name:type::magic...``h]h:name:type::magic...}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh2). Ignored when using filename extension matching.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhK!hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(hX``magic`` is the byte sequence binfmt_misc is matching for. The magic string may contain hex-encoded characters like ``\x0a`` or ``\xA4``. Note that you must escape any NUL bytes; parsing halts at the first one. In a shell environment you might have to write ``\\x0a`` to prevent the shell from eating your ``\``. If you chose filename extension matching, this is the extension to be recognised (without the ``.``, the ``\x0a`` specials are not allowed). Extension matching is case sensitive, and slashes ``/`` are not allowed!h]j)}(hhh]j)}(hX``magic`` is the byte sequence binfmt_misc is matching for. The magic string may contain hex-encoded characters like ``\x0a`` or ``\xA4``. Note that you must escape any NUL bytes; parsing halts at the first one. In a shell environment you might have to write ``\\x0a`` to prevent the shell from eating your ``\``. If you chose filename extension matching, this is the extension to be recognised (without the ``.``, the ``\x0a`` specials are not allowed). Extension matching is case sensitive, and slashes ``/`` are not allowed!h](j)}(h ``magic``h]h)}(hjh]hmagic}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhhhK*hjubj)}(hhh]h)}(hXis the byte sequence binfmt_misc is matching for. The magic string may contain hex-encoded characters like ``\x0a`` or ``\xA4``. Note that you must escape any NUL bytes; parsing halts at the first one. In a shell environment you might have to write ``\\x0a`` to prevent the shell from eating your ``\``. If you chose filename extension matching, this is the extension to be recognised (without the ``.``, the ``\x0a`` specials are not allowed). Extension matching is case sensitive, and slashes ``/`` are not allowed!h](hkis the byte sequence binfmt_misc is matching for. The magic string may contain hex-encoded characters like }(hjhhhNhNubh)}(h``\x0a``h]h\x0a}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh or }(hjhhhNhNubh)}(h``\xA4``h]h\xA4}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhz. Note that you must escape any NUL bytes; parsing halts at the first one. In a shell environment you might have to write }(hjhhhNhNubh)}(h ``\\x0a``h]h\\x0a}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh' to prevent the shell from eating your }(hjhhhNhNubh)}(h``\``h]h\}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh`. If you chose filename extension matching, this is the extension to be recognised (without the }(hjhhhNhNubh)}(h``.``h]h.}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh, the }(hjhhhNhNubh)}(h``\x0a``h]h\x0a}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhQ specials are not allowed). Extension matching is case sensitive, and slashes }(hjhhhNhNubh)}(h``/``h]h/}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh are not allowed!}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK$hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhK*hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(hXI``mask`` is an (optional, defaults to all 0xff) mask. You can mask out some bits from matching by supplying a string like magic and as long as magic. The mask is anded with the byte sequence of the file. Note that you must escape any NUL bytes; parsing halts at the first one. Ignored when using filename extension matching.h]j)}(hhh]j)}(hXD``mask`` is an (optional, defaults to all 0xff) mask. You can mask out some bits from matching by supplying a string like magic and as long as magic. The mask is anded with the byte sequence of the file. Note that you must escape any NUL bytes; parsing halts at the first one. Ignored when using filename extension matching.h](j)}(h``mask``h]h)}(hjh]hmask}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhhhK0hjubj)}(hhh]h)}(hX;is an (optional, defaults to all 0xff) mask. You can mask out some bits from matching by supplying a string like magic and as long as magic. The mask is anded with the byte sequence of the file. Note that you must escape any NUL bytes; parsing halts at the first one. Ignored when using filename extension matching.h]hX;is an (optional, defaults to all 0xff) mask. You can mask out some bits from matching by supplying a string like magic and as long as magic. The mask is anded with the byte sequence of the file. Note that you must escape any NUL bytes; parsing halts at the first one. Ignored when using filename extension matching.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhK0hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(h``interpreter`` is the program that should be invoked with the binary as first argument (specify the full path). For ``B`` entries this field carries the name of the bpf handler instead (see below).h]j)}(hhh]j)}(h``interpreter`` is the program that should be invoked with the binary as first argument (specify the full path). For ``B`` entries this field carries the name of the bpf handler instead (see below).h](j)}(h``interpreter``h]h)}(hjh]h interpreter}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhhhK4hjubj)}(hhh]h)}(his the program that should be invoked with the binary as first argument (specify the full path). For ``B`` entries this field carries the name of the bpf handler instead (see below).h](heis the program that should be invoked with the binary as first argument (specify the full path). For }(hjhhhNhNubh)}(h``B``h]hB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhL entries this field carries the name of the bpf handler instead (see below).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK3hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhK4hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(hX``flags`` is an optional field that controls several aspects of the invocation of the interpreter. It is a string of capital letters, each controls a certain aspect. The following flags are supported: ``P`` - preserve-argv[0] Legacy behavior of binfmt_misc is to overwrite the original argv[0] with the full path to the binary. When this flag is included, binfmt_misc will add an argument to the argument vector for this purpose, thus preserving the original ``argv[0]``. e.g. If your interp is set to ``/bin/foo`` and you run ``blah`` (which is in ``/usr/local/bin``), then the kernel will execute ``/bin/foo`` with ``argv[]`` set to ``["/bin/foo", "/usr/local/bin/blah", "blah"]``. The interp has to be aware of this so it can execute ``/usr/local/bin/blah`` with ``argv[]`` set to ``["blah"]``. ``O`` - open-binary Legacy behavior of binfmt_misc is to pass the full path of the binary to the interpreter as an argument. When this flag is included, binfmt_misc will open the file for reading and pass its descriptor into the auxilary vector with the key "AT_EXECFD", thus allowing the interpreter to execute non-readable binaries. This feature should be used with care - the interpreter has to be trusted not to emit the contents of the non-readable binary. ``C`` - credentials Currently, the behavior of binfmt_misc is to calculate the credentials and security token of the new process according to the interpreter. When this flag is included, these attributes are calculated according to the binary. It also implies the ``O`` flag. This feature should be used with care as the interpreter will run with root permissions when a setuid binary owned by root is run with binfmt_misc. ``F`` - fix binary The usual behaviour of binfmt_misc is to spawn the binary lazily when the misc format file is invoked. However, this doesn't work very well in the face of mount namespaces and changeroots, so the ``F`` mode opens the binary as soon as the emulation is installed and uses the opened image to spawn the emulator, meaning it is always available once installed, regardless of how the environment changes. ``T`` - transparent Run the interpreter transparently. The binary is handed to the interpreter through ``AT_EXECFD`` (``T`` implies ``O``), the argument vector is left exactly as the caller built it and the kernel labels ``/proc/pid/exe`` with the binary instead of the interpreter. The interpreter has to load the binary from ``AT_EXECFD`` and follow the ``AT_FLAGS_TRANSPARENT_INTERP`` contract. Combining ``T`` with ``P`` is rejected: transparency preserves the whole argument vector, argv[0] included. ``L`` - loader substitution Do not run the interpreter on the binary at all: load the binary itself as a fully native exec and substitute the interpreter for the loader named in the binary's ``PT_INTERP``. See the "Loader substitution" section below. ``L`` rejects ``T``, ``P``, ``O`` and ``C``; ``F`` composes. ``D`` - registered disabled The entry is created disabled instead of being matchable at once, and has to be enabled by writing ``1`` to its file before it dispatches anything. This splits a registration into creating the entry and activating it, leaving room to configure it in between - which is what a ``B`` entry that binds interpreters needs; see the bpf section below. The flag is spent on the registration and is not read back: what an entry file reports afterwards is whether it is enabled. h]j)}(hhh]j)}(hXR``flags`` is an optional field that controls several aspects of the invocation of the interpreter. It is a string of capital letters, each controls a certain aspect. The following flags are supported: ``P`` - preserve-argv[0] Legacy behavior of binfmt_misc is to overwrite the original argv[0] with the full path to the binary. When this flag is included, binfmt_misc will add an argument to the argument vector for this purpose, thus preserving the original ``argv[0]``. e.g. If your interp is set to ``/bin/foo`` and you run ``blah`` (which is in ``/usr/local/bin``), then the kernel will execute ``/bin/foo`` with ``argv[]`` set to ``["/bin/foo", "/usr/local/bin/blah", "blah"]``. The interp has to be aware of this so it can execute ``/usr/local/bin/blah`` with ``argv[]`` set to ``["blah"]``. ``O`` - open-binary Legacy behavior of binfmt_misc is to pass the full path of the binary to the interpreter as an argument. When this flag is included, binfmt_misc will open the file for reading and pass its descriptor into the auxilary vector with the key "AT_EXECFD", thus allowing the interpreter to execute non-readable binaries. This feature should be used with care - the interpreter has to be trusted not to emit the contents of the non-readable binary. ``C`` - credentials Currently, the behavior of binfmt_misc is to calculate the credentials and security token of the new process according to the interpreter. When this flag is included, these attributes are calculated according to the binary. It also implies the ``O`` flag. This feature should be used with care as the interpreter will run with root permissions when a setuid binary owned by root is run with binfmt_misc. ``F`` - fix binary The usual behaviour of binfmt_misc is to spawn the binary lazily when the misc format file is invoked. However, this doesn't work very well in the face of mount namespaces and changeroots, so the ``F`` mode opens the binary as soon as the emulation is installed and uses the opened image to spawn the emulator, meaning it is always available once installed, regardless of how the environment changes. ``T`` - transparent Run the interpreter transparently. The binary is handed to the interpreter through ``AT_EXECFD`` (``T`` implies ``O``), the argument vector is left exactly as the caller built it and the kernel labels ``/proc/pid/exe`` with the binary instead of the interpreter. The interpreter has to load the binary from ``AT_EXECFD`` and follow the ``AT_FLAGS_TRANSPARENT_INTERP`` contract. Combining ``T`` with ``P`` is rejected: transparency preserves the whole argument vector, argv[0] included. ``L`` - loader substitution Do not run the interpreter on the binary at all: load the binary itself as a fully native exec and substitute the interpreter for the loader named in the binary's ``PT_INTERP``. See the "Loader substitution" section below. ``L`` rejects ``T``, ``P``, ``O`` and ``C``; ``F`` composes. ``D`` - registered disabled The entry is created disabled instead of being matchable at once, and has to be enabled by writing ``1`` to its file before it dispatches anything. This splits a registration into creating the entry and activating it, leaving room to configure it in between - which is what a ``B`` entry that binds interpreters needs; see the bpf section below. The flag is spent on the registration and is not read back: what an entry file reports afterwards is whether it is enabled. h](j)}(h ``flags``h]h)}(hj[h]hflags}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjYubah}(h]h ]h"]h$]h&]uh1jhhhKwhjUubj)}(hhh](h)}(his an optional field that controls several aspects of the invocation of the interpreter. It is a string of capital letters, each controls a certain aspect. The following flags are supported:h]his an optional field that controls several aspects of the invocation of the interpreter. It is a string of capital letters, each controls a certain aspect. The following flags are supported:}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hjpubh block_quote)}(hX ``P`` - preserve-argv[0] Legacy behavior of binfmt_misc is to overwrite the original argv[0] with the full path to the binary. When this flag is included, binfmt_misc will add an argument to the argument vector for this purpose, thus preserving the original ``argv[0]``. e.g. If your interp is set to ``/bin/foo`` and you run ``blah`` (which is in ``/usr/local/bin``), then the kernel will execute ``/bin/foo`` with ``argv[]`` set to ``["/bin/foo", "/usr/local/bin/blah", "blah"]``. The interp has to be aware of this so it can execute ``/usr/local/bin/blah`` with ``argv[]`` set to ``["blah"]``. ``O`` - open-binary Legacy behavior of binfmt_misc is to pass the full path of the binary to the interpreter as an argument. When this flag is included, binfmt_misc will open the file for reading and pass its descriptor into the auxilary vector with the key "AT_EXECFD", thus allowing the interpreter to execute non-readable binaries. This feature should be used with care - the interpreter has to be trusted not to emit the contents of the non-readable binary. ``C`` - credentials Currently, the behavior of binfmt_misc is to calculate the credentials and security token of the new process according to the interpreter. When this flag is included, these attributes are calculated according to the binary. It also implies the ``O`` flag. This feature should be used with care as the interpreter will run with root permissions when a setuid binary owned by root is run with binfmt_misc. ``F`` - fix binary The usual behaviour of binfmt_misc is to spawn the binary lazily when the misc format file is invoked. However, this doesn't work very well in the face of mount namespaces and changeroots, so the ``F`` mode opens the binary as soon as the emulation is installed and uses the opened image to spawn the emulator, meaning it is always available once installed, regardless of how the environment changes. ``T`` - transparent Run the interpreter transparently. The binary is handed to the interpreter through ``AT_EXECFD`` (``T`` implies ``O``), the argument vector is left exactly as the caller built it and the kernel labels ``/proc/pid/exe`` with the binary instead of the interpreter. The interpreter has to load the binary from ``AT_EXECFD`` and follow the ``AT_FLAGS_TRANSPARENT_INTERP`` contract. Combining ``T`` with ``P`` is rejected: transparency preserves the whole argument vector, argv[0] included. ``L`` - loader substitution Do not run the interpreter on the binary at all: load the binary itself as a fully native exec and substitute the interpreter for the loader named in the binary's ``PT_INTERP``. See the "Loader substitution" section below. ``L`` rejects ``T``, ``P``, ``O`` and ``C``; ``F`` composes. ``D`` - registered disabled The entry is created disabled instead of being matchable at once, and has to be enabled by writing ``1`` to its file before it dispatches anything. This splits a registration into creating the entry and activating it, leaving room to configure it in between - which is what a ``B`` entry that binds interpreters needs; see the bpf section below. The flag is spent on the registration and is not read back: what an entry file reports afterwards is whether it is enabled. h]j)}(hhh](j)}(hXU``P`` - preserve-argv[0] Legacy behavior of binfmt_misc is to overwrite the original argv[0] with the full path to the binary. When this flag is included, binfmt_misc will add an argument to the argument vector for this purpose, thus preserving the original ``argv[0]``. e.g. If your interp is set to ``/bin/foo`` and you run ``blah`` (which is in ``/usr/local/bin``), then the kernel will execute ``/bin/foo`` with ``argv[]`` set to ``["/bin/foo", "/usr/local/bin/blah", "blah"]``. The interp has to be aware of this so it can execute ``/usr/local/bin/blah`` with ``argv[]`` set to ``["blah"]``.h](j)}(h``P`` - preserve-argv[0]h](h)}(h``P``h]hP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh - preserve-argv[0]}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1jhhhKChjubj)}(hhh]h)}(hX<Legacy behavior of binfmt_misc is to overwrite the original argv[0] with the full path to the binary. When this flag is included, binfmt_misc will add an argument to the argument vector for this purpose, thus preserving the original ``argv[0]``. e.g. If your interp is set to ``/bin/foo`` and you run ``blah`` (which is in ``/usr/local/bin``), then the kernel will execute ``/bin/foo`` with ``argv[]`` set to ``["/bin/foo", "/usr/local/bin/blah", "blah"]``. The interp has to be aware of this so it can execute ``/usr/local/bin/blah`` with ``argv[]`` set to ``["blah"]``.h](hLegacy behavior of binfmt_misc is to overwrite the original argv[0] with the full path to the binary. When this flag is included, binfmt_misc will add an argument to the argument vector for this purpose, thus preserving the original }(hjhhhNhNubh)}(h ``argv[0]``h]hargv[0]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh . e.g. If your interp is set to }(hjhhhNhNubh)}(h ``/bin/foo``h]h/bin/foo}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh and you run }(hjhhhNhNubh)}(h``blah``h]hblah}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh (which is in }(hjhhhNhNubh)}(h``/usr/local/bin``h]h/usr/local/bin}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh ), then the kernel will execute }(hjhhhNhNubh)}(h ``/bin/foo``h]h/bin/foo}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh with }(hjhhhNhNubh)}(h ``argv[]``h]hargv[]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh set to }(hjhhhNhNubh)}(h/``["/bin/foo", "/usr/local/bin/blah", "blah"]``h]h+["/bin/foo", "/usr/local/bin/blah", "blah"]}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh8. The interp has to be aware of this so it can execute }(hjhhhNhNubh)}(h``/usr/local/bin/blah``h]h/usr/local/bin/blah}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh with }(hjhhhNhNubh)}(h ``argv[]``h]hargv[]}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh set to }hjsbh)}(h ``["blah"]``h]h["blah"]}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK register echo ':i486:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register h](h)}(h@enable support for em86 (like binfmt_em86, for Alpha AXP only)::h]h?enable support for em86 (like binfmt_em86, for Alpha AXP only):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubj)}(hXmecho ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register echo ':i486:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > registerh]hXmecho ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register echo ':i486:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register}hj' sbah}(h]h ]h"]h$]h&]j-j.uh1jhhhKhj ubeh}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(henable support for packed DOS applications (pre-configured dosemu hdimages):: echo ':DEXE:M::\x0eDEX::/usr/bin/dosexec:' > register h](h)}(hMenable support for packed DOS applications (pre-configured dosemu hdimages)::h]hLenable support for packed DOS applications (pre-configured dosemu hdimages):}(hj? hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj; ubj)}(h5echo ':DEXE:M::\x0eDEX::/usr/bin/dosexec:' > registerh]h5echo ':DEXE:M::\x0eDEX::/usr/bin/dosexec:' > register}hjM sbah}(h]h ]h"]h$]h&]j-j.uh1jhhhKhj; ubeh}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hmenable support for Windows executables using wine:: echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > register h](h)}(h3enable support for Windows executables using wine::h]h2enable support for Windows executables using wine:}(hje hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhja ubj)}(h5echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > registerh]h5echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > register}hjs sbah}(h]h ]h"]h$]h&]j-j.uh1jhhhKhja ubeh}(h]h ]h"]h$]h&]uh1jhj hhhhhNubeh}(h]h ]h"]h$]h&]jijjuh1jhhhKhhhhubh)}(h7For java support see Documentation/admin-guide/java.rsth]h7For java support see Documentation/admin-guide/java.rst}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hYou can enable/disable binfmt_misc or one binary type by echoing 0 (to disable) or 1 (to enable) to ``/proc/sys/fs/binfmt_misc/status`` or ``/proc/.../the_name``. Catting the file tells you the current status of ``binfmt_misc/the_entry``.h](hdYou can enable/disable binfmt_misc or one binary type by echoing 0 (to disable) or 1 (to enable) to }(hj hhhNhNubh)}(h#``/proc/sys/fs/binfmt_misc/status``h]h/proc/sys/fs/binfmt_misc/status}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh or }(hj hhhNhNubh)}(h``/proc/.../the_name``h]h/proc/.../the_name}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh3. Catting the file tells you the current status of }(hj hhhNhNubh)}(h``binfmt_misc/the_entry``h]hbinfmt_misc/the_entry}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hYou can remove one entry or all entries by echoing -1 to ``/proc/.../the_name`` or ``/proc/sys/fs/binfmt_misc/status``. A single entry can also be removed by simply unlinking (``rm``) ``/proc/.../the_name``.h](h9You can remove one entry or all entries by echoing -1 to }(hj hhhNhNubh)}(h``/proc/.../the_name``h]h/proc/.../the_name}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh or }(hj hhhNhNubh)}(h#``/proc/sys/fs/binfmt_misc/status``h]h/proc/sys/fs/binfmt_misc/status}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh:. A single entry can also be removed by simply unlinking (}(hj hhhNhNubh)}(h``rm``h]hrm}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh) }(hj hhhNhNubh)}(h``/proc/.../the_name``h]h/proc/.../the_name}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hbpf-backed handlersh]hbpf-backed handlers}(hj8 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj5 hhhhhKubh)}(hXWith ``CONFIG_BINFMT_MISC_BPF`` both the matching and the interpreter selection can be delegated to bpf programs. A handler is an instance of the ``binfmt_misc_ops`` struct_ops with a ``match`` and a ``load`` program and a ``name``. Once the struct_ops map is registered the handler can be activated with a ``B`` entry that references it by name in the ``interpreter`` field and carries neither offset, magic, nor mask::h](hWith }(hjF hhhNhNubh)}(h``CONFIG_BINFMT_MISC_BPF``h]hCONFIG_BINFMT_MISC_BPF}(hjN hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubhs both the matching and the interpreter selection can be delegated to bpf programs. A handler is an instance of the }(hjF hhhNhNubh)}(h``binfmt_misc_ops``h]hbinfmt_misc_ops}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh struct_ops with a }(hjF hhhNhNubh)}(h ``match``h]hmatch}(hjr hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh and a }(hjF hhhNhNubh)}(h``load``h]hload}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh program and a }(hjF hhhNhNubh)}(h``name``h]hname}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubhL. Once the struct_ops map is registered the handler can be activated with a }(hjF hhhNhNubh)}(h``B``h]hB}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh) entry that references it by name in the }(hjF hhhNhNubh)}(h``interpreter``h]h interpreter}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh3 field and carries neither offset, magic, nor mask:}(hjF hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubj)}(h(echo ':qemu:B::::my_handler:' > registerh]h(echo ':qemu:B::::my_handler:' > register}hj sbah}(h]h ]h"]h$]h&]j-j.uh1jhhhKhj5 hhubh)}(hXBoth programs receive the ``linux_binprm`` of the binary and both can sleep. The ``match`` program decides whether the handler applies: it is consulted during the entry walk exactly like magic and extension matching, in the same registration order with the same first-match-wins semantics. Unlike static matching it is not limited to the prefetched first bytes of the file in ``bprm->buf``: it can read the file, e.g. to parse ELF program headers whose data sits at arbitrary offsets. It only decides, though: the selection kfuncs below are rejected in it. The ``load`` program of the matched handler then selects the interpreter: it can equally read the file and derive the interpreter from the binary's location. It selects the interpreter by calling the ``bpf_binprm_set_interp()`` kfunc with an absolute path and returning ``0``. A match is committed: a failing ``load`` fails the exec with its error instead of falling through to later entries; ``-ENOEXEC`` lets the remaining binary formats have a go. A path selected this way is opened with the credentials of the task doing the exec, exactly as a statically registered interpreter without ``F`` would be.h](hBoth programs receive the }(hj hhhNhNubh)}(h``linux_binprm``h]h linux_binprm}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh' of the binary and both can sleep. The }(hj hhhNhNubh)}(h ``match``h]hmatch}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhX program decides whether the handler applies: it is consulted during the entry walk exactly like magic and extension matching, in the same registration order with the same first-match-wins semantics. Unlike static matching it is not limited to the prefetched first bytes of the file in }(hj hhhNhNubh)}(h ``bprm->buf``h]h bprm->buf}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh: it can read the file, e.g. to parse ELF program headers whose data sits at arbitrary offsets. It only decides, though: the selection kfuncs below are rejected in it. The }(hj hhhNhNubh)}(h``load``h]hload}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh program of the matched handler then selects the interpreter: it can equally read the file and derive the interpreter from the binary’s location. It selects the interpreter by calling the }(hj hhhNhNubh)}(h``bpf_binprm_set_interp()``h]hbpf_binprm_set_interp()}(hj0 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh+ kfunc with an absolute path and returning }(hj hhhNhNubh)}(h``0``h]h0}(hjB hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh". A match is committed: a failing }(hj hhhNhNubh)}(h``load``h]hload}(hjT hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhL fails the exec with its error instead of falling through to later entries; }(hj hhhNhNubh)}(h ``-ENOEXEC``h]h-ENOEXEC}(hjf hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh lets the remaining binary formats have a go. A path selected this way is opened with the credentials of the task doing the exec, exactly as a statically registered interpreter without }(hj hhhNhNubh)}(h``F``h]hF}(hjx hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh would be.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubh)}(hAn entry can instead bind the interpreters its handler may use, so that no path is resolved at exec time at all. An entry registered with ``D`` is not matchable yet, which is what leaves it open to being given them, one ``+name path`` write at a time::h](hAn entry can instead bind the interpreters its handler may use, so that no path is resolved at exec time at all. An entry registered with }(hj hhhNhNubh)}(h``D``h]hD}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhM is not matchable yet, which is what leaves it open to being given them, one }(hj hhhNhNubh)}(h``+name path``h]h +name path}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh write at a time:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubj)}(hecho ':qemu:B::::my_handler:D' > register echo '+aarch64 /usr/bin/qemu-aarch64' > qemu echo '+arm /usr/bin/qemu-arm' > qemu echo 1 > qemuh]hecho ':qemu:B::::my_handler:D' > register echo '+aarch64 /usr/bin/qemu-aarch64' > qemu echo '+arm /usr/bin/qemu-arm' > qemu echo 1 > qemu}hj sbah}(h]h ]h"]h$]h&]j-j.uh1jhhhKhj5 hhubh)}(hXEach path is opened during its write, in the writing process's context and with the credentials the entry file was opened with, exactly the way ``F`` pre-opens a static entry's interpreter; the paths must be absolute. The path is everything past the first space, so there is nothing it cannot express, and no interpreter has to fit in a register string. An entry binds at most 100 interpreters, and each one is charged against ``max_binfmt_misc_interpreters`` like any other binding. A write past either limit is refused with ``-ENOSPC``.h](hEach path is opened during its write, in the writing process’s context and with the credentials the entry file was opened with, exactly the way }(hj hhhNhNubh)}(h``F``h]hF}(hj hhhNhNubah}(h]h ]h"]h$^]h&]uh1hhj ubhX pre-opens a static entry’s interpreter; the paths must be absolute. The path is everything past the first space, so there is nothing it cannot express, and no interpreter has to fit in a register string. An entry binds at most 100 interpreters, and each one is charged against }(hj hhhNhNubh)}(h ``max_binfmt_misc_interpreters``h]hmax_binfmt_misc_interpreters}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhC like any other binding. A write past either limit is refused with }(hj hhhNhNubh)}(h ``-ENOSPC``h]h-ENOSPC}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubh)}(hXuThe ``load`` program then selects one per exec by name with the ``bpf_binprm_select_interp()`` kfunc, and every exec runs a clone of the file that was opened. The path decides which file is bound and nothing else: it is not resolved again, in any namespace, so what it holds later - or what it holds in the namespace of whoever runs the binary - no longer decides anything.h](hThe }(hj hhhNhNubh)}(h``load``h]hload}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh4 program then selects one per exec by name with the }(hj hhhNhNubh)}(h``bpf_binprm_select_interp()``h]hbpf_binprm_select_interp()}(hj. hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhX kfunc, and every exec runs a clone of the file that was opened. The path decides which file is bound and nothing else: it is not resolved again, in any namespace, so what it holds later - or what it holds in the namespace of whoever runs the binary - no longer decides anything.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubh)}(hX~Enabling the entry ends this. Its interpreters are read at exec time with nothing but a reference held on the entry, so an entry that has ever been matchable can never have its set changed again: the first ``1`` seals it, from then on ``+`` is refused with ``-EBUSY``, and an entry registered without ``D`` is sealed from the start. Binding a name twice is refused with ``-EEXIST``.h](hEnabling the entry ends this. Its interpreters are read at exec time with nothing but a reference held on the entry, so an entry that has ever been matchable can never have its set changed again: the first }(hjF hhhNhNubh)}(h``1``h]h1}(hjN hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh seals it, from then on }(hjF hhhNhNubh)}(h``+``h]h+}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh is refused with }(hjF hhhNhNubh)}(h ``-EBUSY``h]h-EBUSY}(hjr hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh", and an entry registered without }(hjF hhhNhNubh)}(h``D``h]hD}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh@ is sealed from the start. Binding a name twice is refused with }(hjF hhhNhNubh)}(h ``-EEXIST``h]h-EEXIST}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF ubh.}(hjF hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubh)}(hXSelection is by name so that the configuration and the program need not agree on an order, and so that a handler is not tied to where a distribution puts its interpreters. A name is a single word of printable ASCII, at most 32 characters; a name the entry did not bind gives the program ``-ENOENT``, which it can act on or return. The interpreter runs under the path it was registered under, and the entry reports what it bound::h](hXSelection is by name so that the configuration and the program need not agree on an order, and so that a handler is not tied to where a distribution puts its interpreters. A name is a single word of printable ASCII, at most 32 characters; a name the entry did not bind gives the program }(hj hhhNhNubh)}(h ``-ENOENT``h]h-ENOENT}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh, which it can act on or return. The interpreter runs under the path it was registered under, and the entry reports what it bound:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubj)}(h$ cat /proc/sys/fs/binfmt_misc/qemu enabled bpf my_handler bpf-interpreter aarch64 /usr/bin/qemu-aarch64 bpf-interpreter arm /usr/bin/qemu-arm flags:h]h$ cat /proc/sys/fs/binfmt_misc/qemu enabled bpf my_handler bpf-interpreter aarch64 /usr/bin/qemu-aarch64 bpf-interpreter arm /usr/bin/qemu-arm flags:}hj sbah}(h]h ]h"]h$]h&]j-j.uh1jhhhKhj5 hhubh)}(hThe path reported is the one the interpreter was bound under, which named the file at that moment; it is not re-resolved, so it is a record of what was bound rather than a promise about what that path holds now.h]hThe path reported is the one the interpreter was bound under, which named the file at that moment; it is not re-resolved, so it is a record of what was bound rather than a promise about what that path holds now.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj5 hhubh)}(hXkThe ``load`` program can also pass a single argument to the interpreter with the ``bpf_binprm_set_interp_arg()`` kfunc. It is inserted between the interpreter and the binary, exactly like the optional argument of a ``#!`` interpreter line, e.g. for a handler that resolves ``$ORIGIN`` in a script's ``#!`` path and needs to preserve the argument that followed it.h](hThe }(hj hhhNhNubh)}(h``load``h]hload}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhE program can also pass a single argument to the interpreter with the }(hj hhhNhNubh)}(h``bpf_binprm_set_interp_arg()``h]hbpf_binprm_set_interp_arg()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhg kfunc. It is inserted between the interpreter and the binary, exactly like the optional argument of a }(hj hhhNhNubh)}(h``#!``h]h#!}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh4 interpreter line, e.g. for a handler that resolves }(hj hhhNhNubh)}(h ``$ORIGIN``h]h$ORIGIN}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh in a script’s }(hj hhhNhNubh)}(h``#!``h]h#!}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh: path and needs to preserve the argument that followed it.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj5 hhubh)}(hXThe invocation flags a static entry fixes at registration - ``P``, ``C``, ``O``, ``T`` and ``L`` - are per-exec choices for a bpf handler, made by the ``load`` program with the ``bpf_binprm_set_flags()`` kfunc, so a single handler can decide them differently for each binary it handles:h](hWith the ``T`` flag or ``BPF_BINPRM_TRANSPARENT`` the dispatch is invisible to the resulting process. The argument vector is left exactly as the caller built it. The binary is passed through ``AT_EXECFD``. The kernel also labels ``/proc/pid/exe`` correctly. The binary's file is write-denied while the process runs and the interpreter's is not, exactly as if the binary had been executed directly. A transparent entry does not change how credentials are derived. As with any other entry, set*id bits of the binary are only honored with ``C`` (or ``BPF_BINPRM_CREDENTIALS``).h](h With the }(hjfhhhNhNubh)}(h``T``h]hT}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh flag or }(hjfhhhNhNubh)}(h``BPF_BINPRM_TRANSPARENT``h]hBPF_BINPRM_TRANSPARENT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh the dispatch is invisible to the resulting process. The argument vector is left exactly as the caller built it. The binary is passed through }(hjfhhhNhNubh)}(h ``AT_EXECFD``h]h AT_EXECFD}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh. The kernel also labels }(hjfhhhNhNubh)}(h``/proc/pid/exe``h]h /proc/pid/exe}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubhX& correctly. The binary’s file is write-denied while the process runs and the interpreter’s is not, exactly as if the binary had been executed directly. A transparent entry does not change how credentials are derived. As with any other entry, set*id bits of the binary are only honored with }(hjfhhhNhNubh)}(h``C``h]hC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh (or }(hjfhhhNhNubh)}(h``BPF_BINPRM_CREDENTIALS``h]hBPF_BINPRM_CREDENTIALS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh).}(hjfhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM5hjUhhubh)}(hX&The interpreter has to be built for this contract. The kernel announces it with ``AT_FLAGS_TRANSPARENT_INTERP`` in the ``AT_FLAGS`` aux vector entry next to ``AT_EXECFD``. The argument vector belongs entirely to the program, nothing was spliced in, so the interpreter doesn't consume arguments and simply loads the program from the descriptor. The bit is also the loader's license to finish the identity. After mapping the program it may retarget the ``AT_PHDR``/``AT_ENTRY``/``AT_BASE`` entries of ``/proc/pid/auxv`` and the code/data statistics markers via one ``PR_SET_MM_MAP`` which completes what attaching debuggers observe. What remains visibly different from a direct execution is the address space layout. The interpreter occupies the main-image position and the program lives in the mmap region.h](hPThe interpreter has to be built for this contract. The kernel announces it with }(hjhhhNhNubh)}(h``AT_FLAGS_TRANSPARENT_INTERP``h]hAT_FLAGS_TRANSPARENT_INTERP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh in the }(hjhhhNhNubh)}(h ``AT_FLAGS``h]hAT_FLAGS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh aux vector entry next to }(hjhhhNhNubh)}(h ``AT_EXECFD``h]h AT_EXECFD}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhX. The argument vector belongs entirely to the program, nothing was spliced in, so the interpreter doesn’t consume arguments and simply loads the program from the descriptor. The bit is also the loader’s license to finish the identity. After mapping the program it may retarget the }(hjhhhNhNubh)}(h ``AT_PHDR``h]hAT_PHDR}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh/}(hjhhhNhNubh)}(h ``AT_ENTRY``h]hAT_ENTRY}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh/}hjsbh)}(h ``AT_BASE``h]hAT_BASE}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh entries of }(hjhhhNhNubh)}(h``/proc/pid/auxv``h]h/proc/pid/auxv}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh. and the code/data statistics markers via one }(hjhhhNhNubh)}(h``PR_SET_MM_MAP``h]h PR_SET_MM_MAP}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh which completes what attaching debuggers observe. What remains visibly different from a direct execution is the address space layout. The interpreter occupies the main-image position and the program lives in the mmap region.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM?hjUhhubeh}(h]transparent-interpretersah ]h"]transparent interpretersah$]h&]uh1hhhhhhhhM3ubh)}(hhh](h)}(hLoader substitutionh]hLoader substitution}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMMubh)}(hXThe ``L`` flag turns the execution model around. Instead of running the registered interpreter with the binary as its payload the kernel loads the matched binary itself as the main image and substitutes the registered interpreter for the loader named in the binary's ``PT_INTERP``.h](hThe }(hjhhhNhNubh)}(h``L``h]hL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhX flag turns the execution model around. Instead of running the registered interpreter with the binary as its payload the kernel loads the matched binary itself as the main image and substitutes the registered interpreter for the loader named in the binary’s }(hjhhhNhNubh)}(h ``PT_INTERP``h]h PT_INTERP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMOhjhhubh)}(hXBecause the exec is native, there is no dispatch identity to reconstruct and no contract the substitute has to implement. A stock dynamic loader works unchanged. The argument vector is untouched, credentials and ``AT_SECURE`` derive from the binary, there is no ``AT_EXECFD`` and no marker in the aux vector, the binary sits in the main-image slot with the native brk placement so ``/proc/pid/maps``, core dumps and perf mmap records have the native shape, and the identity is already complete when ``PTRACE_EVENT_EXEC`` stops the tracee. So launching under a debugger works, not just attaching. ``L`` entries are for ELF binaries of a native architecture. Foreign-arch emulation and non-ELF payloads remain the domain of the classic and transparent modes.h](hBecause the exec is native, there is no dispatch identity to reconstruct and no contract the substitute has to implement. A stock dynamic loader works unchanged. The argument vector is untouched, credentials and }(hjhhhNhNubh)}(h ``AT_SECURE``h]h AT_SECURE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh% derive from the binary, there is no }(hjhhhNhNubh)}(h ``AT_EXECFD``h]h AT_EXECFD}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhj and no marker in the aux vector, the binary sits in the main-image slot with the native brk placement so }(hjhhhNhNubh)}(h``/proc/pid/maps``h]h/proc/pid/maps}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhd, core dumps and perf mmap records have the native shape, and the identity is already complete when }(hjhhhNhNubh)}(h``PTRACE_EVENT_EXEC``h]hPTRACE_EVENT_EXEC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhL stops the tracee. So launching under a debugger works, not just attaching. }(hjhhhNhNubh)}(h``L``h]hL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh entries are for ELF binaries of a native architecture. Foreign-arch emulation and non-ELF payloads remain the domain of the classic and transparent modes.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMThjhhubh)}(hXnThe override applies when the format that finally claims the file is ELF with a ``PT_INTERP``. A matched binary without one or an interpreter-less ``ET_DYN`` drops the override and runs natively. A file claimed by another format - a ``#!`` script, say - is handled by that format as if the entry had not matched. ``L`` is therefore not an enforcement mechanism: it decides how a binary that asks for a loader is run, it does not guarantee that everything matching the entry runs under the substitute. A format that cannot consume the override at all instead refuses the exec with ``ENOEXEC`` before the point of no return.h](hPThe override applies when the format that finally claims the file is ELF with a }(hj1hhhNhNubh)}(h ``PT_INTERP``h]h PT_INTERP}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1ubh6. A matched binary without one or an interpreter-less }(hj1hhhNhNubh)}(h ``ET_DYN``h]hET_DYN}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1ubhL drops the override and runs natively. A file claimed by another format - a }(hj1hhhNhNubh)}(h``#!``h]h#!}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1ubhJ script, say - is handled by that format as if the entry had not matched. }(hj1hhhNhNubh)}(h``L``h]hL}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1ubhX is therefore not an enforcement mechanism: it decides how a binary that asks for a loader is run, it does not guarantee that everything matching the entry runs under the substitute. A format that cannot consume the override at all instead refuses the exec with }(hj1hhhNhNubh)}(h ``ENOEXEC``h]hENOEXEC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1ubh before the point of no return.}(hj1hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMahjhhubh)}(hX%A wrong-architecture ELF fails the whole exec with ``ENOEXEC`` exactly as if no entry had matched. A substitute that is not ELF of the right architecture fails with ``ELIBBAD``. The usual ``PT_INTERP`` sanity checks on the binary still apply. But the segment's content is otherwise irrelevant.h](h3A wrong-architecture ELF fails the whole exec with }(hjhhhNhNubh)}(h ``ENOEXEC``h]hENOEXEC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhg exactly as if no entry had matched. A substitute that is not ELF of the right architecture fails with }(hjhhhNhNubh)}(h ``ELIBBAD``h]hELIBBAD}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh . The usual }(hjhhhNhNubh)}(h ``PT_INTERP``h]h PT_INTERP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh^ sanity checks on the binary still apply. But the segment’s content is otherwise irrelevant.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMkhjhhubh)}(hX``L`` rejects the classic-dispatch flags ``T``, ``P``, ``O`` and ``C`` at registration. ``F`` composes and is valuable: with it the substitute is opened at registration time, so later mount namespace or path changes cannot redirect it. Without it the substitute is opened when the binary is executed, and the path is resolved in the mount namespace and root of whoever runs the binary, which is why it has to be absolute. As with ``C``, register only trusted interpreters. The substituted loader runs with credentials derived from the binary.h](h)}(h``L``h]hL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh$ rejects the classic-dispatch flags }(hjhhhNhNubh)}(h``T``h]hT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh, }(hjhhhNhNubh)}(h``P``h]hP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh, }hjsbh)}(h``O``h]hO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh and }(hjhhhNhNubh)}(h``C``h]hC}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh at registration. }(hjhhhNhNubh)}(h``F``h]hF}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhXQ composes and is valuable: with it the substitute is opened at registration time, so later mount namespace or path changes cannot redirect it. Without it the substitute is opened when the binary is executed, and the path is resolved in the mount namespace and root of whoever runs the binary, which is why it has to be absolute. As with }(hjhhhNhNubh)}(h``C``h]hC}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhk, register only trusted interpreters. The substituted loader runs with credentials derived from the binary.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMqhjhhubeh}(h]loader-substitutionah ]h"]loader substitutionah$]h&]uh1hhhhhhhhMMubh)}(hhh](h)}(hHintsh]hHints}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhjmhhhhhM|ubh)}(hIf you want to pass special arguments to your interpreter, you can write a wrapper script for it. See :doc:`Documentation/admin-guide/java.rst <./java>` for an example.h](hfIf you want to pass special arguments to your interpreter, you can write a wrapper script for it. See }(hj~hhhNhNubh)}(h2:doc:`Documentation/admin-guide/java.rst <./java>`h]hinline)}(hjh]h"Documentation/admin-guide/java.rst}(hjhhhNhNubah}(h]h ](xrefstdstd-doceh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocadmin-guide/binfmt-misc refdomainjreftypedoc refexplicitrefwarn reftarget./javauh1hhhhM~hj~ubh for an example.}(hj~hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM~hjmhhubh)}(hYour interpreter should NOT look in the PATH for the filename; the kernel passes it the full filename (or the file descriptor) to use. Using ``$PATH`` can cause unexpected behaviour and can be a security hazard.h](hYour interpreter should NOT look in the PATH for the filename; the kernel passes it the full filename (or the file descriptor) to use. Using }(hjhhhNhNubh)}(h ``$PATH``h]h$PATH}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh= can cause unexpected behaviour and can be a security hazard.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjmhhubh)}(h6Richard Günther h](hRichard Günther <}(hjhhhNhNubh reference)}(h#rguenth@tat.physik.uni-tuebingen.deh]h#rguenth@tat.physik.uni-tuebingen.de}(hjhhhNhNubah}(h]h ]h"]h$]h&]refuri*mailto:rguenth@tat.physik.uni-tuebingen.deuh1jhjubh>}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjmhhubeh}(h]hintsah ]h"]hintsah$]h&]uh1hhhhhhhhM|ubeh}(h];kernel-support-for-miscellaneous-binary-formats-binfmt-miscah ]h"]=kernel support for miscellaneous binary formats (binfmt_misc)ah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj,error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehʌ _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjjRjOjjjjjgjju nametypes}(jjRjjjjuh}(jhjOj5 jjUjgjjjmu footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.