binfmts.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/list.h>
  17. #define CORENAME_MAX_SIZE 128
  18. /*
  19. * This structure is used to hold the arguments that are used when loading binaries.
  20. */
  21. struct linux_binprm{
  22. char buf[BINPRM_BUF_SIZE];
  23. #ifdef CONFIG_MMU
  24. struct vm_area_struct *vma;
  25. #else
  26. # define MAX_ARG_PAGES 32
  27. struct page *page[MAX_ARG_PAGES];
  28. #endif
  29. struct mm_struct *mm;
  30. unsigned long p; /* current top of mem */
  31. unsigned int
  32. cred_prepared:1,/* true if creds already prepared (multiple
  33. * preps happen for interpreters) */
  34. cap_effective:1;/* true if has elevated effective capabilities,
  35. * false if not; except for init which inherits
  36. * its parent's caps anyway */
  37. #ifdef __alpha__
  38. unsigned int taso:1;
  39. #endif
  40. unsigned int recursion_depth;
  41. struct file * file;
  42. struct cred *cred; /* new credentials */
  43. int unsafe; /* how unsafe this exec is (mask of LSM_UNSAFE_*) */
  44. unsigned int per_clear; /* bits to clear in current->personality */
  45. int argc, envc;
  46. char * filename; /* Name of binary as seen by procps */
  47. char * interp; /* Name of the binary really executed. Most
  48. of the time same as filename, but could be
  49. different for binfmt_{misc,script} */
  50. unsigned interp_flags;
  51. unsigned interp_data;
  52. unsigned long loader, exec;
  53. };
  54. #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
  55. #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
  56. /* fd of the binary should be passed to the interpreter */
  57. #define BINPRM_FLAGS_EXECFD_BIT 1
  58. #define BINPRM_FLAGS_EXECFD (1 << BINPRM_FLAGS_EXECFD_BIT)
  59. #define BINPRM_MAX_RECURSION 4
  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 *, struct pt_regs * regs);
  68. int (*load_shlib)(struct file *);
  69. int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
  70. unsigned long min_coredump; /* minimal dump size */
  71. int hasvdso;
  72. };
  73. extern int __register_binfmt(struct linux_binfmt *fmt, int insert);
  74. /* Registration of default binfmt handlers */
  75. static inline int register_binfmt(struct linux_binfmt *fmt)
  76. {
  77. return __register_binfmt(fmt, 0);
  78. }
  79. /* Same as above, but adds a new binfmt at the top of the list */
  80. static inline int insert_binfmt(struct linux_binfmt *fmt)
  81. {
  82. return __register_binfmt(fmt, 1);
  83. }
  84. extern void unregister_binfmt(struct linux_binfmt *);
  85. extern int prepare_binprm(struct linux_binprm *);
  86. extern int __must_check remove_arg_zero(struct linux_binprm *);
  87. extern int search_binary_handler(struct linux_binprm *,struct pt_regs *);
  88. extern int flush_old_exec(struct linux_binprm * bprm);
  89. extern int suid_dumpable;
  90. #define SUID_DUMP_DISABLE 0 /* No setuid dumping */
  91. #define SUID_DUMP_USER 1 /* Dump as user of process */
  92. #define SUID_DUMP_ROOT 2 /* Dump as root */
  93. /* Stack area protections */
  94. #define EXSTACK_DEFAULT 0 /* Whatever the arch defaults to */
  95. #define EXSTACK_DISABLE_X 1 /* Disable executable stacks */
  96. #define EXSTACK_ENABLE_X 2 /* Enable executable stacks */
  97. extern int setup_arg_pages(struct linux_binprm * bprm,
  98. unsigned long stack_top,
  99. int executable_stack);
  100. extern int bprm_mm_init(struct linux_binprm *bprm);
  101. extern int copy_strings_kernel(int argc,char ** argv,struct linux_binprm *bprm);
  102. extern int prepare_bprm_creds(struct linux_binprm *bprm);
  103. extern void install_exec_creds(struct linux_binprm *bprm);
  104. extern void do_coredump(long signr, int exit_code, struct pt_regs *regs);
  105. extern int set_binfmt(struct linux_binfmt *new);
  106. extern void free_bprm(struct linux_binprm *);
  107. #endif /* __KERNEL__ */
  108. #endif /* _LINUX_BINFMTS_H */