binfmts.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef _LINUX_BINFMTS_H
  2. #define _LINUX_BINFMTS_H
  3. #include <linux/sched.h>
  4. #include <linux/unistd.h>
  5. #include <asm/exec.h>
  6. #include <uapi/linux/binfmts.h>
  7. struct filename;
  8. #define CORENAME_MAX_SIZE 128
  9. /*
  10. * This structure is used to hold the arguments that are used when loading binaries.
  11. */
  12. struct linux_binprm {
  13. char buf[BINPRM_BUF_SIZE];
  14. #ifdef CONFIG_MMU
  15. struct vm_area_struct *vma;
  16. unsigned long vma_pages;
  17. #else
  18. # define MAX_ARG_PAGES 32
  19. struct page *page[MAX_ARG_PAGES];
  20. #endif
  21. struct mm_struct *mm;
  22. unsigned long p; /* current top of mem */
  23. unsigned int
  24. /*
  25. * True after the bprm_set_creds hook has been called once
  26. * (multiple calls can be made via prepare_binprm() for
  27. * binfmt_script/misc).
  28. */
  29. called_set_creds:1,
  30. /*
  31. * True if most recent call to the commoncaps bprm_set_creds
  32. * hook (due to multiple prepare_binprm() calls from the
  33. * binfmt_script/misc handlers) resulted in elevated
  34. * privileges.
  35. */
  36. cap_elevated:1,
  37. /*
  38. * Set by bprm_set_creds hook to indicate a privilege-gaining
  39. * exec has happened. Used to sanitize execution environment
  40. * and to set AT_SECURE auxv for glibc.
  41. */
  42. secureexec:1;
  43. #ifdef __alpha__
  44. unsigned int taso:1;
  45. #endif
  46. unsigned int recursion_depth; /* only for search_binary_handler() */
  47. struct file * file;
  48. struct cred *cred; /* new credentials */
  49. int unsafe; /* how unsafe this exec is (mask of LSM_UNSAFE_*) */
  50. unsigned int per_clear; /* bits to clear in current->personality */
  51. int argc, envc;
  52. const char * filename; /* Name of binary as seen by procps */
  53. const char * interp; /* Name of the binary really executed. Most
  54. of the time same as filename, but could be
  55. different for binfmt_{misc,script} */
  56. unsigned interp_flags;
  57. unsigned interp_data;
  58. unsigned long loader, exec;
  59. } __randomize_layout;
  60. #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
  61. #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
  62. /* fd of the binary should be passed to the interpreter */
  63. #define BINPRM_FLAGS_EXECFD_BIT 1
  64. #define BINPRM_FLAGS_EXECFD (1 << BINPRM_FLAGS_EXECFD_BIT)
  65. /* filename of the binary will be inaccessible after exec */
  66. #define BINPRM_FLAGS_PATH_INACCESSIBLE_BIT 2
  67. #define BINPRM_FLAGS_PATH_INACCESSIBLE (1 << BINPRM_FLAGS_PATH_INACCESSIBLE_BIT)
  68. /* Function parameter for binfmt->coredump */
  69. struct coredump_params {
  70. const siginfo_t *siginfo;
  71. struct pt_regs *regs;
  72. struct file *file;
  73. unsigned long limit;
  74. unsigned long mm_flags;
  75. loff_t written;
  76. loff_t pos;
  77. };
  78. /*
  79. * This structure defines the functions that are used to load the binary formats that
  80. * linux accepts.
  81. */
  82. struct linux_binfmt {
  83. struct list_head lh;
  84. struct module *module;
  85. int (*load_binary)(struct linux_binprm *);
  86. int (*load_shlib)(struct file *);
  87. int (*core_dump)(struct coredump_params *cprm);
  88. unsigned long min_coredump; /* minimal dump size */
  89. } __randomize_layout;
  90. extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
  91. /* Registration of default binfmt handlers */
  92. static inline void register_binfmt(struct linux_binfmt *fmt)
  93. {
  94. __register_binfmt(fmt, 0);
  95. }
  96. /* Same as above, but adds a new binfmt at the top of the list */
  97. static inline void insert_binfmt(struct linux_binfmt *fmt)
  98. {
  99. __register_binfmt(fmt, 1);
  100. }
  101. extern void unregister_binfmt(struct linux_binfmt *);
  102. extern int prepare_binprm(struct linux_binprm *);
  103. extern int __must_check remove_arg_zero(struct linux_binprm *);
  104. extern int search_binary_handler(struct linux_binprm *);
  105. extern int flush_old_exec(struct linux_binprm * bprm);
  106. extern void setup_new_exec(struct linux_binprm * bprm);
  107. extern void would_dump(struct linux_binprm *, struct file *);
  108. extern int suid_dumpable;
  109. /* Stack area protections */
  110. #define EXSTACK_DEFAULT 0 /* Whatever the arch defaults to */
  111. #define EXSTACK_DISABLE_X 1 /* Disable executable stacks */
  112. #define EXSTACK_ENABLE_X 2 /* Enable executable stacks */
  113. extern int setup_arg_pages(struct linux_binprm * bprm,
  114. unsigned long stack_top,
  115. int executable_stack);
  116. extern int transfer_args_to_stack(struct linux_binprm *bprm,
  117. unsigned long *sp_location);
  118. extern int bprm_change_interp(const char *interp, struct linux_binprm *bprm);
  119. extern int copy_strings_kernel(int argc, const char *const *argv,
  120. struct linux_binprm *bprm);
  121. extern int prepare_bprm_creds(struct linux_binprm *bprm);
  122. extern void install_exec_creds(struct linux_binprm *bprm);
  123. extern void set_binfmt(struct linux_binfmt *new);
  124. extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
  125. extern int do_execve(struct filename *,
  126. const char __user * const __user *,
  127. const char __user * const __user *);
  128. extern int do_execveat(int, struct filename *,
  129. const char __user * const __user *,
  130. const char __user * const __user *,
  131. int);
  132. #endif /* _LINUX_BINFMTS_H */