blob: e4be7a543ecfd4dba7f50d2e7221a915a21897f9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Al Viro3bfacef2009-01-03 07:16:33 +00002#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 Viro71613c32012-10-20 22:00:48 -04009static int load_binary(struct linux_binprm *bprm)
Al Viro3bfacef2009-01-03 07:16:33 +000010{
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 Viro3bfacef2009-01-03 07:16:33 +000022 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. Biedermanbc2bf332020-05-18 18:43:20 -050032 bprm->interpreter = file;
Al Viro3bfacef2009-01-03 07:16:33 +000033 bprm->loader = loader;
Eric W. Biedermanbc2bf332020-05-18 18:43:20 -050034 return 0;
Al Viro3bfacef2009-01-03 07:16:33 +000035}
36
37static struct linux_binfmt loader_format = {
38 .load_binary = load_binary,
39};
40
41static int __init init_loader_binfmt(void)
42{
Al Viro8fc3dc52012-03-17 03:05:16 -040043 insert_binfmt(&loader_format);
44 return 0;
Al Viro3bfacef2009-01-03 07:16:33 +000045}
46arch_initcall(init_loader_binfmt);