Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_BINFMTS_H
0003 #define _LINUX_BINFMTS_H
0004 
0005 #include <linux/sched.h>
0006 #include <linux/unistd.h>
0007 #include <asm/exec.h>
0008 #include <uapi/linux/binfmts.h>
0009 
0010 struct filename;
0011 struct coredump_params;
0012 
0013 #define CORENAME_MAX_SIZE 128
0014 
0015 /*
0016  * This structure is used to hold the arguments that are used when loading binaries.
0017  */
0018 struct linux_binprm {
0019 #ifdef CONFIG_MMU
0020     struct vm_area_struct *vma;
0021     unsigned long vma_pages;
0022 #else
0023 # define MAX_ARG_PAGES  32
0024     struct page *page[MAX_ARG_PAGES];
0025 #endif
0026     struct mm_struct *mm;
0027     unsigned long p; /* current top of mem */
0028     unsigned long argmin; /* rlimit marker for copy_strings() */
0029     unsigned int
0030         /* Should an execfd be passed to userspace? */
0031         have_execfd:1,
0032 
0033         /* Use the creds of a script (see binfmt_misc) */
0034         execfd_creds:1,
0035         /*
0036          * Set by bprm_creds_for_exec hook to indicate a
0037          * privilege-gaining exec has happened. Used to set
0038          * AT_SECURE auxv for glibc.
0039          */
0040         secureexec:1,
0041         /*
0042          * Set when errors can no longer be returned to the
0043          * original userspace.
0044          */
0045         point_of_no_return:1;
0046 #ifdef __alpha__
0047     unsigned int taso:1;
0048 #endif
0049     struct file *executable; /* Executable to pass to the interpreter */
0050     struct file *interpreter;
0051     struct file *file;
0052     struct cred *cred;  /* new credentials */
0053     int unsafe;     /* how unsafe this exec is (mask of LSM_UNSAFE_*) */
0054     unsigned int per_clear; /* bits to clear in current->personality */
0055     int argc, envc;
0056     const char *filename;   /* Name of binary as seen by procps */
0057     const char *interp; /* Name of the binary really executed. Most
0058                    of the time same as filename, but could be
0059                    different for binfmt_{misc,script} */
0060     const char *fdpath; /* generated filename for execveat */
0061     unsigned interp_flags;
0062     int execfd;     /* File descriptor of the executable */
0063     unsigned long loader, exec;
0064 
0065     struct rlimit rlim_stack; /* Saved RLIMIT_STACK used during exec. */
0066 
0067     char buf[BINPRM_BUF_SIZE];
0068 } __randomize_layout;
0069 
0070 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
0071 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
0072 
0073 /* filename of the binary will be inaccessible after exec */
0074 #define BINPRM_FLAGS_PATH_INACCESSIBLE_BIT 2
0075 #define BINPRM_FLAGS_PATH_INACCESSIBLE (1 << BINPRM_FLAGS_PATH_INACCESSIBLE_BIT)
0076 
0077 /* preserve argv0 for the interpreter  */
0078 #define BINPRM_FLAGS_PRESERVE_ARGV0_BIT 3
0079 #define BINPRM_FLAGS_PRESERVE_ARGV0 (1 << BINPRM_FLAGS_PRESERVE_ARGV0_BIT)
0080 
0081 /*
0082  * This structure defines the functions that are used to load the binary formats that
0083  * linux accepts.
0084  */
0085 struct linux_binfmt {
0086     struct list_head lh;
0087     struct module *module;
0088     int (*load_binary)(struct linux_binprm *);
0089     int (*load_shlib)(struct file *);
0090 #ifdef CONFIG_COREDUMP
0091     int (*core_dump)(struct coredump_params *cprm);
0092     unsigned long min_coredump; /* minimal dump size */
0093 #endif
0094 } __randomize_layout;
0095 
0096 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
0097 
0098 /* Registration of default binfmt handlers */
0099 static inline void register_binfmt(struct linux_binfmt *fmt)
0100 {
0101     __register_binfmt(fmt, 0);
0102 }
0103 /* Same as above, but adds a new binfmt at the top of the list */
0104 static inline void insert_binfmt(struct linux_binfmt *fmt)
0105 {
0106     __register_binfmt(fmt, 1);
0107 }
0108 
0109 extern void unregister_binfmt(struct linux_binfmt *);
0110 
0111 extern int __must_check remove_arg_zero(struct linux_binprm *);
0112 extern int begin_new_exec(struct linux_binprm * bprm);
0113 extern void setup_new_exec(struct linux_binprm * bprm);
0114 extern void finalize_exec(struct linux_binprm *bprm);
0115 extern void would_dump(struct linux_binprm *, struct file *);
0116 
0117 extern int suid_dumpable;
0118 
0119 /* Stack area protections */
0120 #define EXSTACK_DEFAULT   0 /* Whatever the arch defaults to */
0121 #define EXSTACK_DISABLE_X 1 /* Disable executable stacks */
0122 #define EXSTACK_ENABLE_X  2 /* Enable executable stacks */
0123 
0124 extern int setup_arg_pages(struct linux_binprm * bprm,
0125                unsigned long stack_top,
0126                int executable_stack);
0127 extern int transfer_args_to_stack(struct linux_binprm *bprm,
0128                   unsigned long *sp_location);
0129 extern int bprm_change_interp(const char *interp, struct linux_binprm *bprm);
0130 int copy_string_kernel(const char *arg, struct linux_binprm *bprm);
0131 extern void set_binfmt(struct linux_binfmt *new);
0132 extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
0133 
0134 int kernel_execve(const char *filename,
0135           const char *const *argv, const char *const *envp);
0136 
0137 #endif /* _LINUX_BINFMTS_H */