1
2
3
4
5
6
7
8
9
10
11#include <linux/module.h>
12#include <linux/string.h>
13#include <linux/stat.h>
14#include <linux/slab.h>
15#include <linux/binfmts.h>
16#include <linux/elf.h>
17#include <linux/init.h>
18#include <linux/fs.h>
19#include <linux/file.h>
20#include <linux/errno.h>
21
22
23#define EM86_INTERP "/usr/bin/em86"
24#define EM86_I_NAME "em86"
25
26static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
27{
28 char *interp, *i_name, *i_arg;
29 struct file * file;
30 int retval;
31 struct elfhdr elf_ex;
32
33
34 elf_ex = *((struct elfhdr *)bprm->buf);
35
36 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
37 return -ENOEXEC;
38
39
40 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
41 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
42 (!bprm->file->f_op || !bprm->file->f_op->mmap)) {
43 return -ENOEXEC;
44 }
45
46 bprm->recursion_depth++;
47 allow_write_access(bprm->file);
48 fput(bprm->file);
49 bprm->file = NULL;
50
51
52
53
54 interp = EM86_INTERP;
55 i_name = EM86_I_NAME;
56 i_arg = NULL;
57
58
59
60
61
62
63
64
65
66 remove_arg_zero(bprm);
67 retval = copy_strings_kernel(1, &bprm->filename, bprm);
68 if (retval < 0) return retval;
69 bprm->argc++;
70 if (i_arg) {
71 retval = copy_strings_kernel(1, &i_arg, bprm);
72 if (retval < 0) return retval;
73 bprm->argc++;
74 }
75 retval = copy_strings_kernel(1, &i_name, bprm);
76 if (retval < 0) return retval;
77 bprm->argc++;
78
79
80
81
82
83
84 file = open_exec(interp);
85 if (IS_ERR(file))
86 return PTR_ERR(file);
87
88 bprm->file = file;
89
90 retval = prepare_binprm(bprm);
91 if (retval < 0)
92 return retval;
93
94 return search_binary_handler(bprm, regs);
95}
96
97static struct linux_binfmt em86_format = {
98 .module = THIS_MODULE,
99 .load_binary = load_em86,
100};
101
102static int __init init_em86_binfmt(void)
103{
104 return register_binfmt(&em86_format);
105}
106
107static void __exit exit_em86_binfmt(void)
108{
109 unregister_binfmt(&em86_format);
110}
111
112core_initcall(init_em86_binfmt);
113module_exit(exit_em86_binfmt);
114MODULE_LICENSE("GPL");
115