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