binfmts.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. cred_prepared:1,/* true if creds already prepared (multiple
  25. * preps happen for interpreters) */
  26. cap_effective:1;/* true if has elevated effective capabilities,
  27. * false if not; except for init which inherits
  28. * its parent's caps anyway */
  29. #ifdef __alpha__
  30. unsigned int taso:1;
  31. #endif
  32. unsigned int recursion_depth; /* only for search_binary_handler() */
  33. struct file * file;
  34. struct cred *cred; /* new credentials */
  35. int unsafe; /* how unsafe this exec is (mask of LSM_UNSAFE_*) */
  36. unsigned int per_clear; /* bits to clear in current->personality */
  37. int argc, envc;
  38. const char * filename; /* Name of binary as seen by procps */
  39. const char * interp; /* Name of the binary really executed. Most
  40. of the time same as filename, but could be
  41. different for binfmt_{misc,script} */
  42. unsigned interp_flags;
  43. unsigned interp_data;
  44. unsigned long loader, exec;
  45. } __randomize_layout;
  46. #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
  47. #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
  48. /* fd of the binary should be passed to the interpreter */
  49. #define BINPRM_FLAGS_EXECFD_BIT 1
  50. #define BINPRM_FLAGS_EXECFD (1 << BINPRM_FLAGS_EXECFD_BIT)
  51. /* filename of the binary will be inaccessible after exec */
  52. #define BINPRM_FLAGS_PATH_INACCESSIBLE_BIT 2
  53. #define BINPRM_FLAGS_PATH_INACCESSIBLE (1 << BINPRM_FLAGS_PATH_INACCESSIBLE_BIT)
  54. /* Function parameter for binfmt->coredump */
  55. struct coredump_params {
  56. const siginfo_t *siginfo;
  57. struct pt_regs *regs;
  58. struct file *file;
  59. unsigned long limit;
  60. unsigned long mm_flags;
  61. loff_t written;
  62. loff_t pos;
  63. };
  64. /*
  65. * This structure defines the functions that are used to load the binary formats that
  66. * linux accepts.
  67. */
  68. struct linux_binfmt {
  69. struct list_head lh;
  70. struct module *module;
  71. int (*load_binary)(struct linux_binprm *);
  72. int (*load_shlib)(struct file *);
  73. int (*core_dump)(struct coredump_params *cprm);
  74. unsigned long min_coredump; /* minimal dump size */
  75. } __randomize_layout;
  76. extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
  77. /* Registration of default binfmt handlers */
  78. static inline void register_binfmt(struct linux_binfmt *fmt)
  79. {
  80. __register_binfmt(fmt, 0);
  81. }
  82. /* Same as above, but adds a new binfmt at the top of the list */
  83. static inline void insert_binfmt(struct linux_binfmt *fmt)
  84. {
  85. __register_binfmt(fmt, 1);
  86. }
  87. extern void unregister_binfmt(struct linux_binfmt *);
  88. extern int prepare_binprm(struct linux_binprm *);
  89. extern int __must_check remove_arg_zero(struct linux_binprm *);
  90. extern int search_binary_handler(struct linux_binprm *);
  91. extern int flush_old_exec(struct linux_binprm * bprm);
  92. extern void setup_new_exec(struct linux_binprm * bprm);
  93. extern void would_dump(struct linux_binprm *, struct file *);
  94. extern int suid_dumpable;
  95. /* Stack area protections */
  96. #define EXSTACK_DEFAULT 0 /* Whatever the arch defaults to */
  97. #define EXSTACK_DISABLE_X 1 /* Disable executable stacks */
  98. #define EXSTACK_ENABLE_X 2 /* Enable executable stacks */
  99. extern int setup_arg_pages(struct linux_binprm * bprm,
  100. unsigned long stack_top,
  101. int executable_stack);
  102. extern int transfer_args_to_stack(struct linux_binprm *bprm,
  103. unsigned long *sp_location);
  104. extern int bprm_change_interp(char *interp, struct linux_binprm *bprm);
  105. extern int copy_strings_kernel(int argc, const char *const *argv,
  106. struct linux_binprm *bprm);
  107. extern int prepare_bprm_creds(struct linux_binprm *bprm);
  108. extern void install_exec_creds(struct linux_binprm *bprm);
  109. extern void set_binfmt(struct linux_binfmt *new);
  110. extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
  111. extern int do_execve(struct filename *,
  112. const char __user * const __user *,
  113. const char __user * const __user *);
  114. extern int do_execveat(int, struct filename *,
  115. const char __user * const __user *,
  116. const char __user * const __user *,
  117. int);
  118. #endif /* _LINUX_BINFMTS_H */