binfmts.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #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 long argmin; /* rlimit marker for copy_strings() */
  24. unsigned int
  25. /* Should an execfd be passed to userspace? */
  26. have_execfd:1,
  27. /* Use the creds of a script (see binfmt_misc) */
  28. execfd_creds:1,
  29. /*
  30. * Set by bprm_creds_for_exec hook to indicate a
  31. * privilege-gaining exec has happened. Used to set
  32. * AT_SECURE auxv for glibc.
  33. */
  34. secureexec:1,
  35. /*
  36. * Set when errors can no longer be returned to the
  37. * original userspace.
  38. */
  39. point_of_no_return:1;
  40. #ifdef __alpha__
  41. unsigned int taso:1;
  42. #endif
  43. struct file *executable; /* Executable to pass to the interpreter */
  44. struct file *interpreter;
  45. struct file *file;
  46. struct cred *cred; /* new credentials */
  47. int unsafe; /* how unsafe this exec is (mask of LSM_UNSAFE_*) */
  48. unsigned int per_clear; /* bits to clear in current->personality */
  49. int argc, envc;
  50. const char *filename; /* Name of binary as seen by procps */
  51. const char *interp; /* Name of the binary really executed. Most
  52. of the time same as filename, but could be
  53. different for binfmt_{misc,script} */
  54. const char *fdpath; /* generated filename for execveat */
  55. unsigned interp_flags;
  56. int execfd; /* File descriptor of the executable */
  57. unsigned long loader, exec;
  58. struct rlimit rlim_stack; /* Saved RLIMIT_STACK used during exec. */
  59. char buf[BINPRM_BUF_SIZE];
  60. } __randomize_layout;
  61. #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
  62. #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
  63. /* filename of the binary will be inaccessible after exec */
  64. #define BINPRM_FLAGS_PATH_INACCESSIBLE_BIT 2
  65. #define BINPRM_FLAGS_PATH_INACCESSIBLE (1 << BINPRM_FLAGS_PATH_INACCESSIBLE_BIT)
  66. /* Function parameter for binfmt->coredump */
  67. struct coredump_params {
  68. const kernel_siginfo_t *siginfo;
  69. struct pt_regs *regs;
  70. struct file *file;
  71. unsigned long limit;
  72. unsigned long mm_flags;
  73. loff_t written;
  74. loff_t pos;
  75. };
  76. /*
  77. * This structure defines the functions that are used to load the binary formats that
  78. * linux accepts.
  79. */
  80. struct linux_binfmt {
  81. struct list_head lh;
  82. struct module *module;
  83. int (*load_binary)(struct linux_binprm *);
  84. int (*load_shlib)(struct file *);
  85. int (*core_dump)(struct coredump_params *cprm);
  86. unsigned long min_coredump; /* minimal dump size */
  87. } __randomize_layout;
  88. extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
  89. /* Registration of default binfmt handlers */
  90. static inline void register_binfmt(struct linux_binfmt *fmt)
  91. {
  92. __register_binfmt(fmt, 0);
  93. }
  94. /* Same as above, but adds a new binfmt at the top of the list */
  95. static inline void insert_binfmt(struct linux_binfmt *fmt)
  96. {
  97. __register_binfmt(fmt, 1);
  98. }
  99. extern void unregister_binfmt(struct linux_binfmt *);
  100. extern int __must_check remove_arg_zero(struct linux_binprm *);
  101. extern int begin_new_exec(struct linux_binprm * bprm);
  102. extern void setup_new_exec(struct linux_binprm * bprm);
  103. extern void finalize_exec(struct linux_binprm *bprm);
  104. extern void would_dump(struct linux_binprm *, struct file *);
  105. extern int suid_dumpable;
  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 transfer_args_to_stack(struct linux_binprm *bprm,
  114. unsigned long *sp_location);
  115. extern int bprm_change_interp(const char *interp, struct linux_binprm *bprm);
  116. int copy_string_kernel(const char *arg, struct linux_binprm *bprm);
  117. extern void set_binfmt(struct linux_binfmt *new);
  118. extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
  119. int kernel_execve(const char *filename,
  120. const char *const *argv, const char *const *envp);
  121. #endif /* _LINUX_BINFMTS_H */