Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Al Viro | 3bfacef | 2009-01-03 07:16:33 +0000 | [diff] [blame] | 2 | #include <linux/init.h> |
| 3 | #include <linux/fs.h> |
| 4 | #include <linux/file.h> |
| 5 | #include <linux/mm_types.h> |
| 6 | #include <linux/binfmts.h> |
| 7 | #include <linux/a.out.h> |
| 8 | |
Al Viro | 71613c3 | 2012-10-20 22:00:48 -0400 | [diff] [blame] | 9 | static int load_binary(struct linux_binprm *bprm) |
Al Viro | 3bfacef | 2009-01-03 07:16:33 +0000 | [diff] [blame] | 10 | { |
| 11 | struct exec *eh = (struct exec *)bprm->buf; |
| 12 | unsigned long loader; |
| 13 | struct file *file; |
| 14 | int retval; |
| 15 | |
| 16 | if (eh->fh.f_magic != 0x183 || (eh->fh.f_flags & 0x3000) != 0x3000) |
| 17 | return -ENOEXEC; |
| 18 | |
| 19 | if (bprm->loader) |
| 20 | return -ENOEXEC; |
| 21 | |
Al Viro | 3bfacef | 2009-01-03 07:16:33 +0000 | [diff] [blame] | 22 | loader = bprm->vma->vm_end - sizeof(void *); |
| 23 | |
| 24 | file = open_exec("/sbin/loader"); |
| 25 | retval = PTR_ERR(file); |
| 26 | if (IS_ERR(file)) |
| 27 | return retval; |
| 28 | |
| 29 | /* Remember if the application is TASO. */ |
| 30 | bprm->taso = eh->ah.entry < 0x100000000UL; |
| 31 | |
Eric W. Biederman | bc2bf33 | 2020-05-18 18:43:20 -0500 | [diff] [blame] | 32 | bprm->interpreter = file; |
Al Viro | 3bfacef | 2009-01-03 07:16:33 +0000 | [diff] [blame] | 33 | bprm->loader = loader; |
Eric W. Biederman | bc2bf33 | 2020-05-18 18:43:20 -0500 | [diff] [blame] | 34 | return 0; |
Al Viro | 3bfacef | 2009-01-03 07:16:33 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static struct linux_binfmt loader_format = { |
| 38 | .load_binary = load_binary, |
| 39 | }; |
| 40 | |
| 41 | static int __init init_loader_binfmt(void) |
| 42 | { |
Al Viro | 8fc3dc5 | 2012-03-17 03:05:16 -0400 | [diff] [blame] | 43 | insert_binfmt(&loader_format); |
| 44 | return 0; |
Al Viro | 3bfacef | 2009-01-03 07:16:33 +0000 | [diff] [blame] | 45 | } |
| 46 | arch_initcall(init_loader_binfmt); |