binfmt_loader.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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, struct pt_regs *regs)
  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,regs);
  33. }
  34. static struct linux_binfmt loader_format = {
  35. .load_binary = load_binary,
  36. };
  37. static int __init init_loader_binfmt(void)
  38. {
  39. return insert_binfmt(&loader_format);
  40. }
  41. arch_initcall(init_loader_binfmt);