Debian Codegraph @

man/update-binfmts.man8

raw
1 .\" update-binfmts.8
2 .Dd January 24, 2011
3 .Os Debian
4 .ds volume-operating-system Debian
5 .Dt UPDATE\-BINFMTS 8
6 .Sh NAME
7 .Nm update\-binfmts
8 .Nd maintain registry of executable binary formats
9 .Sh SYNOPSIS
10 .Nm
11 .Op Ar options
12 .Fl Fl install
13 .Ar name path spec
14 .br
15 .Nm
16 .Op Ar options
17 .Fl Fl remove
18 .Ar name path
19 .br
20 .Nm
21 .Op Ar options
22 .Fl Fl import
23 .Op Ar name
24 .br
25 .Nm
26 .Op Ar options
27 .Fl Fl unimport
28 .Op Ar name
29 .br
30 .Nm
31 .Op Ar options
32 .Fl Fl display
33 .Op Ar name
34 .br
35 .Nm
36 .Op Ar options
37 .Fl Fl enable
38 .Op Ar name
39 .br
40 .Nm
41 .Op Ar options
42 .Fl Fl disable
43 .Op Ar name
44 .br
45 .Nm
46 .Op Ar options
47 .Fl Fl find
48 .Op Ar path
49 .Sh DESCRIPTION
50 Versions 2.1.43 and later of the Linux kernel have contained the binfmt_misc
51 module.
52 This enables a system administrator to register interpreters for various
53 binary formats based on a magic number or their file extension, and cause
54 the appropriate interpreter to be invoked whenever a matching file is
55 executed.
56 Think of it as a more flexible version of the #! executable interpreter
57 mechanism, or as something which can behave a little like "associations" in
58 certain other operating systems (though in GNU/Linux the tendency is to keep
59 this sort of thing somewhere else, like your file manager).
60 .Nm
61 manages a persistent database of these interpreters.
62 .Pp
63 When each package providing a registered interpreter is installed, changed,
64 or removed,
65 .Nm
66 is called to update information about that interpreter.
67 .Nm
68 is usually called from the
69 .Pa postinst
70 or
71 .Pa prerm
72 scripts in Debian packages.
73 .Sh OPTIONS
74 Exactly one action must be specified; this may be accompanied by any one of
75 the common options.
76 .Ss COMMON OPTIONS
77 .Bl -tag -width 4n
78 .It Fl Fl package Ar package-name
79 Specifies the name of the current package, to be used by package
80 post-installation and pre-removal scripts.
81 System administrators installing binary formats for local use should
82 probably ignore this option.
83 .Pp
84 When installing new formats, the
85 .Fl Fl import
86 action should be used instead.
87 Similarly, when removing old formats, the
88 .Fl Fl unimport
89 action should be used instead.
90 .It Fl Fl admindir Ar directory
91 Specifies the administrative directory, when this is to be different from
92 the default of
93 .Pa %admindir% .
94 .It Fl Fl importdir Ar directory
95 Specifies the directory from which packaged binary formats are imported,
96 when this is to be different from the default of
97 .Pa %importdir% .
98 .It Fl Fl test
99 Don't do anything, just demonstrate what would be done.
100 .It Fl Fl help
101 Display some usage information.
102 .It Fl Fl version
103 Display version information.
104 .El
105 .Ss ACTIONS
106 .Bl -tag -width 4n
107 .It Fl Fl install Ar name path spec
108 Install a binary format identified by
109 .Ar name
110 with interpreter
111 .Ar path
112 into the database.
113 After registration, this format will be used when the kernel tries to
114 execute a file matching
115 .Ar spec
116 (see
117 .Sx BINARY FORMAT SPECIFICATIONS
118 below).
119 .Pp
120 .Fl Fl install
121 will attempt to enable this binary format in the kernel as well as adding it
122 to its own database; see
123 .Fl Fl enable
124 below.
125 .Pp
126 You cannot install a format with any of the names ".", "..", "register", or
127 "status", as these are used by the filesystem or the binfmt_misc module.
128 .It Fl Fl remove Ar name path
129 Remove the binary format identified by
130 .Ar name
131 with interpreter
132 .Ar path
133 from the database.
134 This will also attempt to disable the binary format in the kernel; see
135 .Fl Fl disable
136 below.
137 .It Fl Fl import Op Ar name
138 Import a packaged format file called
139 .Ar name ,
140 or import all format files currently on the system if no
141 .Ar name
142 is given.
143 If
144 .Ar name
145 is not a full path, it is assumed to be a file in the import directory
146 .Pf ( Pa %importdir%
147 by default).
148 See
149 .Sx FORMAT FILES
150 below for the required contents of these files.
151 .Pp
152 For packages, this is preferable to using the
153 .Fl Fl install
154 option, as a format file can be installed without
155 .Nm
156 needing to be available.
157 .It Fl Fl unimport Op Ar name
158 Unimport a packaged format file called
159 .Ar name ,
160 or unimport all format files currently on the system if no
161 .Ar name
162 is given.
163 If
164 .Ar name
165 is not a full path, it is assumed to be a file in the import directory
166 .Pf ( Pa %importdir%
167 by default).
168 See
169 .Sx FORMAT FILES
170 below for the required contents of these files.
171 .Pp
172 For packages, this is preferable to using the
173 .Fl Fl remove
174 option, for symmetry with
175 .Fl Fl import .
176 .It Fl Fl display Op Ar name
177 Display any information held in the database about the binary format
178 identifier
179 .Ar name ,
180 or about all known binary formats if no
181 .Ar name
182 is given.
183 Also show whether displayed binary formats are enabled or disabled.
184 .It Fl Fl enable Op Ar name
185 Enable binary format
186 .Ar name ,
187 or all known binary formats if no
188 .Ar name
189 is given, in the kernel, thus enabling direct execution of matching files.
190 You must have binfmt_misc compiled into the kernel or loaded as a module for
191 this to work.
192 .It Fl Fl disable Op Ar name
193 Disable binary format
194 .Ar name ,
195 or all known binary formats if no
196 .Ar name
197 is given, in the kernel, thus disabling direct execution of matching files.
198 You must have binfmt_misc compiled into the kernel or loaded as a module for
199 this to work.
200 .It Fl Fl find Op Ar path
201 Print the list of interpreters that will be tried in sequence when
202 attempting to execute
203 .Ar path ,
204 one per line.
205 The first one for which
206 .Xr execvp 3
207 succeeds will be used.
208 .Pp
209 Note that if multiple formats match an executable, then the order is in
210 general not defined, and may not be preserved between
211 .Nm
212 operations, so you should generally try to ensure that this option prints at
213 most one line for any given
214 .Ar path .
215 The exception to this is that any format with a userspace detector will be
216 run before any format without a userspace detector.
217 .El
218 .Ss BINARY FORMAT SPECIFICATIONS
219 .Bl -tag -width 4n
220 .It Fl Fl magic Ar byte-sequence
221 This matches all files with the magic number
222 .Ar byte-sequence .
223 Hexadecimal escapes may be included in the
224 .Ar byte-sequence
225 by preceding them with \ex, for example
226 .Sq \ex0a
227 for a linefeed.
228 Remember to protect such escapes with quotes or an additional backslash to
229 prevent their interpretation by the shell.
230 .Pp
231 Also see
232 .Fl Fl offset
233 and
234 .Fl Fl mask .
235 .It Fl Fl offset Ar offset
236 This is the offset of the magic/mask in the file, counted in bytes.
237 The default is 0.
238 Only valid with
239 .Fl Fl magic .
240 .It Fl Fl mask Ar byte-sequence
241 This mask will be logically-ANDed with the string to be checked against the
242 magic number given with
243 .Fl Fl magic .
244 The default is all 0xff, i.e. no effect.
245 Only valid with
246 .Fl Fl magic .
247 .It Fl Fl extension Ar extension
248 This matches all files whose names end in
249 .Qq Pf . Ar extension .
250 Hexadecimal escapes are not recognized here.
251 Extension matching is case-sensitive.
252 .It Fl Fl detector Ar path
253 If this option is used, a userspace detector program will be used to check
254 whether the file is suitable for this interpreter.
255 This may be used when the binary format is more complex than can be handled
256 by the kernel's format specifications alone.
257 The program should return an exit code of zero if the file is appropriate
258 and non-zero otherwise.
259 This option cannot be used together with
260 .Fl Fl fix\-binary Cm yes .
261 .It Fl Fl credentials Cm yes , Fl Fl credentials Cm no
262 Whether to keep the credentials of the original binary to run the interpreter;
263 this is typically useful to run setuid binaries, but has security implications.
264 .It Fl Fl preserve Cm yes , Fl Fl preserve Cm no
265 Whether to preserve the original
266 .Li argv[0]
267 when running the interpreter, rather than overwriting it with the full path
268 to the binary.
269 .It Fl Fl fix\-binary Cm yes , Fl Fl fix\-binary Cm no
270 Whether to open the interpreter binary immediately and always use the opened
271 image.
272 This allows the interpreter from the host to be used regardless of usage in
273 chroots or different mount namespaces.
274 The default behaviour is
275 .Cm no ,
276 meaning that the kernel should open the interpreter binary lazily when
277 needed.
278 This option requires Linux 4.8 or newer.
279 It cannot be used together with
280 .Fl Fl detector ,
281 or with multiple binary formats that share the same magic number, since the
282 kernel will only open a single interpreter binary which will then not be
283 able to detect and execute the real interpreter from inside a chroot or from
284 a different mount namespace.
285 .El
286 .Ss FORMAT FILES
287 A format file is a sequence of options, one per line, corresponding roughly
288 to the options given to an
289 .Fl Fl install
290 command.
291 Each option consists of a key, followed by whitespace, followed by a value.
292 .Pp
293 The
294 .Ar package
295 option should be set to the current package.
296 The
297 .Ar interpreter
298 option should be set to the path to the interpreter that will handle this
299 binary format.
300 The
301 .Ar magic ,
302 .Ar offset ,
303 .Ar mask ,
304 .Ar extension ,
305 .Ar detector ,
306 .Ar credentials ,
307 .Ar preserve ,
308 and
309 .Ar fix_binary
310 options correspond to the command-line options of the same names.
311 .Sh EXIT STATUS
312 .Bl -tag -width 4n
313 .It 0
314 The requested action was successfully performed.
315 .It 2
316 Problems were encountered whilst parsing the command line or performing the
317 action.
318 .El
319 .Sh EXAMPLES
320 This format file can be used with an interpreter capable of handling Java
321 \&.class files:
322 .Bd -literal
323 package javawrapper
324 interpreter /usr/bin/javawrapper
325 magic \exca\exfe\exba\exbe
326 .Ed
327 .Pp
328 This corresponds roughly to the following command:
329 .Bd -literal
330 update\-binfmts \-\-package javawrapper \e
331 \-\-install javawrapper /usr/bin/javawrapper \e
332 \-\-magic \(aq\exca\exfe\exba\exbe\(aq
333 .Ed
334 .Sh NOTES
335 If you're not careful, you can break your system with
336 .Nm .
337 An easy way to do this is to register an ELF binary as a handler for ELF,
338 which will almost certainly cause your system to hang immediately; even if
339 it doesn't, you won't be able to run
340 .Nm
341 to fix it.
342 In the future
343 .Nm
344 may have some checks to prevent this sort of thing happening accidentally,
345 though of course you can still manipulate the binfmt_misc kernel module
346 directly.
347 .Sh AUTHOR
348 .An -nosplit
349 .Nm
350 is copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
351 2010, 2011
352 .An Colin Watson Aq [email protected] .
353 See the GNU General Public License version 3 or later for copying
354 conditions.
355 .Pp
356 You can find the GNU GPL v3 in
357 .Pa /usr/share/common\-licenses/GPL\-3
358 on any modern Debian system.
359 .Pp
360 Richard Guenther wrote the binfmt_misc kernel module.
361 .Sh THANKS
362 Ian Jackson wrote
363 .Ic update\-alternatives
364 and
365 .Ic dpkg\-divert ,
366 from which this program borrows heavily.