binfmts.h 4.1 KB

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