~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/binfmt_em86.c

Version: ~ [ linux-5.13-rc7 ] ~ [ linux-5.12.12 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.45 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.127 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.195 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.237 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.273 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.273 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  *  linux/fs/binfmt_em86.c
  4  *
  5  *  Based on linux/fs/binfmt_script.c
  6  *  Copyright (C) 1996  Martin von Löwis
  7  *  original #!-checking implemented by tytso.
  8  *
  9  *  em86 changes Copyright (C) 1997  Jim Paradis
 10  */
 11 
 12 #include <linux/module.h>
 13 #include <linux/string.h>
 14 #include <linux/stat.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 
 26 static int load_em86(struct linux_binprm *bprm)
 27 {
 28         const char *i_name, *i_arg;
 29         char *interp;
 30         struct file * file;
 31         int retval;
 32         struct elfhdr   elf_ex;
 33 
 34         /* Make sure this is a Linux/Intel ELF executable... */
 35         elf_ex = *((struct elfhdr *)bprm->buf);
 36 
 37         if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
 38                 return  -ENOEXEC;
 39 
 40         /* First of all, some simple consistency checks */
 41         if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
 42                 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
 43                 !bprm->file->f_op->mmap) {
 44                         return -ENOEXEC;
 45         }
 46 
 47         /* Need to be able to load the file after exec */
 48         if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
 49                 return -ENOENT;
 50 
 51         allow_write_access(bprm->file);
 52         fput(bprm->file);
 53         bprm->file = NULL;
 54 
 55         /* Unlike in the script case, we don't have to do any hairy
 56          * parsing to find our interpreter... it's hardcoded!
 57          */
 58         interp = EM86_INTERP;
 59         i_name = EM86_I_NAME;
 60         i_arg = NULL;           /* We reserve the right to add an arg later */
 61 
 62         /*
 63          * Splice in (1) the interpreter's name for argv[0]
 64          *           (2) (optional) argument to interpreter
 65          *           (3) filename of emulated file (replace argv[0])
 66          *
 67          * This is done in reverse order, because of how the
 68          * user environment and arguments are stored.
 69          */
 70         remove_arg_zero(bprm);
 71         retval = copy_strings_kernel(1, &bprm->filename, bprm);
 72         if (retval < 0) return retval; 
 73         bprm->argc++;
 74         if (i_arg) {
 75                 retval = copy_strings_kernel(1, &i_arg, bprm);
 76                 if (retval < 0) return retval; 
 77                 bprm->argc++;
 78         }
 79         retval = copy_strings_kernel(1, &i_name, bprm);
 80         if (retval < 0) return retval;
 81         bprm->argc++;
 82 
 83         /*
 84          * OK, now restart the process with the interpreter's inode.
 85          * Note that we use open_exec() as the name is now in kernel
 86          * space, and we don't need to copy it.
 87          */
 88         file = open_exec(interp);
 89         if (IS_ERR(file))
 90                 return PTR_ERR(file);
 91 
 92         bprm->file = file;
 93 
 94         retval = prepare_binprm(bprm);
 95         if (retval < 0)
 96                 return retval;
 97 
 98         return search_binary_handler(bprm);
 99 }
100 
101 static struct linux_binfmt em86_format = {
102         .module         = THIS_MODULE,
103         .load_binary    = load_em86,
104 };
105 
106 static int __init init_em86_binfmt(void)
107 {
108         register_binfmt(&em86_format);
109         return 0;
110 }
111 
112 static void __exit exit_em86_binfmt(void)
113 {
114         unregister_binfmt(&em86_format);
115 }
116 
117 core_initcall(init_em86_binfmt);
118 module_exit(exit_em86_binfmt);
119 MODULE_LICENSE("GPL");
120 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp