binfmts.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. char tcomm[TASK_COMM_LEN];
  45. };
  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. /* Function parameter for binfmt->coredump */
  52. struct coredump_params {
  53. const siginfo_t *siginfo;
  54. struct pt_regs *regs;
  55. struct file *file;
  56. unsigned long limit;
  57. unsigned long mm_flags;
  58. loff_t written;
  59. };
  60. /*
  61. * This structure defines the functions that are used to load the binary formats that
  62. * linux accepts.
  63. */
  64. struct linux_binfmt {
  65. struct list_head lh;
  66. struct module *module;
  67. int (*load_binary)(struct linux_binprm *);
  68. int (*load_shlib)(struct file *);
  69. int (*core_dump)(struct coredump_params *cprm);
  70. unsigned long min_coredump; /* minimal dump size */
  71. };
  72. extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
  73. /* Registration of default binfmt handlers */
  74. static inline void register_binfmt(struct linux_binfmt *fmt)
  75. {
  76. __register_binfmt(fmt, 0);
  77. }
  78. /* Same as above, but adds a new binfmt at the top of the list */
  79. static inline void insert_binfmt(struct linux_binfmt *fmt)
  80. {
  81. __register_binfmt(fmt, 1);
  82. }
  83. extern void unregister_binfmt(struct linux_binfmt *);
  84. extern int prepare_binprm(struct linux_binprm *);
  85. extern int __must_check remove_arg_zero(struct linux_binprm *);
  86. extern int search_binary_handler(struct linux_binprm *);
  87. extern int flush_old_exec(struct linux_binprm * bprm);
  88. extern void setup_new_exec(struct linux_binprm * bprm);
  89. extern void would_dump(struct linux_binprm *, struct file *);
  90. extern int suid_dumpable;
  91. #define SUID_DUMP_DISABLE 0 /* No setuid dumping */
  92. #define SUID_DUMP_USER 1 /* Dump as user of process */
  93. #define SUID_DUMP_ROOT 2 /* Dump as root */
  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 bprm_change_interp(char *interp, struct linux_binprm *bprm);
  102. extern int copy_strings_kernel(int argc, const char *const *argv,
  103. struct linux_binprm *bprm);
  104. extern int prepare_bprm_creds(struct linux_binprm *bprm);
  105. extern void install_exec_creds(struct linux_binprm *bprm);
  106. extern void set_binfmt(struct linux_binfmt *new);
  107. extern void free_bprm(struct linux_binprm *);
  108. extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
  109. #endif /* _LINUX_BINFMTS_H */