binfmts.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef _LINUX_BINFMTS_H
  2. #define _LINUX_BINFMTS_H
  3. #include <linux/capability.h>
  4. struct pt_regs;
  5. /*
  6. * These are the maximum length and maximum number of strings passed to the
  7. * execve() system call. MAX_ARG_STRLEN is essentially random but serves to
  8. * prevent the kernel from being unduly impacted by misaddressed pointers.
  9. * MAX_ARG_STRINGS is chosen to fit in a signed 32-bit integer.
  10. */
  11. #define MAX_ARG_STRLEN (PAGE_SIZE * 32)
  12. #define MAX_ARG_STRINGS 0x7FFFFFFF
  13. /* sizeof(linux_binprm->buf) */
  14. #define BINPRM_BUF_SIZE 128
  15. #ifdef __KERNEL__
  16. #include <linux/sched.h>
  17. #include <linux/unistd.h>
  18. #include <asm/exec.h>
  19. #define CORENAME_MAX_SIZE 128
  20. /*
  21. * This structure is used to hold the arguments that are used when loading binaries.
  22. */
  23. struct linux_binprm {
  24. char buf[BINPRM_BUF_SIZE];
  25. #ifdef CONFIG_MMU
  26. struct vm_area_struct *vma;
  27. unsigned long vma_pages;
  28. #else
  29. # define MAX_ARG_PAGES 32
  30. struct page *page[MAX_ARG_PAGES];
  31. #endif
  32. struct mm_struct *mm;
  33. unsigned long p; /* current top of mem */
  34. unsigned int
  35. cred_prepared:1,/* true if creds already prepared (multiple
  36. * preps happen for interpreters) */
  37. cap_effective:1;/* true if has elevated effective capabilities,
  38. * false if not; except for init which inherits
  39. * its parent's caps anyway */
  40. #ifdef __alpha__
  41. unsigned int taso:1;
  42. #endif
  43. unsigned int recursion_depth;
  44. struct file * file;
  45. struct cred *cred; /* new credentials */
  46. int unsafe; /* how unsafe this exec is (mask of LSM_UNSAFE_*) */
  47. unsigned int per_clear; /* bits to clear in current->personality */
  48. int argc, envc;
  49. const char * filename; /* Name of binary as seen by procps */
  50. const char * interp; /* Name of the binary really executed. Most
  51. of the time same as filename, but could be
  52. different for binfmt_{misc,script} */
  53. unsigned interp_flags;
  54. unsigned interp_data;
  55. unsigned long loader, exec;
  56. char tcomm[TASK_COMM_LEN];
  57. };
  58. #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
  59. #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
  60. /* fd of the binary should be passed to the interpreter */
  61. #define BINPRM_FLAGS_EXECFD_BIT 1
  62. #define BINPRM_FLAGS_EXECFD (1 << BINPRM_FLAGS_EXECFD_BIT)
  63. #define BINPRM_MAX_RECURSION 4
  64. /* Function parameter for binfmt->coredump */
  65. struct coredump_params {
  66. long signr;
  67. struct pt_regs *regs;
  68. struct file *file;
  69. unsigned long limit;
  70. unsigned long mm_flags;
  71. };
  72. /*
  73. * This structure defines the functions that are used to load the binary formats that
  74. * linux accepts.
  75. */
  76. struct linux_binfmt {
  77. struct list_head lh;
  78. struct module *module;
  79. int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
  80. int (*load_shlib)(struct file *);
  81. int (*core_dump)(struct coredump_params *cprm);
  82. unsigned long min_coredump; /* minimal dump size */
  83. };
  84. extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
  85. /* Registration of default binfmt handlers */
  86. static inline void register_binfmt(struct linux_binfmt *fmt)
  87. {
  88. __register_binfmt(fmt, 0);
  89. }
  90. /* Same as above, but adds a new binfmt at the top of the list */
  91. static inline void insert_binfmt(struct linux_binfmt *fmt)
  92. {
  93. __register_binfmt(fmt, 1);
  94. }
  95. extern void unregister_binfmt(struct linux_binfmt *);
  96. extern int prepare_binprm(struct linux_binprm *);
  97. extern int __must_check remove_arg_zero(struct linux_binprm *);
  98. extern int search_binary_handler(struct linux_binprm *, struct pt_regs *);
  99. extern int flush_old_exec(struct linux_binprm * bprm);
  100. extern void setup_new_exec(struct linux_binprm * bprm);
  101. extern void would_dump(struct linux_binprm *, struct file *);
  102. extern int suid_dumpable;
  103. #define SUID_DUMP_DISABLE 0 /* No setuid dumping */
  104. #define SUID_DUMP_USER 1 /* Dump as user of process */
  105. #define SUID_DUMP_ROOT 2 /* Dump as root */
  106. /* Stack area protections */
  107. #define EXSTACK_DEFAULT 0 /* Whatever the arch defaults to */
  108. #define EXSTACK_DISABLE_X 1 /* Disable executable stacks */
  109. #define EXSTACK_ENABLE_X 2 /* Enable executable stacks */
  110. extern int setup_arg_pages(struct linux_binprm * bprm,
  111. unsigned long stack_top,
  112. int executable_stack);
  113. extern int bprm_mm_init(struct linux_binprm *bprm);
  114. extern int copy_strings_kernel(int argc, const char *const *argv,
  115. struct linux_binprm *bprm);
  116. extern int prepare_bprm_creds(struct linux_binprm *bprm);
  117. extern void install_exec_creds(struct linux_binprm *bprm);
  118. extern void do_coredump(long signr, int exit_code, struct pt_regs *regs);
  119. extern void set_binfmt(struct linux_binfmt *new);
  120. extern void free_bprm(struct linux_binprm *);
  121. #ifdef __ARCH_WANT_KERNEL_EXECVE
  122. extern void ret_from_kernel_execve(struct pt_regs *normal) __noreturn;
  123. #endif
  124. #endif /* __KERNEL__ */
  125. #endif /* _LINUX_BINFMTS_H */