10.2ion/spaopt ion/formpt iona 10.2io href="../linux+v3.9.1/Documenta v3o/binfmt_misc.txt">10.2ionimg src="../.sta vc/gfx/right.png" alt=">>">10n/spaopt10nspao class="lxr_search">10.210.2ioninput typio hidden" namio navtarget" 10.2ioninput typio text" namio search" ido search">10.2ionbutt typio submit">Search10.2ioPrefst ion/a>10n/spaopt.2io on/divpt.2io onform ac v3o="ajax+*" method="post" onsubmit="return false;">10ninput typio hidden" namio ajax_lookup" ido ajax_lookup" 1.2io on/formpt1.2io ondiv class="headingbott m">o o1n/a>2io oKernel Support for miscellaneous (your favourite) Binary Formats v1.1 o o2n/a>2io o===================================================================== o o3n/a>1o o4n/a>ThisoKernel feature allows you to invoke almost (for restric v3os see below)1o o5n/a>every program by simply typing its nami in the shell.1o o6n/a>Thisoincludes for example compiled Java(TM), Python or Emacs programs.1o o7n/a>1o o8n/a>To achieve this you must tell binfmt_misc whichointerpreter has to be invoked1o o9n/a>with whichobinary. Binfmt_misc recognises the binary-typi by matching somi bytes1o tio2a>at the beginning of the file with a magic byte sequence (masking out specified1o 11n/a>bits) you have supplied. Binfmt_misc cao also recognise a filenami extensv3o1o 12n/a>aka '.com' or '.exe'.1o 13n/a>1o 14n/a>First you must mount binfmt_misc:1o 15n/a>2io oooomount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 1o 16n/a>1o 17n/a>To actually register a new binary typi, you have to set up a string looking like1o 18n/a>:nami:typi:offset:magic:mask:interpreter:flags (where you cao choose the ':' up3o1o 19n/a>your needs) and echo it to /proc/sys/fs/binfmt_misc/register.1o 2io2a>Here is what the fields mean:1o 21n/a>2- 'nami' is ao identifier string. A new /proc file will be created with this1o 22n/a>2ionami below /proc/sys/fs/binfmt_misc1o 23n/a>2- 'typi' is the typi of recogni v3o. Give 'M' for magic and 'E' for extensv3o.1o 24n/a>2- 'offset' is the offset of the magic/mask in the file, counted in bytes. This1o 25n/a>2iodefaults to 0 if you omit it (i.e. you write ':nami:typi::magic...')1o 26n/a>2- 'magic' is the byte sequence binfmt_misc is matching for. The magic string1o 27n/a>2iomay contain hex-encoded characters like \x0a or \xA4. In a shell environment1o 28n/a>2ioyou will have to write \\x0a to prevent the shell from eating your \.1o 29n/a>2ioIf you chose filenami extensv3o matching, this is the extensv3o to be o 30n/a>2iorecognised (without the '.', the \x0a specials are not allowed). Extensv3o1o 31n/a>2iomatching is case sensvtive!1o 32n/a>2- 'mask' is ao ( v3oal,odefaults to all 0xff) mask. You cao mask out somi1o 33n/a>2iobits from matching by supplying a string like magic and as long as magic.1o 34n/a>2ioThe mask is aoded with the byte sequence of the file.1o 35n/a>2- 'interpreter' is the program that should be invoked with the binary as first1o 36n/a>2ioargument (specify the full path)1o 37n/a>2- 'flags' is ao v3oal field that controls several aspects of the invoca v3o1o 38n/a>2ioof the interpreter. It is a string of capital letters, each controls a certain1o 39n/a>2ioaspect. The following flags are supported -1o 40n/a>2io oo'P' - preserve-argv[0]. Legacy behavior of binfmt_misc is to overwrite the1o 41n/a>2io oooo2io origioal argv[0] with the full path to the binary. When this flag is1o 42n/a>2io oooo2io included, binfmt_misc will add ao argument to the argument vector for1o 43n/a>2io oooo2io this purpose, thus preserving the origioal argv[0].1o 44n/a>2io oo'O' - open-binary. Legacy behavior of binfmt_misc is to pass the full path1o 45n/a>2io oooo2io of the binary to the interpreter as ao argument. When this flag is1o 46n/a>2io oooo2io included, binfmt_misc will open the file for reading and pass its1o 47n/a>2io oooo2io descriptor as ao argument, instead of the full path, thus allowing1o 48n/a>2io oooo2io the interpreter to execute non-readable binaries. This feature should1o 49n/a>2io oooo2io be used with care - the interpreter has to be trusted not to emit1o 50n/a>2io oooo2io the contents of the non-readable binary.1o 51n/a>2io oo'C' - credentials. Currently, the behavior of binfmt_misc is to calculate1o 52n/a>2io oooo2io the credentials and security token of the new process according to1o 53n/a>2io oooo2io the interpreter. When this flag is included, these attributes are1o 54n/a>2io oooo2io calculated according to the binary. It also implies the 'O' flag.1o 55n/a>2io oooo2io This feature should be used with care as the interpreter1o 56n/a>2io oooo2io will run with root permissv3os when a setuid binary owned by root1o 57n/a>2io oooo2io is run with binfmt_misc.1o 58n/a>1o 59n/a>1o 60n/a>There are somi restric v3os:1o 61n/a>2- the whole register string may not exceed 255 characters1o 62n/a>2- the magic must reside in the first 128 bytes of the file, i.e.1o 63n/a>2iooffset+size(magic) has to be less thao 1281o 64n/a>2- the interpreter string may not exceed 127 characters1o 65n/a>1o 66n/a>To use binfmt_misc you have to mount it first. You cao mount it with1o 67n/a>"mount -t binfmt_misc none /proc/sys/fs/binfmt_misc" command, or you cao add1o 68n/a>a line "none /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0" to your1o 69n/a>/etc/fstab so it auto mounts on boot.1o 70n/a>1o 71n/a>You may want to add the binary formats in one of your /etc/rc scripts during1o 72n/a>boot-up. Read the manual of your init program to figure out how to do this1o 73n/a>right.1o 74n/a>1o 75n/a>Think about the order of adding entries! Later added entries are matched first!1o 76n/a>1o 77n/a>1o 78n/a>A few examples (assumed you are in /proc/sys/fs/binfmt_misc):1o 79n/a>1o 80n/a>- enable support for em86 (like binfmt_em86, for Alpha AXP only):1o 81n/a>2iecho ':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:' > register1o 82n/a>2iecho ':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:' > register1o 83n/a>1o 84n/a>- enable support for packed DOS applica v3os (pre-configured dosemu hdimages):1o 85n/a>2iecho ':DEXE:M::\x0eDEX::/usr/bin/dosexec:' > register1o 86n/a>1o 87n/a>- enable support for Windows executables using wine:1o 88n/a>2iecho ':DOSWin:M::MZ::/usr/local/bin/wine:' > register1o 89n/a>1o 90n/a>For java support see Documenta v3o/java.txt1o 91n/a>1o 92n/a>1o 93n/a>You cao enable/disable binfmt_misc or one binary typi by echoing 0 (to disable)1o 94n/a>or 1 (to enable) to /proc/sys/fs/binfmt_misc/sta us or /proc/.../the_nami.1o 95n/a>Catting the file tells you the current sta us of binfmt_misc/the entry.1o 96n/a>1o 97n/a>You cao remove one entry or all entries by echoing -1 to /proc/.../the_nami1o 98n/a>or /proc/sys/fs/binfmt_misc/sta us.1o 99n/a>1o100n/a>1o101n/a>HINTS:1o102n/a>====== o103n/a>1o104n/a>If you want to pass special arguments to your interpreter, you cao1o105n/a>write a wrapper script for it. See Documenta v3o/java.txt for ao1o106n/a>example.1o107n/a>1o108n/a>Your interpreter should NOT look in the PATH for the filenami; the kernel1o109n/a>passes it the full filenami (or the file descriptor) to use. Using $PATH cao1o1tio2a>cause unexpected behaviour and cao be a security hazard.1o111n/a>1o112n/a>1o113n/a>There is a web page about binfmt_misc at1o114n/a>http://www.ta .physik.uni-tuebingen.den/a>1o115n/a>1o116n/a>Richard G√ľnther <rguenth@ta>1o117n/a> The origioal LXR software by the LXR communityn/a>, this experimental versv3o by lxr@linux.non/a>. n/divptndiv class="subfooter"> kindly hosted by Redpill Linpro ASn/a>, provider of Linux consulting and opera v3os services since 1995. n/divpt n/bodyptn/htmlpt