binfmt_misc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * binfmt_misc.c
  3. *
  4. * Copyright (C) 1997 Richard Günther
  5. *
  6. * binfmt_misc detects binaries via a magic or filename extension and invokes
  7. * a specified wrapper. This should obsolete binfmt_java, binfmt_em86 and
  8. * binfmt_mz.
  9. *
  10. * 1997-04-25 first version
  11. * [...]
  12. * 1997-05-19 cleanup
  13. * 1997-06-26 hpa: pass the real filename rather than argv[0]
  14. * 1997-06-30 minor cleanup
  15. * 1997-08-09 removed extension stripping, locking cleanup
  16. * 2001-02-28 AV: rewritten into something that resembles C. Original didn't.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/binfmts.h>
  21. #include <linux/slab.h>
  22. #include <linux/ctype.h>
  23. #include <linux/file.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/namei.h>
  26. #include <linux/mount.h>
  27. #include <linux/syscalls.h>
  28. #include <asm/uaccess.h>
  29. enum {
  30. VERBOSE_STATUS = 1 /* make it zero to save 400 bytes kernel memory */
  31. };
  32. static LIST_HEAD(entries);
  33. static int enabled = 1;
  34. enum {Enabled, Magic};
  35. #define MISC_FMT_PRESERVE_ARGV0 (1<<31)
  36. #define MISC_FMT_OPEN_BINARY (1<<30)
  37. #define MISC_FMT_CREDENTIALS (1<<29)
  38. typedef struct {
  39. struct list_head list;
  40. unsigned long flags; /* type, status, etc. */
  41. int offset; /* offset of magic */
  42. int size; /* size of magic/mask */
  43. char *magic; /* magic or filename extension */
  44. char *mask; /* mask, NULL for exact match */
  45. char *interpreter; /* filename of interpreter */
  46. char *name;
  47. struct dentry *dentry;
  48. } Node;
  49. static DEFINE_RWLOCK(entries_lock);
  50. static struct file_system_type bm_fs_type;
  51. static struct vfsmount *bm_mnt;
  52. static int entry_count;
  53. /*
  54. * Check if we support the binfmt
  55. * if we do, return the node, else NULL
  56. * locking is done in load_misc_binary
  57. */
  58. static Node *check_file(struct linux_binprm *bprm)
  59. {
  60. char *p = strrchr(bprm->interp, '.');
  61. struct list_head *l;
  62. list_for_each(l, &entries) {
  63. Node *e = list_entry(l, Node, list);
  64. char *s;
  65. int j;
  66. if (!test_bit(Enabled, &e->flags))
  67. continue;
  68. if (!test_bit(Magic, &e->flags)) {
  69. if (p && !strcmp(e->magic, p + 1))
  70. return e;
  71. continue;
  72. }
  73. s = bprm->buf + e->offset;
  74. if (e->mask) {
  75. for (j = 0; j < e->size; j++)
  76. if ((*s++ ^ e->magic[j]) & e->mask[j])
  77. break;
  78. } else {
  79. for (j = 0; j < e->size; j++)
  80. if ((*s++ ^ e->magic[j]))
  81. break;
  82. }
  83. if (j == e->size)
  84. return e;
  85. }
  86. return NULL;
  87. }
  88. /*
  89. * the loader itself
  90. */
  91. static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
  92. {
  93. Node *fmt;
  94. struct file * interp_file = NULL;
  95. char iname[BINPRM_BUF_SIZE];
  96. char *iname_addr = iname;
  97. int retval;
  98. int fd_binary = -1;
  99. struct files_struct *files = NULL;
  100. retval = -ENOEXEC;
  101. if (!enabled)
  102. goto _ret;
  103. /* to keep locking time low, we copy the interpreter string */
  104. read_lock(&entries_lock);
  105. fmt = check_file(bprm);
  106. if (fmt)
  107. strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
  108. read_unlock(&entries_lock);
  109. if (!fmt)
  110. goto _ret;
  111. if (!(fmt->flags & MISC_FMT_PRESERVE_ARGV0)) {
  112. remove_arg_zero(bprm);
  113. }
  114. if (fmt->flags & MISC_FMT_OPEN_BINARY) {
  115. files = current->files;
  116. retval = unshare_files();
  117. if (retval < 0)
  118. goto _ret;
  119. if (files == current->files) {
  120. put_files_struct(files);
  121. files = NULL;
  122. }
  123. /* if the binary should be opened on behalf of the
  124. * interpreter than keep it open and assign descriptor
  125. * to it */
  126. fd_binary = get_unused_fd();
  127. if (fd_binary < 0) {
  128. retval = fd_binary;
  129. goto _unshare;
  130. }
  131. fd_install(fd_binary, bprm->file);
  132. /* if the binary is not readable than enforce mm->dumpable=0
  133. regardless of the interpreter's permissions */
  134. if (file_permission(bprm->file, MAY_READ))
  135. bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
  136. allow_write_access(bprm->file);
  137. bprm->file = NULL;
  138. /* mark the bprm that fd should be passed to interp */
  139. bprm->interp_flags |= BINPRM_FLAGS_EXECFD;
  140. bprm->interp_data = fd_binary;
  141. } else {
  142. allow_write_access(bprm->file);
  143. fput(bprm->file);
  144. bprm->file = NULL;
  145. }
  146. /* make argv[1] be the path to the binary */
  147. retval = copy_strings_kernel (1, &bprm->interp, bprm);
  148. if (retval < 0)
  149. goto _error;
  150. bprm->argc++;
  151. /* add the interp as argv[0] */
  152. retval = copy_strings_kernel (1, &iname_addr, bprm);
  153. if (retval < 0)
  154. goto _error;
  155. bprm->argc ++;
  156. bprm->interp = iname; /* for binfmt_script */
  157. interp_file = open_exec (iname);
  158. retval = PTR_ERR (interp_file);
  159. if (IS_ERR (interp_file))
  160. goto _error;
  161. bprm->file = interp_file;
  162. if (fmt->flags & MISC_FMT_CREDENTIALS) {
  163. /*
  164. * No need to call prepare_binprm(), it's already been
  165. * done. bprm->buf is stale, update from interp_file.
  166. */
  167. memset(bprm->buf, 0, BINPRM_BUF_SIZE);
  168. retval = kernel_read(bprm->file, 0, bprm->buf, BINPRM_BUF_SIZE);
  169. } else
  170. retval = prepare_binprm (bprm);
  171. if (retval < 0)
  172. goto _error;
  173. retval = search_binary_handler (bprm, regs);
  174. if (retval < 0)
  175. goto _error;
  176. if (files) {
  177. put_files_struct(files);
  178. files = NULL;
  179. }
  180. _ret:
  181. return retval;
  182. _error:
  183. if (fd_binary > 0)
  184. sys_close(fd_binary);
  185. bprm->interp_flags = 0;
  186. bprm->interp_data = 0;
  187. _unshare:
  188. if (files)
  189. reset_files_struct(current, files);
  190. goto _ret;
  191. }
  192. /* Command parsers */
  193. /*
  194. * parses and copies one argument enclosed in del from *sp to *dp,
  195. * recognising the \x special.
  196. * returns pointer to the copied argument or NULL in case of an
  197. * error (and sets err) or null argument length.
  198. */
  199. static char *scanarg(char *s, char del)
  200. {
  201. char c;
  202. while ((c = *s++) != del) {
  203. if (c == '\\' && *s == 'x') {
  204. s++;
  205. if (!isxdigit(*s++))
  206. return NULL;
  207. if (!isxdigit(*s++))
  208. return NULL;
  209. }
  210. }
  211. return s;
  212. }
  213. static int unquote(char *from)
  214. {
  215. char c = 0, *s = from, *p = from;
  216. while ((c = *s++) != '\0') {
  217. if (c == '\\' && *s == 'x') {
  218. s++;
  219. c = toupper(*s++);
  220. *p = (c - (isdigit(c) ? '0' : 'A' - 10)) << 4;
  221. c = toupper(*s++);
  222. *p++ |= c - (isdigit(c) ? '0' : 'A' - 10);
  223. continue;
  224. }
  225. *p++ = c;
  226. }
  227. return p - from;
  228. }
  229. static char * check_special_flags (char * sfs, Node * e)
  230. {
  231. char * p = sfs;
  232. int cont = 1;
  233. /* special flags */
  234. while (cont) {
  235. switch (*p) {
  236. case 'P':
  237. p++;
  238. e->flags |= MISC_FMT_PRESERVE_ARGV0;
  239. break;
  240. case 'O':
  241. p++;
  242. e->flags |= MISC_FMT_OPEN_BINARY;
  243. break;
  244. case 'C':
  245. p++;
  246. /* this flags also implies the
  247. open-binary flag */
  248. e->flags |= (MISC_FMT_CREDENTIALS |
  249. MISC_FMT_OPEN_BINARY);
  250. break;
  251. default:
  252. cont = 0;
  253. }
  254. }
  255. return p;
  256. }
  257. /*
  258. * This registers a new binary format, it recognises the syntax
  259. * ':name:type:offset:magic:mask:interpreter:flags'
  260. * where the ':' is the IFS, that can be chosen with the first char
  261. */
  262. static Node *create_entry(const char __user *buffer, size_t count)
  263. {
  264. Node *e;
  265. int memsize, err;
  266. char *buf, *p;
  267. char del;
  268. /* some sanity checks */
  269. err = -EINVAL;
  270. if ((count < 11) || (count > 256))
  271. goto out;
  272. err = -ENOMEM;
  273. memsize = sizeof(Node) + count + 8;
  274. e = kmalloc(memsize, GFP_USER);
  275. if (!e)
  276. goto out;
  277. p = buf = (char *)e + sizeof(Node);
  278. memset(e, 0, sizeof(Node));
  279. if (copy_from_user(buf, buffer, count))
  280. goto Efault;
  281. del = *p++; /* delimeter */
  282. memset(buf+count, del, 8);
  283. e->name = p;
  284. p = strchr(p, del);
  285. if (!p)
  286. goto Einval;
  287. *p++ = '\0';
  288. if (!e->name[0] ||
  289. !strcmp(e->name, ".") ||
  290. !strcmp(e->name, "..") ||
  291. strchr(e->name, '/'))
  292. goto Einval;
  293. switch (*p++) {
  294. case 'E': e->flags = 1<<Enabled; break;
  295. case 'M': e->flags = (1<<Enabled) | (1<<Magic); break;
  296. default: goto Einval;
  297. }
  298. if (*p++ != del)
  299. goto Einval;
  300. if (test_bit(Magic, &e->flags)) {
  301. char *s = strchr(p, del);
  302. if (!s)
  303. goto Einval;
  304. *s++ = '\0';
  305. e->offset = simple_strtoul(p, &p, 10);
  306. if (*p++)
  307. goto Einval;
  308. e->magic = p;
  309. p = scanarg(p, del);
  310. if (!p)
  311. goto Einval;
  312. p[-1] = '\0';
  313. if (!e->magic[0])
  314. goto Einval;
  315. e->mask = p;
  316. p = scanarg(p, del);
  317. if (!p)
  318. goto Einval;
  319. p[-1] = '\0';
  320. if (!e->mask[0])
  321. e->mask = NULL;
  322. e->size = unquote(e->magic);
  323. if (e->mask && unquote(e->mask) != e->size)
  324. goto Einval;
  325. if (e->size + e->offset > BINPRM_BUF_SIZE)
  326. goto Einval;
  327. } else {
  328. p = strchr(p, del);
  329. if (!p)
  330. goto Einval;
  331. *p++ = '\0';
  332. e->magic = p;
  333. p = strchr(p, del);
  334. if (!p)
  335. goto Einval;
  336. *p++ = '\0';
  337. if (!e->magic[0] || strchr(e->magic, '/'))
  338. goto Einval;
  339. p = strchr(p, del);
  340. if (!p)
  341. goto Einval;
  342. *p++ = '\0';
  343. }
  344. e->interpreter = p;
  345. p = strchr(p, del);
  346. if (!p)
  347. goto Einval;
  348. *p++ = '\0';
  349. if (!e->interpreter[0])
  350. goto Einval;
  351. p = check_special_flags (p, e);
  352. if (*p == '\n')
  353. p++;
  354. if (p != buf + count)
  355. goto Einval;
  356. return e;
  357. out:
  358. return ERR_PTR(err);
  359. Efault:
  360. kfree(e);
  361. return ERR_PTR(-EFAULT);
  362. Einval:
  363. kfree(e);
  364. return ERR_PTR(-EINVAL);
  365. }
  366. /*
  367. * Set status of entry/binfmt_misc:
  368. * '1' enables, '0' disables and '-1' clears entry/binfmt_misc
  369. */
  370. static int parse_command(const char __user *buffer, size_t count)
  371. {
  372. char s[4];
  373. if (!count)
  374. return 0;
  375. if (count > 3)
  376. return -EINVAL;
  377. if (copy_from_user(s, buffer, count))
  378. return -EFAULT;
  379. if (s[count-1] == '\n')
  380. count--;
  381. if (count == 1 && s[0] == '0')
  382. return 1;
  383. if (count == 1 && s[0] == '1')
  384. return 2;
  385. if (count == 2 && s[0] == '-' && s[1] == '1')
  386. return 3;
  387. return -EINVAL;
  388. }
  389. /* generic stuff */
  390. static void entry_status(Node *e, char *page)
  391. {
  392. char *dp;
  393. char *status = "disabled";
  394. const char * flags = "flags: ";
  395. if (test_bit(Enabled, &e->flags))
  396. status = "enabled";
  397. if (!VERBOSE_STATUS) {
  398. sprintf(page, "%s\n", status);
  399. return;
  400. }
  401. sprintf(page, "%s\ninterpreter %s\n", status, e->interpreter);
  402. dp = page + strlen(page);
  403. /* print the special flags */
  404. sprintf (dp, "%s", flags);
  405. dp += strlen (flags);
  406. if (e->flags & MISC_FMT_PRESERVE_ARGV0) {
  407. *dp ++ = 'P';
  408. }
  409. if (e->flags & MISC_FMT_OPEN_BINARY) {
  410. *dp ++ = 'O';
  411. }
  412. if (e->flags & MISC_FMT_CREDENTIALS) {
  413. *dp ++ = 'C';
  414. }
  415. *dp ++ = '\n';
  416. if (!test_bit(Magic, &e->flags)) {
  417. sprintf(dp, "extension .%s\n", e->magic);
  418. } else {
  419. int i;
  420. sprintf(dp, "offset %i\nmagic ", e->offset);
  421. dp = page + strlen(page);
  422. for (i = 0; i < e->size; i++) {
  423. sprintf(dp, "%02x", 0xff & (int) (e->magic[i]));
  424. dp += 2;
  425. }
  426. if (e->mask) {
  427. sprintf(dp, "\nmask ");
  428. dp += 6;
  429. for (i = 0; i < e->size; i++) {
  430. sprintf(dp, "%02x", 0xff & (int) (e->mask[i]));
  431. dp += 2;
  432. }
  433. }
  434. *dp++ = '\n';
  435. *dp = '\0';
  436. }
  437. }
  438. static struct inode *bm_get_inode(struct super_block *sb, int mode)
  439. {
  440. struct inode * inode = new_inode(sb);
  441. if (inode) {
  442. inode->i_mode = mode;
  443. inode->i_uid = 0;
  444. inode->i_gid = 0;
  445. inode->i_blocks = 0;
  446. inode->i_atime = inode->i_mtime = inode->i_ctime =
  447. current_fs_time(inode->i_sb);
  448. }
  449. return inode;
  450. }
  451. static void bm_clear_inode(struct inode *inode)
  452. {
  453. kfree(inode->i_private);
  454. }
  455. static void kill_node(Node *e)
  456. {
  457. struct dentry *dentry;
  458. write_lock(&entries_lock);
  459. dentry = e->dentry;
  460. if (dentry) {
  461. list_del_init(&e->list);
  462. e->dentry = NULL;
  463. }
  464. write_unlock(&entries_lock);
  465. if (dentry) {
  466. dentry->d_inode->i_nlink--;
  467. d_drop(dentry);
  468. dput(dentry);
  469. simple_release_fs(&bm_mnt, &entry_count);
  470. }
  471. }
  472. /* /<entry> */
  473. static ssize_t
  474. bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
  475. {
  476. Node *e = file->f_path.dentry->d_inode->i_private;
  477. loff_t pos = *ppos;
  478. ssize_t res;
  479. char *page;
  480. int len;
  481. if (!(page = (char*) __get_free_page(GFP_KERNEL)))
  482. return -ENOMEM;
  483. entry_status(e, page);
  484. len = strlen(page);
  485. res = -EINVAL;
  486. if (pos < 0)
  487. goto out;
  488. res = 0;
  489. if (pos >= len)
  490. goto out;
  491. if (len < pos + nbytes)
  492. nbytes = len - pos;
  493. res = -EFAULT;
  494. if (copy_to_user(buf, page + pos, nbytes))
  495. goto out;
  496. *ppos = pos + nbytes;
  497. res = nbytes;
  498. out:
  499. free_page((unsigned long) page);
  500. return res;
  501. }
  502. static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
  503. size_t count, loff_t *ppos)
  504. {
  505. struct dentry *root;
  506. Node *e = file->f_path.dentry->d_inode->i_private;
  507. int res = parse_command(buffer, count);
  508. switch (res) {
  509. case 1: clear_bit(Enabled, &e->flags);
  510. break;
  511. case 2: set_bit(Enabled, &e->flags);
  512. break;
  513. case 3: root = dget(file->f_path.mnt->mnt_sb->s_root);
  514. mutex_lock(&root->d_inode->i_mutex);
  515. kill_node(e);
  516. mutex_unlock(&root->d_inode->i_mutex);
  517. dput(root);
  518. break;
  519. default: return res;
  520. }
  521. return count;
  522. }
  523. static const struct file_operations bm_entry_operations = {
  524. .read = bm_entry_read,
  525. .write = bm_entry_write,
  526. };
  527. /* /register */
  528. static ssize_t bm_register_write(struct file *file, const char __user *buffer,
  529. size_t count, loff_t *ppos)
  530. {
  531. Node *e;
  532. struct inode *inode;
  533. struct dentry *root, *dentry;
  534. struct super_block *sb = file->f_path.mnt->mnt_sb;
  535. int err = 0;
  536. e = create_entry(buffer, count);
  537. if (IS_ERR(e))
  538. return PTR_ERR(e);
  539. root = dget(sb->s_root);
  540. mutex_lock(&root->d_inode->i_mutex);
  541. dentry = lookup_one_len(e->name, root, strlen(e->name));
  542. err = PTR_ERR(dentry);
  543. if (IS_ERR(dentry))
  544. goto out;
  545. err = -EEXIST;
  546. if (dentry->d_inode)
  547. goto out2;
  548. inode = bm_get_inode(sb, S_IFREG | 0644);
  549. err = -ENOMEM;
  550. if (!inode)
  551. goto out2;
  552. err = simple_pin_fs(&bm_fs_type, &bm_mnt, &entry_count);
  553. if (err) {
  554. iput(inode);
  555. inode = NULL;
  556. goto out2;
  557. }
  558. e->dentry = dget(dentry);
  559. inode->i_private = e;
  560. inode->i_fop = &bm_entry_operations;
  561. d_instantiate(dentry, inode);
  562. write_lock(&entries_lock);
  563. list_add(&e->list, &entries);
  564. write_unlock(&entries_lock);
  565. err = 0;
  566. out2:
  567. dput(dentry);
  568. out:
  569. mutex_unlock(&root->d_inode->i_mutex);
  570. dput(root);
  571. if (err) {
  572. kfree(e);
  573. return -EINVAL;
  574. }
  575. return count;
  576. }
  577. static const struct file_operations bm_register_operations = {
  578. .write = bm_register_write,
  579. };
  580. /* /status */
  581. static ssize_t
  582. bm_status_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
  583. {
  584. char *s = enabled ? "enabled" : "disabled";
  585. int len = strlen(s);
  586. loff_t pos = *ppos;
  587. if (pos < 0)
  588. return -EINVAL;
  589. if (pos >= len)
  590. return 0;
  591. if (len < pos + nbytes)
  592. nbytes = len - pos;
  593. if (copy_to_user(buf, s + pos, nbytes))
  594. return -EFAULT;
  595. *ppos = pos + nbytes;
  596. return nbytes;
  597. }
  598. static ssize_t bm_status_write(struct file * file, const char __user * buffer,
  599. size_t count, loff_t *ppos)
  600. {
  601. int res = parse_command(buffer, count);
  602. struct dentry *root;
  603. switch (res) {
  604. case 1: enabled = 0; break;
  605. case 2: enabled = 1; break;
  606. case 3: root = dget(file->f_path.mnt->mnt_sb->s_root);
  607. mutex_lock(&root->d_inode->i_mutex);
  608. while (!list_empty(&entries))
  609. kill_node(list_entry(entries.next, Node, list));
  610. mutex_unlock(&root->d_inode->i_mutex);
  611. dput(root);
  612. default: return res;
  613. }
  614. return count;
  615. }
  616. static const struct file_operations bm_status_operations = {
  617. .read = bm_status_read,
  618. .write = bm_status_write,
  619. };
  620. /* Superblock handling */
  621. static const struct super_operations s_ops = {
  622. .statfs = simple_statfs,
  623. .clear_inode = bm_clear_inode,
  624. };
  625. static int bm_fill_super(struct super_block * sb, void * data, int silent)
  626. {
  627. static struct tree_descr bm_files[] = {
  628. [1] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
  629. [2] = {"register", &bm_register_operations, S_IWUSR},
  630. /* last one */ {""}
  631. };
  632. int err = simple_fill_super(sb, 0x42494e4d, bm_files);
  633. if (!err)
  634. sb->s_op = &s_ops;
  635. return err;
  636. }
  637. static int bm_get_sb(struct file_system_type *fs_type,
  638. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  639. {
  640. return get_sb_single(fs_type, flags, data, bm_fill_super, mnt);
  641. }
  642. static struct linux_binfmt misc_format = {
  643. .module = THIS_MODULE,
  644. .load_binary = load_misc_binary,
  645. };
  646. static struct file_system_type bm_fs_type = {
  647. .owner = THIS_MODULE,
  648. .name = "binfmt_misc",
  649. .get_sb = bm_get_sb,
  650. .kill_sb = kill_litter_super,
  651. };
  652. static int __init init_misc_binfmt(void)
  653. {
  654. int err = register_filesystem(&bm_fs_type);
  655. if (!err) {
  656. err = register_binfmt(&misc_format);
  657. if (err)
  658. unregister_filesystem(&bm_fs_type);
  659. }
  660. return err;
  661. }
  662. static void __exit exit_misc_binfmt(void)
  663. {
  664. unregister_binfmt(&misc_format);
  665. unregister_filesystem(&bm_fs_type);
  666. }
  667. core_initcall(init_misc_binfmt);
  668. module_exit(exit_misc_binfmt);
  669. MODULE_LICENSE("GPL");