binfmts.h 4.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef _LINUX_BINFMTS_H
#define _LINUX_BINFMTS_H

4
#include <linux/sched.h>
A
Al Viro 已提交
5
#include <linux/unistd.h>
6
#include <asm/exec.h>
7
#include <uapi/linux/binfmts.h>
L
Linus Torvalds 已提交
8

9 10
#define CORENAME_MAX_SIZE 128

L
Linus Torvalds 已提交
11 12 13
/*
 * This structure is used to hold the arguments that are used when loading binaries.
 */
M
Mikael Pettersson 已提交
14
struct linux_binprm {
L
Linus Torvalds 已提交
15
	char buf[BINPRM_BUF_SIZE];
16 17
#ifdef CONFIG_MMU
	struct vm_area_struct *vma;
18
	unsigned long vma_pages;
19 20
#else
# define MAX_ARG_PAGES	32
L
Linus Torvalds 已提交
21
	struct page *page[MAX_ARG_PAGES];
22
#endif
L
Linus Torvalds 已提交
23 24
	struct mm_struct *mm;
	unsigned long p; /* current top of mem */
25
	unsigned int
26 27 28 29 30
		cred_prepared:1,/* true if creds already prepared (multiple
				 * preps happen for interpreters) */
		cap_effective:1;/* true if has elevated effective capabilities,
				 * false if not; except for init which inherits
				 * its parent's caps anyway */
31 32 33
#ifdef __alpha__
	unsigned int taso:1;
#endif
34
	unsigned int recursion_depth;
L
Linus Torvalds 已提交
35
	struct file * file;
36 37 38
	struct cred *cred;	/* new credentials */
	int unsafe;		/* how unsafe this exec is (mask of LSM_UNSAFE_*) */
	unsigned int per_clear;	/* bits to clear in current->personality */
L
Linus Torvalds 已提交
39
	int argc, envc;
40 41
	const char * filename;	/* Name of binary as seen by procps */
	const char * interp;	/* Name of the binary really executed. Most
L
Linus Torvalds 已提交
42 43 44 45 46
				   of the time same as filename, but could be
				   different for binfmt_{misc,script} */
	unsigned interp_flags;
	unsigned interp_data;
	unsigned long loader, exec;
47
	char tcomm[TASK_COMM_LEN];
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56
};

#define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
#define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)

/* fd of the binary should be passed to the interpreter */
#define BINPRM_FLAGS_EXECFD_BIT 1
#define BINPRM_FLAGS_EXECFD (1 << BINPRM_FLAGS_EXECFD_BIT)

57 58
/* Function parameter for binfmt->coredump */
struct coredump_params {
59
	siginfo_t *siginfo;
60 61 62
	struct pt_regs *regs;
	struct file *file;
	unsigned long limit;
63
	unsigned long mm_flags;
64 65
};

L
Linus Torvalds 已提交
66 67 68 69 70
/*
 * This structure defines the functions that are used to load the binary formats that
 * linux accepts.
 */
struct linux_binfmt {
A
Alexey Dobriyan 已提交
71
	struct list_head lh;
L
Linus Torvalds 已提交
72
	struct module *module;
73
	int (*load_binary)(struct linux_binprm *);
L
Linus Torvalds 已提交
74
	int (*load_shlib)(struct file *);
75
	int (*core_dump)(struct coredump_params *cprm);
L
Linus Torvalds 已提交
76 77 78
	unsigned long min_coredump;	/* minimal dump size */
};

A
Al Viro 已提交
79
extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
I
Ivan Kokshaysky 已提交
80 81

/* Registration of default binfmt handlers */
A
Al Viro 已提交
82
static inline void register_binfmt(struct linux_binfmt *fmt)
I
Ivan Kokshaysky 已提交
83
{
A
Al Viro 已提交
84
	__register_binfmt(fmt, 0);
I
Ivan Kokshaysky 已提交
85 86
}
/* Same as above, but adds a new binfmt at the top of the list */
A
Al Viro 已提交
87
static inline void insert_binfmt(struct linux_binfmt *fmt)
I
Ivan Kokshaysky 已提交
88
{
A
Al Viro 已提交
89
	__register_binfmt(fmt, 1);
I
Ivan Kokshaysky 已提交
90 91
}

92
extern void unregister_binfmt(struct linux_binfmt *);
L
Linus Torvalds 已提交
93 94

extern int prepare_binprm(struct linux_binprm *);
95
extern int __must_check remove_arg_zero(struct linux_binprm *);
96
extern int search_binary_handler(struct linux_binprm *);
L
Linus Torvalds 已提交
97
extern int flush_old_exec(struct linux_binprm * bprm);
98
extern void setup_new_exec(struct linux_binprm * bprm);
99
extern void would_dump(struct linux_binprm *, struct file *);
L
Linus Torvalds 已提交
100

A
Alan Cox 已提交
101 102 103 104 105
extern int suid_dumpable;
#define SUID_DUMP_DISABLE	0	/* No setuid dumping */
#define SUID_DUMP_USER		1	/* Dump as user of process */
#define SUID_DUMP_ROOT		2	/* Dump as root */

L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113
/* Stack area protections */
#define EXSTACK_DEFAULT   0	/* Whatever the arch defaults to */
#define EXSTACK_DISABLE_X 1	/* Disable executable stacks */
#define EXSTACK_ENABLE_X  2	/* Enable executable stacks */

extern int setup_arg_pages(struct linux_binprm * bprm,
			   unsigned long stack_top,
			   int executable_stack);
114
extern int bprm_mm_init(struct linux_binprm *bprm);
115
extern int bprm_change_interp(char *interp, struct linux_binprm *bprm);
116 117
extern int copy_strings_kernel(int argc, const char *const *argv,
			       struct linux_binprm *bprm);
118
extern int prepare_bprm_creds(struct linux_binprm *bprm);
119
extern void install_exec_creds(struct linux_binprm *bprm);
120
extern void set_binfmt(struct linux_binfmt *new);
121
extern void free_bprm(struct linux_binprm *);
L
Linus Torvalds 已提交
122

A
Al Viro 已提交
123 124 125 126
#ifdef __ARCH_WANT_KERNEL_EXECVE
extern void ret_from_kernel_execve(struct pt_regs *normal) __noreturn;
#endif

L
Linus Torvalds 已提交
127
#endif /* _LINUX_BINFMTS_H */