binfmts.h 4.2 KB

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