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/binfmts.h>
15#include <linux/elf.h>
16#include <linux/init.h>
17#include <linux/fs.h>
18#include <linux/file.h>
19#include <linux/errno.h>
20
21
22#define EM86_INTERP "/usr/bin/em86"
23#define EM86_I_NAME "em86"
24
25static int load_em86(struct linux_binprm *bprm)
26{
27 const char *i_name, *i_arg;
28 char *interp;
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->mmap) {
43 return -ENOEXEC;
44 }
45
46
47 if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
48 return -ENOENT;
49
50 allow_write_access(bprm->file);
51 fput(bprm->file);
52 bprm->file = NULL;
53
54
55
56
57 interp = EM86_INTERP;
58 i_name = EM86_I_NAME;
59 i_arg = NULL;
60
61
62
63
64
65
66
67
68
69 remove_arg_zero(bprm);
70 retval = copy_strings_kernel(1, &bprm->filename, bprm);
71 if (retval < 0) return retval;
72 bprm->argc++;
73 if (i_arg) {
74 retval = copy_strings_kernel(1, &i_arg, bprm);
75 if (retval < 0) return retval;
76 bprm->argc++;
77 }
78 retval = copy_strings_kernel(1, &i_name, bprm);
79 if (retval < 0) return retval;
80 bprm->argc++;
81
82
83
84
85
86
87 file = open_exec(interp);
88 if (IS_ERR(file))
89 return PTR_ERR(file);
90
91 bprm->file = file;
92
93 retval = prepare_binprm(bprm);
94 if (retval < 0)
95 return retval;
96
97 return search_binary_handler(bprm);
98}
99
100static struct linux_binfmt em86_format = {
101 .module = THIS_MODULE,
102 .load_binary = load_em86,
103};
104
105static int __init init_em86_binfmt(void)
106{
107 register_binfmt(&em86_format);
108 return 0;
109}
110
111static void __exit exit_em86_binfmt(void)
112{
113 unregister_binfmt(&em86_format);
114}
115
116core_initcall(init_em86_binfmt);
117module_exit(exit_em86_binfmt);
118MODULE_LICENSE("GPL");
119