binfmt_loader.c 1.1 KB

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