binfmts.h 5.0 KB

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