binfmt_loader.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <linux/init.h>
  2. #include <linux/fs.h>
  3. #include <linux/file.h>
  4. #include <linux/mm_types.h>
  5. #include <linux/binfmts.h>
  6. #include <linux/a.out.h>
  7. static int load_binary(struct linux_binprm *bprm)
  8. {
  9. struct exec *eh = (struct exec *)bprm->buf;
  10. unsigned long loader;
  11. struct file *file;
  12. int retval;
  13. if (eh->fh.f_magic != 0x183 || (eh->fh.f_flags & 0x3000) != 0x3000)
  14. return -ENOEXEC;
  15. if (bprm->loader)
  16. return -ENOEXEC;
  17. allow_write_access(bprm->file);
  18. fput(bprm->file);
  19. bprm->file = NULL;
  20. loader = bprm->vma->vm_end - sizeof(void *);
  21. file = open_exec("/sbin/loader");
  22. retval = PTR_ERR(file);
  23. if (IS_ERR(file))
  24. return retval;
  25. /* Remember if the application is TASO. */
  26. bprm->taso = eh->ah.entry < 0x100000000UL;
  27. bprm->file = file;
  28. bprm->loader = loader;
  29. retval = prepare_binprm(bprm);
  30. if (retval < 0)
  31. return retval;
  32. return search_binary_handler(bprm);
  33. }
  34. static struct linux_binfmt loader_format = {
  35. .load_binary = load_binary,
  36. };
  37. static int __init init_loader_binfmt(void)
  38. {
  39. insert_binfmt(&loader_format);
  40. return 0;
  41. }
  42. arch_initcall(init_loader_binfmt);