xref: /OK3568_Linux_fs/kernel/fs/binfmt_flat.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /****************************************************************************/
3*4882a593Smuzhiyun /*
4*4882a593Smuzhiyun  *  linux/fs/binfmt_flat.c
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *	Copyright (C) 2000-2003 David McCullough <davidm@snapgear.com>
7*4882a593Smuzhiyun  *	Copyright (C) 2002 Greg Ungerer <gerg@snapgear.com>
8*4882a593Smuzhiyun  *	Copyright (C) 2002 SnapGear, by Paul Dale <pauli@snapgear.com>
9*4882a593Smuzhiyun  *	Copyright (C) 2000, 2001 Lineo, by David McCullough <davidm@lineo.com>
10*4882a593Smuzhiyun  *  based heavily on:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *  linux/fs/binfmt_aout.c:
13*4882a593Smuzhiyun  *      Copyright (C) 1991, 1992, 1996  Linus Torvalds
14*4882a593Smuzhiyun  *  linux/fs/binfmt_flat.c for 2.0 kernel
15*4882a593Smuzhiyun  *	    Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>
16*4882a593Smuzhiyun  *	JAN/99 -- coded full program relocation (gerg@snapgear.com)
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include <linux/kernel.h>
22*4882a593Smuzhiyun #include <linux/sched.h>
23*4882a593Smuzhiyun #include <linux/sched/task_stack.h>
24*4882a593Smuzhiyun #include <linux/mm.h>
25*4882a593Smuzhiyun #include <linux/mman.h>
26*4882a593Smuzhiyun #include <linux/errno.h>
27*4882a593Smuzhiyun #include <linux/signal.h>
28*4882a593Smuzhiyun #include <linux/string.h>
29*4882a593Smuzhiyun #include <linux/fs.h>
30*4882a593Smuzhiyun #include <linux/file.h>
31*4882a593Smuzhiyun #include <linux/ptrace.h>
32*4882a593Smuzhiyun #include <linux/user.h>
33*4882a593Smuzhiyun #include <linux/slab.h>
34*4882a593Smuzhiyun #include <linux/binfmts.h>
35*4882a593Smuzhiyun #include <linux/personality.h>
36*4882a593Smuzhiyun #include <linux/init.h>
37*4882a593Smuzhiyun #include <linux/flat.h>
38*4882a593Smuzhiyun #include <linux/uaccess.h>
39*4882a593Smuzhiyun #include <linux/vmalloc.h>
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #include <asm/byteorder.h>
42*4882a593Smuzhiyun #include <asm/unaligned.h>
43*4882a593Smuzhiyun #include <asm/cacheflush.h>
44*4882a593Smuzhiyun #include <asm/page.h>
45*4882a593Smuzhiyun #include <asm/flat.h>
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #ifndef flat_get_relocate_addr
48*4882a593Smuzhiyun #define flat_get_relocate_addr(rel)	(rel)
49*4882a593Smuzhiyun #endif
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /****************************************************************************/
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun  * User data (data section and bss) needs to be aligned.
55*4882a593Smuzhiyun  * We pick 0x20 here because it is the max value elf2flt has always
56*4882a593Smuzhiyun  * used in producing FLAT files, and because it seems to be large
57*4882a593Smuzhiyun  * enough to make all the gcc alignment related tests happy.
58*4882a593Smuzhiyun  */
59*4882a593Smuzhiyun #define FLAT_DATA_ALIGN	(0x20)
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /*
62*4882a593Smuzhiyun  * User data (stack) also needs to be aligned.
63*4882a593Smuzhiyun  * Here we can be a bit looser than the data sections since this
64*4882a593Smuzhiyun  * needs to only meet arch ABI requirements.
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun #define FLAT_STACK_ALIGN	max_t(unsigned long, sizeof(void *), ARCH_SLAB_MINALIGN)
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun #define RELOC_FAILED 0xff00ff01		/* Relocation incorrect somewhere */
69*4882a593Smuzhiyun #define UNLOADED_LIB 0x7ff000ff		/* Placeholder for unused library */
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_SHARED_FLAT
72*4882a593Smuzhiyun #define	MAX_SHARED_LIBS			(4)
73*4882a593Smuzhiyun #else
74*4882a593Smuzhiyun #define	MAX_SHARED_LIBS			(1)
75*4882a593Smuzhiyun #endif
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun struct lib_info {
78*4882a593Smuzhiyun 	struct {
79*4882a593Smuzhiyun 		unsigned long start_code;		/* Start of text segment */
80*4882a593Smuzhiyun 		unsigned long start_data;		/* Start of data segment */
81*4882a593Smuzhiyun 		unsigned long start_brk;		/* End of data segment */
82*4882a593Smuzhiyun 		unsigned long text_len;			/* Length of text segment */
83*4882a593Smuzhiyun 		unsigned long entry;			/* Start address for this module */
84*4882a593Smuzhiyun 		unsigned long build_date;		/* When this one was compiled */
85*4882a593Smuzhiyun 		bool loaded;				/* Has this library been loaded? */
86*4882a593Smuzhiyun 	} lib_list[MAX_SHARED_LIBS];
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_SHARED_FLAT
90*4882a593Smuzhiyun static int load_flat_shared_library(int id, struct lib_info *p);
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun static int load_flat_binary(struct linux_binprm *);
94*4882a593Smuzhiyun static int flat_core_dump(struct coredump_params *cprm);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun static struct linux_binfmt flat_format = {
97*4882a593Smuzhiyun 	.module		= THIS_MODULE,
98*4882a593Smuzhiyun 	.load_binary	= load_flat_binary,
99*4882a593Smuzhiyun 	.core_dump	= flat_core_dump,
100*4882a593Smuzhiyun 	.min_coredump	= PAGE_SIZE
101*4882a593Smuzhiyun };
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /****************************************************************************/
104*4882a593Smuzhiyun /*
105*4882a593Smuzhiyun  * Routine writes a core dump image in the current directory.
106*4882a593Smuzhiyun  * Currently only a stub-function.
107*4882a593Smuzhiyun  */
108*4882a593Smuzhiyun 
flat_core_dump(struct coredump_params * cprm)109*4882a593Smuzhiyun static int flat_core_dump(struct coredump_params *cprm)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun 	pr_warn("Process %s:%d received signr %d and should have core dumped\n",
112*4882a593Smuzhiyun 		current->comm, current->pid, cprm->siginfo->si_signo);
113*4882a593Smuzhiyun 	return 1;
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /****************************************************************************/
117*4882a593Smuzhiyun /*
118*4882a593Smuzhiyun  * create_flat_tables() parses the env- and arg-strings in new user
119*4882a593Smuzhiyun  * memory and creates the pointer tables from them, and puts their
120*4882a593Smuzhiyun  * addresses on the "stack", recording the new stack pointer value.
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun 
create_flat_tables(struct linux_binprm * bprm,unsigned long arg_start)123*4882a593Smuzhiyun static int create_flat_tables(struct linux_binprm *bprm, unsigned long arg_start)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	char __user *p;
126*4882a593Smuzhiyun 	unsigned long __user *sp;
127*4882a593Smuzhiyun 	long i, len;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	p = (char __user *)arg_start;
130*4882a593Smuzhiyun 	sp = (unsigned long __user *)current->mm->start_stack;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	sp -= bprm->envc + 1;
133*4882a593Smuzhiyun 	sp -= bprm->argc + 1;
134*4882a593Smuzhiyun 	if (IS_ENABLED(CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK))
135*4882a593Smuzhiyun 		sp -= 2; /* argvp + envp */
136*4882a593Smuzhiyun 	sp -= 1;  /* &argc */
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	current->mm->start_stack = (unsigned long)sp & -FLAT_STACK_ALIGN;
139*4882a593Smuzhiyun 	sp = (unsigned long __user *)current->mm->start_stack;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	if (put_user(bprm->argc, sp++))
142*4882a593Smuzhiyun 		return -EFAULT;
143*4882a593Smuzhiyun 	if (IS_ENABLED(CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK)) {
144*4882a593Smuzhiyun 		unsigned long argv, envp;
145*4882a593Smuzhiyun 		argv = (unsigned long)(sp + 2);
146*4882a593Smuzhiyun 		envp = (unsigned long)(sp + 2 + bprm->argc + 1);
147*4882a593Smuzhiyun 		if (put_user(argv, sp++) || put_user(envp, sp++))
148*4882a593Smuzhiyun 			return -EFAULT;
149*4882a593Smuzhiyun 	}
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	current->mm->arg_start = (unsigned long)p;
152*4882a593Smuzhiyun 	for (i = bprm->argc; i > 0; i--) {
153*4882a593Smuzhiyun 		if (put_user((unsigned long)p, sp++))
154*4882a593Smuzhiyun 			return -EFAULT;
155*4882a593Smuzhiyun 		len = strnlen_user(p, MAX_ARG_STRLEN);
156*4882a593Smuzhiyun 		if (!len || len > MAX_ARG_STRLEN)
157*4882a593Smuzhiyun 			return -EINVAL;
158*4882a593Smuzhiyun 		p += len;
159*4882a593Smuzhiyun 	}
160*4882a593Smuzhiyun 	if (put_user(0, sp++))
161*4882a593Smuzhiyun 		return -EFAULT;
162*4882a593Smuzhiyun 	current->mm->arg_end = (unsigned long)p;
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	current->mm->env_start = (unsigned long) p;
165*4882a593Smuzhiyun 	for (i = bprm->envc; i > 0; i--) {
166*4882a593Smuzhiyun 		if (put_user((unsigned long)p, sp++))
167*4882a593Smuzhiyun 			return -EFAULT;
168*4882a593Smuzhiyun 		len = strnlen_user(p, MAX_ARG_STRLEN);
169*4882a593Smuzhiyun 		if (!len || len > MAX_ARG_STRLEN)
170*4882a593Smuzhiyun 			return -EINVAL;
171*4882a593Smuzhiyun 		p += len;
172*4882a593Smuzhiyun 	}
173*4882a593Smuzhiyun 	if (put_user(0, sp++))
174*4882a593Smuzhiyun 		return -EFAULT;
175*4882a593Smuzhiyun 	current->mm->env_end = (unsigned long)p;
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	return 0;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun /****************************************************************************/
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_ZFLAT
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun #include <linux/zlib.h>
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun #define LBUFSIZE	4000
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun /* gzip flag byte */
189*4882a593Smuzhiyun #define ASCII_FLAG   0x01 /* bit 0 set: file probably ASCII text */
190*4882a593Smuzhiyun #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
191*4882a593Smuzhiyun #define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
192*4882a593Smuzhiyun #define ORIG_NAME    0x08 /* bit 3 set: original file name present */
193*4882a593Smuzhiyun #define COMMENT      0x10 /* bit 4 set: file comment present */
194*4882a593Smuzhiyun #define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
195*4882a593Smuzhiyun #define RESERVED     0xC0 /* bit 6,7:   reserved */
196*4882a593Smuzhiyun 
decompress_exec(struct linux_binprm * bprm,loff_t fpos,char * dst,long len,int fd)197*4882a593Smuzhiyun static int decompress_exec(struct linux_binprm *bprm, loff_t fpos, char *dst,
198*4882a593Smuzhiyun 		long len, int fd)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun 	unsigned char *buf;
201*4882a593Smuzhiyun 	z_stream strm;
202*4882a593Smuzhiyun 	int ret, retval;
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun 	pr_debug("decompress_exec(offset=%llx,buf=%p,len=%lx)\n", fpos, dst, len);
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	memset(&strm, 0, sizeof(strm));
207*4882a593Smuzhiyun 	strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
208*4882a593Smuzhiyun 	if (!strm.workspace)
209*4882a593Smuzhiyun 		return -ENOMEM;
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	buf = kmalloc(LBUFSIZE, GFP_KERNEL);
212*4882a593Smuzhiyun 	if (!buf) {
213*4882a593Smuzhiyun 		retval = -ENOMEM;
214*4882a593Smuzhiyun 		goto out_free;
215*4882a593Smuzhiyun 	}
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun 	/* Read in first chunk of data and parse gzip header. */
218*4882a593Smuzhiyun 	ret = kernel_read(bprm->file, buf, LBUFSIZE, &fpos);
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	strm.next_in = buf;
221*4882a593Smuzhiyun 	strm.avail_in = ret;
222*4882a593Smuzhiyun 	strm.total_in = 0;
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	retval = -ENOEXEC;
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	/* Check minimum size -- gzip header */
227*4882a593Smuzhiyun 	if (ret < 10) {
228*4882a593Smuzhiyun 		pr_debug("file too small?\n");
229*4882a593Smuzhiyun 		goto out_free_buf;
230*4882a593Smuzhiyun 	}
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	/* Check gzip magic number */
233*4882a593Smuzhiyun 	if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) {
234*4882a593Smuzhiyun 		pr_debug("unknown compression magic?\n");
235*4882a593Smuzhiyun 		goto out_free_buf;
236*4882a593Smuzhiyun 	}
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 	/* Check gzip method */
239*4882a593Smuzhiyun 	if (buf[2] != 8) {
240*4882a593Smuzhiyun 		pr_debug("unknown compression method?\n");
241*4882a593Smuzhiyun 		goto out_free_buf;
242*4882a593Smuzhiyun 	}
243*4882a593Smuzhiyun 	/* Check gzip flags */
244*4882a593Smuzhiyun 	if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) ||
245*4882a593Smuzhiyun 	    (buf[3] & RESERVED)) {
246*4882a593Smuzhiyun 		pr_debug("unknown flags?\n");
247*4882a593Smuzhiyun 		goto out_free_buf;
248*4882a593Smuzhiyun 	}
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun 	ret = 10;
251*4882a593Smuzhiyun 	if (buf[3] & EXTRA_FIELD) {
252*4882a593Smuzhiyun 		ret += 2 + buf[10] + (buf[11] << 8);
253*4882a593Smuzhiyun 		if (unlikely(ret >= LBUFSIZE)) {
254*4882a593Smuzhiyun 			pr_debug("buffer overflow (EXTRA)?\n");
255*4882a593Smuzhiyun 			goto out_free_buf;
256*4882a593Smuzhiyun 		}
257*4882a593Smuzhiyun 	}
258*4882a593Smuzhiyun 	if (buf[3] & ORIG_NAME) {
259*4882a593Smuzhiyun 		while (ret < LBUFSIZE && buf[ret++] != 0)
260*4882a593Smuzhiyun 			;
261*4882a593Smuzhiyun 		if (unlikely(ret == LBUFSIZE)) {
262*4882a593Smuzhiyun 			pr_debug("buffer overflow (ORIG_NAME)?\n");
263*4882a593Smuzhiyun 			goto out_free_buf;
264*4882a593Smuzhiyun 		}
265*4882a593Smuzhiyun 	}
266*4882a593Smuzhiyun 	if (buf[3] & COMMENT) {
267*4882a593Smuzhiyun 		while (ret < LBUFSIZE && buf[ret++] != 0)
268*4882a593Smuzhiyun 			;
269*4882a593Smuzhiyun 		if (unlikely(ret == LBUFSIZE)) {
270*4882a593Smuzhiyun 			pr_debug("buffer overflow (COMMENT)?\n");
271*4882a593Smuzhiyun 			goto out_free_buf;
272*4882a593Smuzhiyun 		}
273*4882a593Smuzhiyun 	}
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 	strm.next_in += ret;
276*4882a593Smuzhiyun 	strm.avail_in -= ret;
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun 	strm.next_out = dst;
279*4882a593Smuzhiyun 	strm.avail_out = len;
280*4882a593Smuzhiyun 	strm.total_out = 0;
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun 	if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) {
283*4882a593Smuzhiyun 		pr_debug("zlib init failed?\n");
284*4882a593Smuzhiyun 		goto out_free_buf;
285*4882a593Smuzhiyun 	}
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun 	while ((ret = zlib_inflate(&strm, Z_NO_FLUSH)) == Z_OK) {
288*4882a593Smuzhiyun 		ret = kernel_read(bprm->file, buf, LBUFSIZE, &fpos);
289*4882a593Smuzhiyun 		if (ret <= 0)
290*4882a593Smuzhiyun 			break;
291*4882a593Smuzhiyun 		len -= ret;
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun 		strm.next_in = buf;
294*4882a593Smuzhiyun 		strm.avail_in = ret;
295*4882a593Smuzhiyun 		strm.total_in = 0;
296*4882a593Smuzhiyun 	}
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	if (ret < 0) {
299*4882a593Smuzhiyun 		pr_debug("decompression failed (%d), %s\n",
300*4882a593Smuzhiyun 			ret, strm.msg);
301*4882a593Smuzhiyun 		goto out_zlib;
302*4882a593Smuzhiyun 	}
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	retval = 0;
305*4882a593Smuzhiyun out_zlib:
306*4882a593Smuzhiyun 	zlib_inflateEnd(&strm);
307*4882a593Smuzhiyun out_free_buf:
308*4882a593Smuzhiyun 	kfree(buf);
309*4882a593Smuzhiyun out_free:
310*4882a593Smuzhiyun 	kfree(strm.workspace);
311*4882a593Smuzhiyun 	return retval;
312*4882a593Smuzhiyun }
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun #endif /* CONFIG_BINFMT_ZFLAT */
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /****************************************************************************/
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun static unsigned long
calc_reloc(unsigned long r,struct lib_info * p,int curid,int internalp)319*4882a593Smuzhiyun calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun 	unsigned long addr;
322*4882a593Smuzhiyun 	int id;
323*4882a593Smuzhiyun 	unsigned long start_brk;
324*4882a593Smuzhiyun 	unsigned long start_data;
325*4882a593Smuzhiyun 	unsigned long text_len;
326*4882a593Smuzhiyun 	unsigned long start_code;
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_SHARED_FLAT
329*4882a593Smuzhiyun 	if (r == 0)
330*4882a593Smuzhiyun 		id = curid;	/* Relocs of 0 are always self referring */
331*4882a593Smuzhiyun 	else {
332*4882a593Smuzhiyun 		id = (r >> 24) & 0xff;	/* Find ID for this reloc */
333*4882a593Smuzhiyun 		r &= 0x00ffffff;	/* Trim ID off here */
334*4882a593Smuzhiyun 	}
335*4882a593Smuzhiyun 	if (id >= MAX_SHARED_LIBS) {
336*4882a593Smuzhiyun 		pr_err("reference 0x%lx to shared library %d", r, id);
337*4882a593Smuzhiyun 		goto failed;
338*4882a593Smuzhiyun 	}
339*4882a593Smuzhiyun 	if (curid != id) {
340*4882a593Smuzhiyun 		if (internalp) {
341*4882a593Smuzhiyun 			pr_err("reloc address 0x%lx not in same module "
342*4882a593Smuzhiyun 			       "(%d != %d)", r, curid, id);
343*4882a593Smuzhiyun 			goto failed;
344*4882a593Smuzhiyun 		} else if (!p->lib_list[id].loaded &&
345*4882a593Smuzhiyun 			   load_flat_shared_library(id, p) < 0) {
346*4882a593Smuzhiyun 			pr_err("failed to load library %d", id);
347*4882a593Smuzhiyun 			goto failed;
348*4882a593Smuzhiyun 		}
349*4882a593Smuzhiyun 		/* Check versioning information (i.e. time stamps) */
350*4882a593Smuzhiyun 		if (p->lib_list[id].build_date && p->lib_list[curid].build_date &&
351*4882a593Smuzhiyun 				p->lib_list[curid].build_date < p->lib_list[id].build_date) {
352*4882a593Smuzhiyun 			pr_err("library %d is younger than %d", id, curid);
353*4882a593Smuzhiyun 			goto failed;
354*4882a593Smuzhiyun 		}
355*4882a593Smuzhiyun 	}
356*4882a593Smuzhiyun #else
357*4882a593Smuzhiyun 	id = 0;
358*4882a593Smuzhiyun #endif
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun 	start_brk = p->lib_list[id].start_brk;
361*4882a593Smuzhiyun 	start_data = p->lib_list[id].start_data;
362*4882a593Smuzhiyun 	start_code = p->lib_list[id].start_code;
363*4882a593Smuzhiyun 	text_len = p->lib_list[id].text_len;
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun 	if (r > start_brk - start_data + text_len) {
366*4882a593Smuzhiyun 		pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
367*4882a593Smuzhiyun 		       r, start_brk-start_data+text_len, text_len);
368*4882a593Smuzhiyun 		goto failed;
369*4882a593Smuzhiyun 	}
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	if (r < text_len)			/* In text segment */
372*4882a593Smuzhiyun 		addr = r + start_code;
373*4882a593Smuzhiyun 	else					/* In data segment */
374*4882a593Smuzhiyun 		addr = r - text_len + start_data;
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	/* Range checked already above so doing the range tests is redundant...*/
377*4882a593Smuzhiyun 	return addr;
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun failed:
380*4882a593Smuzhiyun 	pr_cont(", killing %s!\n", current->comm);
381*4882a593Smuzhiyun 	send_sig(SIGSEGV, current, 0);
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun 	return RELOC_FAILED;
384*4882a593Smuzhiyun }
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun /****************************************************************************/
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_FLAT_OLD
old_reloc(unsigned long rl)389*4882a593Smuzhiyun static void old_reloc(unsigned long rl)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun 	static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
392*4882a593Smuzhiyun 	flat_v2_reloc_t	r;
393*4882a593Smuzhiyun 	unsigned long __user *ptr;
394*4882a593Smuzhiyun 	unsigned long val;
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun 	r.value = rl;
397*4882a593Smuzhiyun #if defined(CONFIG_COLDFIRE)
398*4882a593Smuzhiyun 	ptr = (unsigned long __user *)(current->mm->start_code + r.reloc.offset);
399*4882a593Smuzhiyun #else
400*4882a593Smuzhiyun 	ptr = (unsigned long __user *)(current->mm->start_data + r.reloc.offset);
401*4882a593Smuzhiyun #endif
402*4882a593Smuzhiyun 	get_user(val, ptr);
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	pr_debug("Relocation of variable at DATASEG+%x "
405*4882a593Smuzhiyun 		 "(address %p, currently %lx) into segment %s\n",
406*4882a593Smuzhiyun 		 r.reloc.offset, ptr, val, segment[r.reloc.type]);
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun 	switch (r.reloc.type) {
409*4882a593Smuzhiyun 	case OLD_FLAT_RELOC_TYPE_TEXT:
410*4882a593Smuzhiyun 		val += current->mm->start_code;
411*4882a593Smuzhiyun 		break;
412*4882a593Smuzhiyun 	case OLD_FLAT_RELOC_TYPE_DATA:
413*4882a593Smuzhiyun 		val += current->mm->start_data;
414*4882a593Smuzhiyun 		break;
415*4882a593Smuzhiyun 	case OLD_FLAT_RELOC_TYPE_BSS:
416*4882a593Smuzhiyun 		val += current->mm->end_data;
417*4882a593Smuzhiyun 		break;
418*4882a593Smuzhiyun 	default:
419*4882a593Smuzhiyun 		pr_err("Unknown relocation type=%x\n", r.reloc.type);
420*4882a593Smuzhiyun 		break;
421*4882a593Smuzhiyun 	}
422*4882a593Smuzhiyun 	put_user(val, ptr);
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun 	pr_debug("Relocation became %lx\n", val);
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun #endif /* CONFIG_BINFMT_FLAT_OLD */
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun /****************************************************************************/
429*4882a593Smuzhiyun 
skip_got_header(u32 __user * rp)430*4882a593Smuzhiyun static inline u32 __user *skip_got_header(u32 __user *rp)
431*4882a593Smuzhiyun {
432*4882a593Smuzhiyun 	if (IS_ENABLED(CONFIG_RISCV)) {
433*4882a593Smuzhiyun 		/*
434*4882a593Smuzhiyun 		 * RISC-V has a 16 byte GOT PLT header for elf64-riscv
435*4882a593Smuzhiyun 		 * and 8 byte GOT PLT header for elf32-riscv.
436*4882a593Smuzhiyun 		 * Skip the whole GOT PLT header, since it is reserved
437*4882a593Smuzhiyun 		 * for the dynamic linker (ld.so).
438*4882a593Smuzhiyun 		 */
439*4882a593Smuzhiyun 		u32 rp_val0, rp_val1;
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun 		if (get_user(rp_val0, rp))
442*4882a593Smuzhiyun 			return rp;
443*4882a593Smuzhiyun 		if (get_user(rp_val1, rp + 1))
444*4882a593Smuzhiyun 			return rp;
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun 		if (rp_val0 == 0xffffffff && rp_val1 == 0xffffffff)
447*4882a593Smuzhiyun 			rp += 4;
448*4882a593Smuzhiyun 		else if (rp_val0 == 0xffffffff)
449*4882a593Smuzhiyun 			rp += 2;
450*4882a593Smuzhiyun 	}
451*4882a593Smuzhiyun 	return rp;
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun 
load_flat_file(struct linux_binprm * bprm,struct lib_info * libinfo,int id,unsigned long * extra_stack)454*4882a593Smuzhiyun static int load_flat_file(struct linux_binprm *bprm,
455*4882a593Smuzhiyun 		struct lib_info *libinfo, int id, unsigned long *extra_stack)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun 	struct flat_hdr *hdr;
458*4882a593Smuzhiyun 	unsigned long textpos, datapos, realdatastart;
459*4882a593Smuzhiyun 	u32 text_len, data_len, bss_len, stack_len, full_data, flags;
460*4882a593Smuzhiyun 	unsigned long len, memp, memp_size, extra, rlim;
461*4882a593Smuzhiyun 	__be32 __user *reloc;
462*4882a593Smuzhiyun 	u32 __user *rp;
463*4882a593Smuzhiyun 	int i, rev, relocs;
464*4882a593Smuzhiyun 	loff_t fpos;
465*4882a593Smuzhiyun 	unsigned long start_code, end_code;
466*4882a593Smuzhiyun 	ssize_t result;
467*4882a593Smuzhiyun 	int ret;
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 	hdr = ((struct flat_hdr *) bprm->buf);		/* exec-header */
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun 	text_len  = ntohl(hdr->data_start);
472*4882a593Smuzhiyun 	data_len  = ntohl(hdr->data_end) - ntohl(hdr->data_start);
473*4882a593Smuzhiyun 	bss_len   = ntohl(hdr->bss_end) - ntohl(hdr->data_end);
474*4882a593Smuzhiyun 	stack_len = ntohl(hdr->stack_size);
475*4882a593Smuzhiyun 	if (extra_stack) {
476*4882a593Smuzhiyun 		stack_len += *extra_stack;
477*4882a593Smuzhiyun 		*extra_stack = stack_len;
478*4882a593Smuzhiyun 	}
479*4882a593Smuzhiyun 	relocs    = ntohl(hdr->reloc_count);
480*4882a593Smuzhiyun 	flags     = ntohl(hdr->flags);
481*4882a593Smuzhiyun 	rev       = ntohl(hdr->rev);
482*4882a593Smuzhiyun 	full_data = data_len + relocs * sizeof(unsigned long);
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun 	if (strncmp(hdr->magic, "bFLT", 4)) {
485*4882a593Smuzhiyun 		/*
486*4882a593Smuzhiyun 		 * Previously, here was a printk to tell people
487*4882a593Smuzhiyun 		 *   "BINFMT_FLAT: bad header magic".
488*4882a593Smuzhiyun 		 * But for the kernel which also use ELF FD-PIC format, this
489*4882a593Smuzhiyun 		 * error message is confusing.
490*4882a593Smuzhiyun 		 * because a lot of people do not manage to produce good
491*4882a593Smuzhiyun 		 */
492*4882a593Smuzhiyun 		ret = -ENOEXEC;
493*4882a593Smuzhiyun 		goto err;
494*4882a593Smuzhiyun 	}
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun 	if (flags & FLAT_FLAG_KTRACE)
497*4882a593Smuzhiyun 		pr_info("Loading file: %s\n", bprm->filename);
498*4882a593Smuzhiyun 
499*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_FLAT_OLD
500*4882a593Smuzhiyun 	if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
501*4882a593Smuzhiyun 		pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n",
502*4882a593Smuzhiyun 		       rev, FLAT_VERSION, OLD_FLAT_VERSION);
503*4882a593Smuzhiyun 		ret = -ENOEXEC;
504*4882a593Smuzhiyun 		goto err;
505*4882a593Smuzhiyun 	}
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun 	/* Don't allow old format executables to use shared libraries */
508*4882a593Smuzhiyun 	if (rev == OLD_FLAT_VERSION && id != 0) {
509*4882a593Smuzhiyun 		pr_err("shared libraries are not available before rev 0x%lx\n",
510*4882a593Smuzhiyun 		       FLAT_VERSION);
511*4882a593Smuzhiyun 		ret = -ENOEXEC;
512*4882a593Smuzhiyun 		goto err;
513*4882a593Smuzhiyun 	}
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun 	/*
516*4882a593Smuzhiyun 	 * fix up the flags for the older format,  there were all kinds
517*4882a593Smuzhiyun 	 * of endian hacks,  this only works for the simple cases
518*4882a593Smuzhiyun 	 */
519*4882a593Smuzhiyun 	if (rev == OLD_FLAT_VERSION &&
520*4882a593Smuzhiyun 	   (flags || IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM)))
521*4882a593Smuzhiyun 		flags = FLAT_FLAG_RAM;
522*4882a593Smuzhiyun 
523*4882a593Smuzhiyun #else /* CONFIG_BINFMT_FLAT_OLD */
524*4882a593Smuzhiyun 	if (rev != FLAT_VERSION) {
525*4882a593Smuzhiyun 		pr_err("bad flat file version 0x%x (supported 0x%lx)\n",
526*4882a593Smuzhiyun 		       rev, FLAT_VERSION);
527*4882a593Smuzhiyun 		ret = -ENOEXEC;
528*4882a593Smuzhiyun 		goto err;
529*4882a593Smuzhiyun 	}
530*4882a593Smuzhiyun #endif /* !CONFIG_BINFMT_FLAT_OLD */
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun 	/*
533*4882a593Smuzhiyun 	 * Make sure the header params are sane.
534*4882a593Smuzhiyun 	 * 28 bits (256 MB) is way more than reasonable in this case.
535*4882a593Smuzhiyun 	 * If some top bits are set we have probable binary corruption.
536*4882a593Smuzhiyun 	*/
537*4882a593Smuzhiyun 	if ((text_len | data_len | bss_len | stack_len | full_data) >> 28) {
538*4882a593Smuzhiyun 		pr_err("bad header\n");
539*4882a593Smuzhiyun 		ret = -ENOEXEC;
540*4882a593Smuzhiyun 		goto err;
541*4882a593Smuzhiyun 	}
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun #ifndef CONFIG_BINFMT_ZFLAT
544*4882a593Smuzhiyun 	if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {
545*4882a593Smuzhiyun 		pr_err("Support for ZFLAT executables is not enabled.\n");
546*4882a593Smuzhiyun 		ret = -ENOEXEC;
547*4882a593Smuzhiyun 		goto err;
548*4882a593Smuzhiyun 	}
549*4882a593Smuzhiyun #endif
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun 	/*
552*4882a593Smuzhiyun 	 * Check initial limits. This avoids letting people circumvent
553*4882a593Smuzhiyun 	 * size limits imposed on them by creating programs with large
554*4882a593Smuzhiyun 	 * arrays in the data or bss.
555*4882a593Smuzhiyun 	 */
556*4882a593Smuzhiyun 	rlim = rlimit(RLIMIT_DATA);
557*4882a593Smuzhiyun 	if (rlim >= RLIM_INFINITY)
558*4882a593Smuzhiyun 		rlim = ~0;
559*4882a593Smuzhiyun 	if (data_len + bss_len > rlim) {
560*4882a593Smuzhiyun 		ret = -ENOMEM;
561*4882a593Smuzhiyun 		goto err;
562*4882a593Smuzhiyun 	}
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	/* Flush all traces of the currently running executable */
565*4882a593Smuzhiyun 	if (id == 0) {
566*4882a593Smuzhiyun 		ret = begin_new_exec(bprm);
567*4882a593Smuzhiyun 		if (ret)
568*4882a593Smuzhiyun 			goto err;
569*4882a593Smuzhiyun 
570*4882a593Smuzhiyun 		/* OK, This is the point of no return */
571*4882a593Smuzhiyun 		set_personality(PER_LINUX_32BIT);
572*4882a593Smuzhiyun 		setup_new_exec(bprm);
573*4882a593Smuzhiyun 	}
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 	/*
576*4882a593Smuzhiyun 	 * calculate the extra space we need to map in
577*4882a593Smuzhiyun 	 */
578*4882a593Smuzhiyun 	extra = max_t(unsigned long, bss_len + stack_len,
579*4882a593Smuzhiyun 			relocs * sizeof(unsigned long));
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	/*
582*4882a593Smuzhiyun 	 * there are a couple of cases here,  the separate code/data
583*4882a593Smuzhiyun 	 * case,  and then the fully copied to RAM case which lumps
584*4882a593Smuzhiyun 	 * it all together.
585*4882a593Smuzhiyun 	 */
586*4882a593Smuzhiyun 	if (!IS_ENABLED(CONFIG_MMU) && !(flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP))) {
587*4882a593Smuzhiyun 		/*
588*4882a593Smuzhiyun 		 * this should give us a ROM ptr,  but if it doesn't we don't
589*4882a593Smuzhiyun 		 * really care
590*4882a593Smuzhiyun 		 */
591*4882a593Smuzhiyun 		pr_debug("ROM mapping of file (we hope)\n");
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun 		textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
594*4882a593Smuzhiyun 				  MAP_PRIVATE|MAP_EXECUTABLE, 0);
595*4882a593Smuzhiyun 		if (!textpos || IS_ERR_VALUE(textpos)) {
596*4882a593Smuzhiyun 			ret = textpos;
597*4882a593Smuzhiyun 			if (!textpos)
598*4882a593Smuzhiyun 				ret = -ENOMEM;
599*4882a593Smuzhiyun 			pr_err("Unable to mmap process text, errno %d\n", ret);
600*4882a593Smuzhiyun 			goto err;
601*4882a593Smuzhiyun 		}
602*4882a593Smuzhiyun 
603*4882a593Smuzhiyun 		len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
604*4882a593Smuzhiyun 		len = PAGE_ALIGN(len);
605*4882a593Smuzhiyun 		realdatastart = vm_mmap(NULL, 0, len,
606*4882a593Smuzhiyun 			PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
607*4882a593Smuzhiyun 
608*4882a593Smuzhiyun 		if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) {
609*4882a593Smuzhiyun 			ret = realdatastart;
610*4882a593Smuzhiyun 			if (!realdatastart)
611*4882a593Smuzhiyun 				ret = -ENOMEM;
612*4882a593Smuzhiyun 			pr_err("Unable to allocate RAM for process data, "
613*4882a593Smuzhiyun 			       "errno %d\n", ret);
614*4882a593Smuzhiyun 			vm_munmap(textpos, text_len);
615*4882a593Smuzhiyun 			goto err;
616*4882a593Smuzhiyun 		}
617*4882a593Smuzhiyun 		datapos = ALIGN(realdatastart +
618*4882a593Smuzhiyun 				MAX_SHARED_LIBS * sizeof(unsigned long),
619*4882a593Smuzhiyun 				FLAT_DATA_ALIGN);
620*4882a593Smuzhiyun 
621*4882a593Smuzhiyun 		pr_debug("Allocated data+bss+stack (%u bytes): %lx\n",
622*4882a593Smuzhiyun 			 data_len + bss_len + stack_len, datapos);
623*4882a593Smuzhiyun 
624*4882a593Smuzhiyun 		fpos = ntohl(hdr->data_start);
625*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_ZFLAT
626*4882a593Smuzhiyun 		if (flags & FLAT_FLAG_GZDATA) {
627*4882a593Smuzhiyun 			result = decompress_exec(bprm, fpos, (char *)datapos,
628*4882a593Smuzhiyun 						 full_data, 0);
629*4882a593Smuzhiyun 		} else
630*4882a593Smuzhiyun #endif
631*4882a593Smuzhiyun 		{
632*4882a593Smuzhiyun 			result = read_code(bprm->file, datapos, fpos,
633*4882a593Smuzhiyun 					full_data);
634*4882a593Smuzhiyun 		}
635*4882a593Smuzhiyun 		if (IS_ERR_VALUE(result)) {
636*4882a593Smuzhiyun 			ret = result;
637*4882a593Smuzhiyun 			pr_err("Unable to read data+bss, errno %d\n", ret);
638*4882a593Smuzhiyun 			vm_munmap(textpos, text_len);
639*4882a593Smuzhiyun 			vm_munmap(realdatastart, len);
640*4882a593Smuzhiyun 			goto err;
641*4882a593Smuzhiyun 		}
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun 		reloc = (__be32 __user *)
644*4882a593Smuzhiyun 			(datapos + (ntohl(hdr->reloc_start) - text_len));
645*4882a593Smuzhiyun 		memp = realdatastart;
646*4882a593Smuzhiyun 		memp_size = len;
647*4882a593Smuzhiyun 	} else {
648*4882a593Smuzhiyun 
649*4882a593Smuzhiyun 		len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(u32);
650*4882a593Smuzhiyun 		len = PAGE_ALIGN(len);
651*4882a593Smuzhiyun 		textpos = vm_mmap(NULL, 0, len,
652*4882a593Smuzhiyun 			PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
653*4882a593Smuzhiyun 
654*4882a593Smuzhiyun 		if (!textpos || IS_ERR_VALUE(textpos)) {
655*4882a593Smuzhiyun 			ret = textpos;
656*4882a593Smuzhiyun 			if (!textpos)
657*4882a593Smuzhiyun 				ret = -ENOMEM;
658*4882a593Smuzhiyun 			pr_err("Unable to allocate RAM for process text/data, "
659*4882a593Smuzhiyun 			       "errno %d\n", ret);
660*4882a593Smuzhiyun 			goto err;
661*4882a593Smuzhiyun 		}
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun 		realdatastart = textpos + ntohl(hdr->data_start);
664*4882a593Smuzhiyun 		datapos = ALIGN(realdatastart +
665*4882a593Smuzhiyun 				MAX_SHARED_LIBS * sizeof(u32),
666*4882a593Smuzhiyun 				FLAT_DATA_ALIGN);
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun 		reloc = (__be32 __user *)
669*4882a593Smuzhiyun 			(datapos + (ntohl(hdr->reloc_start) - text_len));
670*4882a593Smuzhiyun 		memp = textpos;
671*4882a593Smuzhiyun 		memp_size = len;
672*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_ZFLAT
673*4882a593Smuzhiyun 		/*
674*4882a593Smuzhiyun 		 * load it all in and treat it like a RAM load from now on
675*4882a593Smuzhiyun 		 */
676*4882a593Smuzhiyun 		if (flags & FLAT_FLAG_GZIP) {
677*4882a593Smuzhiyun #ifndef CONFIG_MMU
678*4882a593Smuzhiyun 			result = decompress_exec(bprm, sizeof(struct flat_hdr),
679*4882a593Smuzhiyun 					 (((char *)textpos) + sizeof(struct flat_hdr)),
680*4882a593Smuzhiyun 					 (text_len + full_data
681*4882a593Smuzhiyun 						  - sizeof(struct flat_hdr)),
682*4882a593Smuzhiyun 					 0);
683*4882a593Smuzhiyun 			memmove((void *) datapos, (void *) realdatastart,
684*4882a593Smuzhiyun 					full_data);
685*4882a593Smuzhiyun #else
686*4882a593Smuzhiyun 			/*
687*4882a593Smuzhiyun 			 * This is used on MMU systems mainly for testing.
688*4882a593Smuzhiyun 			 * Let's use a kernel buffer to simplify things.
689*4882a593Smuzhiyun 			 */
690*4882a593Smuzhiyun 			long unz_text_len = text_len - sizeof(struct flat_hdr);
691*4882a593Smuzhiyun 			long unz_len = unz_text_len + full_data;
692*4882a593Smuzhiyun 			char *unz_data = vmalloc(unz_len);
693*4882a593Smuzhiyun 			if (!unz_data) {
694*4882a593Smuzhiyun 				result = -ENOMEM;
695*4882a593Smuzhiyun 			} else {
696*4882a593Smuzhiyun 				result = decompress_exec(bprm, sizeof(struct flat_hdr),
697*4882a593Smuzhiyun 							 unz_data, unz_len, 0);
698*4882a593Smuzhiyun 				if (result == 0 &&
699*4882a593Smuzhiyun 				    (copy_to_user((void __user *)textpos + sizeof(struct flat_hdr),
700*4882a593Smuzhiyun 						  unz_data, unz_text_len) ||
701*4882a593Smuzhiyun 				     copy_to_user((void __user *)datapos,
702*4882a593Smuzhiyun 						  unz_data + unz_text_len, full_data)))
703*4882a593Smuzhiyun 					result = -EFAULT;
704*4882a593Smuzhiyun 				vfree(unz_data);
705*4882a593Smuzhiyun 			}
706*4882a593Smuzhiyun #endif
707*4882a593Smuzhiyun 		} else if (flags & FLAT_FLAG_GZDATA) {
708*4882a593Smuzhiyun 			result = read_code(bprm->file, textpos, 0, text_len);
709*4882a593Smuzhiyun 			if (!IS_ERR_VALUE(result)) {
710*4882a593Smuzhiyun #ifndef CONFIG_MMU
711*4882a593Smuzhiyun 				result = decompress_exec(bprm, text_len, (char *) datapos,
712*4882a593Smuzhiyun 						 full_data, 0);
713*4882a593Smuzhiyun #else
714*4882a593Smuzhiyun 				char *unz_data = vmalloc(full_data);
715*4882a593Smuzhiyun 				if (!unz_data) {
716*4882a593Smuzhiyun 					result = -ENOMEM;
717*4882a593Smuzhiyun 				} else {
718*4882a593Smuzhiyun 					result = decompress_exec(bprm, text_len,
719*4882a593Smuzhiyun 						       unz_data, full_data, 0);
720*4882a593Smuzhiyun 					if (result == 0 &&
721*4882a593Smuzhiyun 					    copy_to_user((void __user *)datapos,
722*4882a593Smuzhiyun 							 unz_data, full_data))
723*4882a593Smuzhiyun 						result = -EFAULT;
724*4882a593Smuzhiyun 					vfree(unz_data);
725*4882a593Smuzhiyun 				}
726*4882a593Smuzhiyun #endif
727*4882a593Smuzhiyun 			}
728*4882a593Smuzhiyun 		} else
729*4882a593Smuzhiyun #endif /* CONFIG_BINFMT_ZFLAT */
730*4882a593Smuzhiyun 		{
731*4882a593Smuzhiyun 			result = read_code(bprm->file, textpos, 0, text_len);
732*4882a593Smuzhiyun 			if (!IS_ERR_VALUE(result))
733*4882a593Smuzhiyun 				result = read_code(bprm->file, datapos,
734*4882a593Smuzhiyun 						   ntohl(hdr->data_start),
735*4882a593Smuzhiyun 						   full_data);
736*4882a593Smuzhiyun 		}
737*4882a593Smuzhiyun 		if (IS_ERR_VALUE(result)) {
738*4882a593Smuzhiyun 			ret = result;
739*4882a593Smuzhiyun 			pr_err("Unable to read code+data+bss, errno %d\n", ret);
740*4882a593Smuzhiyun 			vm_munmap(textpos, text_len + data_len + extra +
741*4882a593Smuzhiyun 				MAX_SHARED_LIBS * sizeof(u32));
742*4882a593Smuzhiyun 			goto err;
743*4882a593Smuzhiyun 		}
744*4882a593Smuzhiyun 	}
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun 	start_code = textpos + sizeof(struct flat_hdr);
747*4882a593Smuzhiyun 	end_code = textpos + text_len;
748*4882a593Smuzhiyun 	text_len -= sizeof(struct flat_hdr); /* the real code len */
749*4882a593Smuzhiyun 
750*4882a593Smuzhiyun 	/* The main program needs a little extra setup in the task structure */
751*4882a593Smuzhiyun 	if (id == 0) {
752*4882a593Smuzhiyun 		current->mm->start_code = start_code;
753*4882a593Smuzhiyun 		current->mm->end_code = end_code;
754*4882a593Smuzhiyun 		current->mm->start_data = datapos;
755*4882a593Smuzhiyun 		current->mm->end_data = datapos + data_len;
756*4882a593Smuzhiyun 		/*
757*4882a593Smuzhiyun 		 * set up the brk stuff, uses any slack left in data/bss/stack
758*4882a593Smuzhiyun 		 * allocation.  We put the brk after the bss (between the bss
759*4882a593Smuzhiyun 		 * and stack) like other platforms.
760*4882a593Smuzhiyun 		 * Userspace code relies on the stack pointer starting out at
761*4882a593Smuzhiyun 		 * an address right at the end of a page.
762*4882a593Smuzhiyun 		 */
763*4882a593Smuzhiyun 		current->mm->start_brk = datapos + data_len + bss_len;
764*4882a593Smuzhiyun 		current->mm->brk = (current->mm->start_brk + 3) & ~3;
765*4882a593Smuzhiyun #ifndef CONFIG_MMU
766*4882a593Smuzhiyun 		current->mm->context.end_brk = memp + memp_size - stack_len;
767*4882a593Smuzhiyun #endif
768*4882a593Smuzhiyun 	}
769*4882a593Smuzhiyun 
770*4882a593Smuzhiyun 	if (flags & FLAT_FLAG_KTRACE) {
771*4882a593Smuzhiyun 		pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n",
772*4882a593Smuzhiyun 			textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));
773*4882a593Smuzhiyun 		pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n",
774*4882a593Smuzhiyun 			id ? "Lib" : "Load", bprm->filename,
775*4882a593Smuzhiyun 			start_code, end_code, datapos, datapos + data_len,
776*4882a593Smuzhiyun 			datapos + data_len, (datapos + data_len + bss_len + 3) & ~3);
777*4882a593Smuzhiyun 	}
778*4882a593Smuzhiyun 
779*4882a593Smuzhiyun 	/* Store the current module values into the global library structure */
780*4882a593Smuzhiyun 	libinfo->lib_list[id].start_code = start_code;
781*4882a593Smuzhiyun 	libinfo->lib_list[id].start_data = datapos;
782*4882a593Smuzhiyun 	libinfo->lib_list[id].start_brk = datapos + data_len + bss_len;
783*4882a593Smuzhiyun 	libinfo->lib_list[id].text_len = text_len;
784*4882a593Smuzhiyun 	libinfo->lib_list[id].loaded = 1;
785*4882a593Smuzhiyun 	libinfo->lib_list[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;
786*4882a593Smuzhiyun 	libinfo->lib_list[id].build_date = ntohl(hdr->build_date);
787*4882a593Smuzhiyun 
788*4882a593Smuzhiyun 	/*
789*4882a593Smuzhiyun 	 * We just load the allocations into some temporary memory to
790*4882a593Smuzhiyun 	 * help simplify all this mumbo jumbo
791*4882a593Smuzhiyun 	 *
792*4882a593Smuzhiyun 	 * We've got two different sections of relocation entries.
793*4882a593Smuzhiyun 	 * The first is the GOT which resides at the beginning of the data segment
794*4882a593Smuzhiyun 	 * and is terminated with a -1.  This one can be relocated in place.
795*4882a593Smuzhiyun 	 * The second is the extra relocation entries tacked after the image's
796*4882a593Smuzhiyun 	 * data segment. These require a little more processing as the entry is
797*4882a593Smuzhiyun 	 * really an offset into the image which contains an offset into the
798*4882a593Smuzhiyun 	 * image.
799*4882a593Smuzhiyun 	 */
800*4882a593Smuzhiyun 	if (flags & FLAT_FLAG_GOTPIC) {
801*4882a593Smuzhiyun 		rp = skip_got_header((u32 __user *) datapos);
802*4882a593Smuzhiyun 		for (; ; rp++) {
803*4882a593Smuzhiyun 			u32 addr, rp_val;
804*4882a593Smuzhiyun 			if (get_user(rp_val, rp))
805*4882a593Smuzhiyun 				return -EFAULT;
806*4882a593Smuzhiyun 			if (rp_val == 0xffffffff)
807*4882a593Smuzhiyun 				break;
808*4882a593Smuzhiyun 			if (rp_val) {
809*4882a593Smuzhiyun 				addr = calc_reloc(rp_val, libinfo, id, 0);
810*4882a593Smuzhiyun 				if (addr == RELOC_FAILED) {
811*4882a593Smuzhiyun 					ret = -ENOEXEC;
812*4882a593Smuzhiyun 					goto err;
813*4882a593Smuzhiyun 				}
814*4882a593Smuzhiyun 				if (put_user(addr, rp))
815*4882a593Smuzhiyun 					return -EFAULT;
816*4882a593Smuzhiyun 			}
817*4882a593Smuzhiyun 		}
818*4882a593Smuzhiyun 	}
819*4882a593Smuzhiyun 
820*4882a593Smuzhiyun 	/*
821*4882a593Smuzhiyun 	 * Now run through the relocation entries.
822*4882a593Smuzhiyun 	 * We've got to be careful here as C++ produces relocatable zero
823*4882a593Smuzhiyun 	 * entries in the constructor and destructor tables which are then
824*4882a593Smuzhiyun 	 * tested for being not zero (which will always occur unless we're
825*4882a593Smuzhiyun 	 * based from address zero).  This causes an endless loop as __start
826*4882a593Smuzhiyun 	 * is at zero.  The solution used is to not relocate zero addresses.
827*4882a593Smuzhiyun 	 * This has the negative side effect of not allowing a global data
828*4882a593Smuzhiyun 	 * reference to be statically initialised to _stext (I've moved
829*4882a593Smuzhiyun 	 * __start to address 4 so that is okay).
830*4882a593Smuzhiyun 	 */
831*4882a593Smuzhiyun 	if (rev > OLD_FLAT_VERSION) {
832*4882a593Smuzhiyun 		for (i = 0; i < relocs; i++) {
833*4882a593Smuzhiyun 			u32 addr, relval;
834*4882a593Smuzhiyun 			__be32 tmp;
835*4882a593Smuzhiyun 
836*4882a593Smuzhiyun 			/*
837*4882a593Smuzhiyun 			 * Get the address of the pointer to be
838*4882a593Smuzhiyun 			 * relocated (of course, the address has to be
839*4882a593Smuzhiyun 			 * relocated first).
840*4882a593Smuzhiyun 			 */
841*4882a593Smuzhiyun 			if (get_user(tmp, reloc + i))
842*4882a593Smuzhiyun 				return -EFAULT;
843*4882a593Smuzhiyun 			relval = ntohl(tmp);
844*4882a593Smuzhiyun 			addr = flat_get_relocate_addr(relval);
845*4882a593Smuzhiyun 			rp = (u32 __user *)calc_reloc(addr, libinfo, id, 1);
846*4882a593Smuzhiyun 			if (rp == (u32 __user *)RELOC_FAILED) {
847*4882a593Smuzhiyun 				ret = -ENOEXEC;
848*4882a593Smuzhiyun 				goto err;
849*4882a593Smuzhiyun 			}
850*4882a593Smuzhiyun 
851*4882a593Smuzhiyun 			/* Get the pointer's value.  */
852*4882a593Smuzhiyun 			ret = flat_get_addr_from_rp(rp, relval, flags, &addr);
853*4882a593Smuzhiyun 			if (unlikely(ret))
854*4882a593Smuzhiyun 				goto err;
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun 			if (addr != 0) {
857*4882a593Smuzhiyun 				/*
858*4882a593Smuzhiyun 				 * Do the relocation.  PIC relocs in the data section are
859*4882a593Smuzhiyun 				 * already in target order
860*4882a593Smuzhiyun 				 */
861*4882a593Smuzhiyun 				if ((flags & FLAT_FLAG_GOTPIC) == 0) {
862*4882a593Smuzhiyun 					/*
863*4882a593Smuzhiyun 					 * Meh, the same value can have a different
864*4882a593Smuzhiyun 					 * byte order based on a flag..
865*4882a593Smuzhiyun 					 */
866*4882a593Smuzhiyun 					addr = ntohl((__force __be32)addr);
867*4882a593Smuzhiyun 				}
868*4882a593Smuzhiyun 				addr = calc_reloc(addr, libinfo, id, 0);
869*4882a593Smuzhiyun 				if (addr == RELOC_FAILED) {
870*4882a593Smuzhiyun 					ret = -ENOEXEC;
871*4882a593Smuzhiyun 					goto err;
872*4882a593Smuzhiyun 				}
873*4882a593Smuzhiyun 
874*4882a593Smuzhiyun 				/* Write back the relocated pointer.  */
875*4882a593Smuzhiyun 				ret = flat_put_addr_at_rp(rp, addr, relval);
876*4882a593Smuzhiyun 				if (unlikely(ret))
877*4882a593Smuzhiyun 					goto err;
878*4882a593Smuzhiyun 			}
879*4882a593Smuzhiyun 		}
880*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_FLAT_OLD
881*4882a593Smuzhiyun 	} else {
882*4882a593Smuzhiyun 		for (i = 0; i < relocs; i++) {
883*4882a593Smuzhiyun 			__be32 relval;
884*4882a593Smuzhiyun 			if (get_user(relval, reloc + i))
885*4882a593Smuzhiyun 				return -EFAULT;
886*4882a593Smuzhiyun 			old_reloc(ntohl(relval));
887*4882a593Smuzhiyun 		}
888*4882a593Smuzhiyun #endif /* CONFIG_BINFMT_FLAT_OLD */
889*4882a593Smuzhiyun 	}
890*4882a593Smuzhiyun 
891*4882a593Smuzhiyun 	flush_icache_user_range(start_code, end_code);
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun 	/* zero the BSS,  BRK and stack areas */
894*4882a593Smuzhiyun 	if (clear_user((void __user *)(datapos + data_len), bss_len +
895*4882a593Smuzhiyun 		       (memp + memp_size - stack_len -		/* end brk */
896*4882a593Smuzhiyun 		       libinfo->lib_list[id].start_brk) +	/* start brk */
897*4882a593Smuzhiyun 		       stack_len))
898*4882a593Smuzhiyun 		return -EFAULT;
899*4882a593Smuzhiyun 
900*4882a593Smuzhiyun 	return 0;
901*4882a593Smuzhiyun err:
902*4882a593Smuzhiyun 	return ret;
903*4882a593Smuzhiyun }
904*4882a593Smuzhiyun 
905*4882a593Smuzhiyun 
906*4882a593Smuzhiyun /****************************************************************************/
907*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_SHARED_FLAT
908*4882a593Smuzhiyun 
909*4882a593Smuzhiyun /*
910*4882a593Smuzhiyun  * Load a shared library into memory.  The library gets its own data
911*4882a593Smuzhiyun  * segment (including bss) but not argv/argc/environ.
912*4882a593Smuzhiyun  */
913*4882a593Smuzhiyun 
load_flat_shared_library(int id,struct lib_info * libs)914*4882a593Smuzhiyun static int load_flat_shared_library(int id, struct lib_info *libs)
915*4882a593Smuzhiyun {
916*4882a593Smuzhiyun 	/*
917*4882a593Smuzhiyun 	 * This is a fake bprm struct; only the members "buf", "file" and
918*4882a593Smuzhiyun 	 * "filename" are actually used.
919*4882a593Smuzhiyun 	 */
920*4882a593Smuzhiyun 	struct linux_binprm bprm;
921*4882a593Smuzhiyun 	int res;
922*4882a593Smuzhiyun 	char buf[16];
923*4882a593Smuzhiyun 	loff_t pos = 0;
924*4882a593Smuzhiyun 
925*4882a593Smuzhiyun 	memset(&bprm, 0, sizeof(bprm));
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun 	/* Create the file name */
928*4882a593Smuzhiyun 	sprintf(buf, "/lib/lib%d.so", id);
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun 	/* Open the file up */
931*4882a593Smuzhiyun 	bprm.filename = buf;
932*4882a593Smuzhiyun 	bprm.file = open_exec(bprm.filename);
933*4882a593Smuzhiyun 	res = PTR_ERR(bprm.file);
934*4882a593Smuzhiyun 	if (IS_ERR(bprm.file))
935*4882a593Smuzhiyun 		return res;
936*4882a593Smuzhiyun 
937*4882a593Smuzhiyun 	res = kernel_read(bprm.file, bprm.buf, BINPRM_BUF_SIZE, &pos);
938*4882a593Smuzhiyun 
939*4882a593Smuzhiyun 	if (res >= 0)
940*4882a593Smuzhiyun 		res = load_flat_file(&bprm, libs, id, NULL);
941*4882a593Smuzhiyun 
942*4882a593Smuzhiyun 	allow_write_access(bprm.file);
943*4882a593Smuzhiyun 	fput(bprm.file);
944*4882a593Smuzhiyun 
945*4882a593Smuzhiyun 	return res;
946*4882a593Smuzhiyun }
947*4882a593Smuzhiyun 
948*4882a593Smuzhiyun #endif /* CONFIG_BINFMT_SHARED_FLAT */
949*4882a593Smuzhiyun /****************************************************************************/
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun /*
952*4882a593Smuzhiyun  * These are the functions used to load flat style executables and shared
953*4882a593Smuzhiyun  * libraries.  There is no binary dependent code anywhere else.
954*4882a593Smuzhiyun  */
955*4882a593Smuzhiyun 
load_flat_binary(struct linux_binprm * bprm)956*4882a593Smuzhiyun static int load_flat_binary(struct linux_binprm *bprm)
957*4882a593Smuzhiyun {
958*4882a593Smuzhiyun 	struct lib_info libinfo;
959*4882a593Smuzhiyun 	struct pt_regs *regs = current_pt_regs();
960*4882a593Smuzhiyun 	unsigned long stack_len = 0;
961*4882a593Smuzhiyun 	unsigned long start_addr;
962*4882a593Smuzhiyun 	int res;
963*4882a593Smuzhiyun 	int i, j;
964*4882a593Smuzhiyun 
965*4882a593Smuzhiyun 	memset(&libinfo, 0, sizeof(libinfo));
966*4882a593Smuzhiyun 
967*4882a593Smuzhiyun 	/*
968*4882a593Smuzhiyun 	 * We have to add the size of our arguments to our stack size
969*4882a593Smuzhiyun 	 * otherwise it's too easy for users to create stack overflows
970*4882a593Smuzhiyun 	 * by passing in a huge argument list.  And yes,  we have to be
971*4882a593Smuzhiyun 	 * pedantic and include space for the argv/envp array as it may have
972*4882a593Smuzhiyun 	 * a lot of entries.
973*4882a593Smuzhiyun 	 */
974*4882a593Smuzhiyun #ifndef CONFIG_MMU
975*4882a593Smuzhiyun 	stack_len += PAGE_SIZE * MAX_ARG_PAGES - bprm->p; /* the strings */
976*4882a593Smuzhiyun #endif
977*4882a593Smuzhiyun 	stack_len += (bprm->argc + 1) * sizeof(char *);   /* the argv array */
978*4882a593Smuzhiyun 	stack_len += (bprm->envc + 1) * sizeof(char *);   /* the envp array */
979*4882a593Smuzhiyun 	stack_len = ALIGN(stack_len, FLAT_STACK_ALIGN);
980*4882a593Smuzhiyun 
981*4882a593Smuzhiyun 	res = load_flat_file(bprm, &libinfo, 0, &stack_len);
982*4882a593Smuzhiyun 	if (res < 0)
983*4882a593Smuzhiyun 		return res;
984*4882a593Smuzhiyun 
985*4882a593Smuzhiyun 	/* Update data segment pointers for all libraries */
986*4882a593Smuzhiyun 	for (i = 0; i < MAX_SHARED_LIBS; i++) {
987*4882a593Smuzhiyun 		if (!libinfo.lib_list[i].loaded)
988*4882a593Smuzhiyun 			continue;
989*4882a593Smuzhiyun 		for (j = 0; j < MAX_SHARED_LIBS; j++) {
990*4882a593Smuzhiyun 			unsigned long val = libinfo.lib_list[j].loaded ?
991*4882a593Smuzhiyun 				libinfo.lib_list[j].start_data : UNLOADED_LIB;
992*4882a593Smuzhiyun 			unsigned long __user *p = (unsigned long __user *)
993*4882a593Smuzhiyun 				libinfo.lib_list[i].start_data;
994*4882a593Smuzhiyun 			p -= j + 1;
995*4882a593Smuzhiyun 			if (put_user(val, p))
996*4882a593Smuzhiyun 				return -EFAULT;
997*4882a593Smuzhiyun 		}
998*4882a593Smuzhiyun 	}
999*4882a593Smuzhiyun 
1000*4882a593Smuzhiyun 	set_binfmt(&flat_format);
1001*4882a593Smuzhiyun 
1002*4882a593Smuzhiyun #ifdef CONFIG_MMU
1003*4882a593Smuzhiyun 	res = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
1004*4882a593Smuzhiyun 	if (!res)
1005*4882a593Smuzhiyun 		res = create_flat_tables(bprm, bprm->p);
1006*4882a593Smuzhiyun #else
1007*4882a593Smuzhiyun 	/* Stash our initial stack pointer into the mm structure */
1008*4882a593Smuzhiyun 	current->mm->start_stack =
1009*4882a593Smuzhiyun 		((current->mm->context.end_brk + stack_len + 3) & ~3) - 4;
1010*4882a593Smuzhiyun 	pr_debug("sp=%lx\n", current->mm->start_stack);
1011*4882a593Smuzhiyun 
1012*4882a593Smuzhiyun 	/* copy the arg pages onto the stack */
1013*4882a593Smuzhiyun 	res = transfer_args_to_stack(bprm, &current->mm->start_stack);
1014*4882a593Smuzhiyun 	if (!res)
1015*4882a593Smuzhiyun 		res = create_flat_tables(bprm, current->mm->start_stack);
1016*4882a593Smuzhiyun #endif
1017*4882a593Smuzhiyun 	if (res)
1018*4882a593Smuzhiyun 		return res;
1019*4882a593Smuzhiyun 
1020*4882a593Smuzhiyun 	/* Fake some return addresses to ensure the call chain will
1021*4882a593Smuzhiyun 	 * initialise library in order for us.  We are required to call
1022*4882a593Smuzhiyun 	 * lib 1 first, then 2, ... and finally the main program (id 0).
1023*4882a593Smuzhiyun 	 */
1024*4882a593Smuzhiyun 	start_addr = libinfo.lib_list[0].entry;
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun #ifdef CONFIG_BINFMT_SHARED_FLAT
1027*4882a593Smuzhiyun 	for (i = MAX_SHARED_LIBS-1; i > 0; i--) {
1028*4882a593Smuzhiyun 		if (libinfo.lib_list[i].loaded) {
1029*4882a593Smuzhiyun 			/* Push previos first to call address */
1030*4882a593Smuzhiyun 			unsigned long __user *sp;
1031*4882a593Smuzhiyun 			current->mm->start_stack -= sizeof(unsigned long);
1032*4882a593Smuzhiyun 			sp = (unsigned long __user *)current->mm->start_stack;
1033*4882a593Smuzhiyun 			if (put_user(start_addr, sp))
1034*4882a593Smuzhiyun 				return -EFAULT;
1035*4882a593Smuzhiyun 			start_addr = libinfo.lib_list[i].entry;
1036*4882a593Smuzhiyun 		}
1037*4882a593Smuzhiyun 	}
1038*4882a593Smuzhiyun #endif
1039*4882a593Smuzhiyun 
1040*4882a593Smuzhiyun #ifdef FLAT_PLAT_INIT
1041*4882a593Smuzhiyun 	FLAT_PLAT_INIT(regs);
1042*4882a593Smuzhiyun #endif
1043*4882a593Smuzhiyun 
1044*4882a593Smuzhiyun 	finalize_exec(bprm);
1045*4882a593Smuzhiyun 	pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
1046*4882a593Smuzhiyun 		 regs, start_addr, current->mm->start_stack);
1047*4882a593Smuzhiyun 	start_thread(regs, start_addr, current->mm->start_stack);
1048*4882a593Smuzhiyun 
1049*4882a593Smuzhiyun 	return 0;
1050*4882a593Smuzhiyun }
1051*4882a593Smuzhiyun 
1052*4882a593Smuzhiyun /****************************************************************************/
1053*4882a593Smuzhiyun 
init_flat_binfmt(void)1054*4882a593Smuzhiyun static int __init init_flat_binfmt(void)
1055*4882a593Smuzhiyun {
1056*4882a593Smuzhiyun 	register_binfmt(&flat_format);
1057*4882a593Smuzhiyun 	return 0;
1058*4882a593Smuzhiyun }
1059*4882a593Smuzhiyun core_initcall(init_flat_binfmt);
1060*4882a593Smuzhiyun 
1061*4882a593Smuzhiyun /****************************************************************************/
1062