binfmt_elf.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. /*
  2. * linux/fs/binfmt_elf.c
  3. *
  4. * These are the functions used to load ELF format executables as used
  5. * on SVr4 machines. Information on the format may be found in the book
  6. * "UNIX SYSTEM V RELEASE 4 Programmers Guide: Ansi C and Programming Support
  7. * Tools".
  8. *
  9. * Copyright 1993, 1994: Eric Youngdale (ericy@cais.com).
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/fs.h>
  14. #include <linux/stat.h>
  15. #include <linux/time.h>
  16. #include <linux/mm.h>
  17. #include <linux/mman.h>
  18. #include <linux/a.out.h>
  19. #include <linux/errno.h>
  20. #include <linux/signal.h>
  21. #include <linux/binfmts.h>
  22. #include <linux/string.h>
  23. #include <linux/file.h>
  24. #include <linux/fcntl.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/slab.h>
  27. #include <linux/shm.h>
  28. #include <linux/personality.h>
  29. #include <linux/elfcore.h>
  30. #include <linux/init.h>
  31. #include <linux/highuid.h>
  32. #include <linux/smp.h>
  33. #include <linux/smp_lock.h>
  34. #include <linux/compiler.h>
  35. #include <linux/highmem.h>
  36. #include <linux/pagemap.h>
  37. #include <linux/security.h>
  38. #include <linux/syscalls.h>
  39. #include <linux/random.h>
  40. #include <linux/elf.h>
  41. #include <asm/uaccess.h>
  42. #include <asm/param.h>
  43. #include <asm/page.h>
  44. static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
  45. static int load_elf_library(struct file *);
  46. static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int);
  47. /*
  48. * If we don't support core dumping, then supply a NULL so we
  49. * don't even try.
  50. */
  51. #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
  52. static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file);
  53. #else
  54. #define elf_core_dump NULL
  55. #endif
  56. #if ELF_EXEC_PAGESIZE > PAGE_SIZE
  57. #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
  58. #else
  59. #define ELF_MIN_ALIGN PAGE_SIZE
  60. #endif
  61. #ifndef ELF_CORE_EFLAGS
  62. #define ELF_CORE_EFLAGS 0
  63. #endif
  64. #define ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ELF_MIN_ALIGN-1))
  65. #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
  66. #define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
  67. static struct linux_binfmt elf_format = {
  68. .module = THIS_MODULE,
  69. .load_binary = load_elf_binary,
  70. .load_shlib = load_elf_library,
  71. .core_dump = elf_core_dump,
  72. .min_coredump = ELF_EXEC_PAGESIZE,
  73. .hasvdso = 1
  74. };
  75. #define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
  76. static int set_brk(unsigned long start, unsigned long end)
  77. {
  78. start = ELF_PAGEALIGN(start);
  79. end = ELF_PAGEALIGN(end);
  80. if (end > start) {
  81. unsigned long addr;
  82. down_write(&current->mm->mmap_sem);
  83. addr = do_brk(start, end - start);
  84. up_write(&current->mm->mmap_sem);
  85. if (BAD_ADDR(addr))
  86. return addr;
  87. }
  88. current->mm->start_brk = current->mm->brk = end;
  89. return 0;
  90. }
  91. /* We need to explicitly zero any fractional pages
  92. after the data section (i.e. bss). This would
  93. contain the junk from the file that should not
  94. be in memory
  95. */
  96. static int padzero(unsigned long elf_bss)
  97. {
  98. unsigned long nbyte;
  99. nbyte = ELF_PAGEOFFSET(elf_bss);
  100. if (nbyte) {
  101. nbyte = ELF_MIN_ALIGN - nbyte;
  102. if (clear_user((void __user *) elf_bss, nbyte))
  103. return -EFAULT;
  104. }
  105. return 0;
  106. }
  107. /* Let's use some macros to make this stack manipulation a litle clearer */
  108. #ifdef CONFIG_STACK_GROWSUP
  109. #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) + (items))
  110. #define STACK_ROUND(sp, items) \
  111. ((15 + (unsigned long) ((sp) + (items))) &~ 15UL)
  112. #define STACK_ALLOC(sp, len) ({ \
  113. elf_addr_t __user *old_sp = (elf_addr_t __user *)sp; sp += len; \
  114. old_sp; })
  115. #else
  116. #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) - (items))
  117. #define STACK_ROUND(sp, items) \
  118. (((unsigned long) (sp - items)) &~ 15UL)
  119. #define STACK_ALLOC(sp, len) ({ sp -= len ; sp; })
  120. #endif
  121. static int
  122. create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
  123. int interp_aout, unsigned long load_addr,
  124. unsigned long interp_load_addr)
  125. {
  126. unsigned long p = bprm->p;
  127. int argc = bprm->argc;
  128. int envc = bprm->envc;
  129. elf_addr_t __user *argv;
  130. elf_addr_t __user *envp;
  131. elf_addr_t __user *sp;
  132. elf_addr_t __user *u_platform;
  133. const char *k_platform = ELF_PLATFORM;
  134. int items;
  135. elf_addr_t *elf_info;
  136. int ei_index = 0;
  137. struct task_struct *tsk = current;
  138. /*
  139. * If this architecture has a platform capability string, copy it
  140. * to userspace. In some cases (Sparc), this info is impossible
  141. * for userspace to get any other way, in others (i386) it is
  142. * merely difficult.
  143. */
  144. u_platform = NULL;
  145. if (k_platform) {
  146. size_t len = strlen(k_platform) + 1;
  147. /*
  148. * In some cases (e.g. Hyper-Threading), we want to avoid L1
  149. * evictions by the processes running on the same package. One
  150. * thing we can do is to shuffle the initial stack for them.
  151. */
  152. p = arch_align_stack(p);
  153. u_platform = (elf_addr_t __user *)STACK_ALLOC(p, len);
  154. if (__copy_to_user(u_platform, k_platform, len))
  155. return -EFAULT;
  156. }
  157. /* Create the ELF interpreter info */
  158. elf_info = (elf_addr_t *)current->mm->saved_auxv;
  159. #define NEW_AUX_ENT(id, val) \
  160. do { \
  161. elf_info[ei_index++] = id; \
  162. elf_info[ei_index++] = val; \
  163. } while (0)
  164. #ifdef ARCH_DLINFO
  165. /*
  166. * ARCH_DLINFO must come first so PPC can do its special alignment of
  167. * AUXV.
  168. */
  169. ARCH_DLINFO;
  170. #endif
  171. NEW_AUX_ENT(AT_HWCAP, ELF_HWCAP);
  172. NEW_AUX_ENT(AT_PAGESZ, ELF_EXEC_PAGESIZE);
  173. NEW_AUX_ENT(AT_CLKTCK, CLOCKS_PER_SEC);
  174. NEW_AUX_ENT(AT_PHDR, load_addr + exec->e_phoff);
  175. NEW_AUX_ENT(AT_PHENT, sizeof(struct elf_phdr));
  176. NEW_AUX_ENT(AT_PHNUM, exec->e_phnum);
  177. NEW_AUX_ENT(AT_BASE, interp_load_addr);
  178. NEW_AUX_ENT(AT_FLAGS, 0);
  179. NEW_AUX_ENT(AT_ENTRY, exec->e_entry);
  180. NEW_AUX_ENT(AT_UID, tsk->uid);
  181. NEW_AUX_ENT(AT_EUID, tsk->euid);
  182. NEW_AUX_ENT(AT_GID, tsk->gid);
  183. NEW_AUX_ENT(AT_EGID, tsk->egid);
  184. NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
  185. if (k_platform) {
  186. NEW_AUX_ENT(AT_PLATFORM,
  187. (elf_addr_t)(unsigned long)u_platform);
  188. }
  189. if (bprm->interp_flags & BINPRM_FLAGS_EXECFD) {
  190. NEW_AUX_ENT(AT_EXECFD, bprm->interp_data);
  191. }
  192. #undef NEW_AUX_ENT
  193. /* AT_NULL is zero; clear the rest too */
  194. memset(&elf_info[ei_index], 0,
  195. sizeof current->mm->saved_auxv - ei_index * sizeof elf_info[0]);
  196. /* And advance past the AT_NULL entry. */
  197. ei_index += 2;
  198. sp = STACK_ADD(p, ei_index);
  199. items = (argc + 1) + (envc + 1);
  200. if (interp_aout) {
  201. items += 3; /* a.out interpreters require argv & envp too */
  202. } else {
  203. items += 1; /* ELF interpreters only put argc on the stack */
  204. }
  205. bprm->p = STACK_ROUND(sp, items);
  206. /* Point sp at the lowest address on the stack */
  207. #ifdef CONFIG_STACK_GROWSUP
  208. sp = (elf_addr_t __user *)bprm->p - items - ei_index;
  209. bprm->exec = (unsigned long)sp; /* XXX: PARISC HACK */
  210. #else
  211. sp = (elf_addr_t __user *)bprm->p;
  212. #endif
  213. /* Now, let's put argc (and argv, envp if appropriate) on the stack */
  214. if (__put_user(argc, sp++))
  215. return -EFAULT;
  216. if (interp_aout) {
  217. argv = sp + 2;
  218. envp = argv + argc + 1;
  219. if (__put_user((elf_addr_t)(unsigned long)argv, sp++) ||
  220. __put_user((elf_addr_t)(unsigned long)envp, sp++))
  221. return -EFAULT;
  222. } else {
  223. argv = sp;
  224. envp = argv + argc + 1;
  225. }
  226. /* Populate argv and envp */
  227. p = current->mm->arg_end = current->mm->arg_start;
  228. while (argc-- > 0) {
  229. size_t len;
  230. if (__put_user((elf_addr_t)p, argv++))
  231. return -EFAULT;
  232. len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES);
  233. if (!len || len > PAGE_SIZE*MAX_ARG_PAGES)
  234. return 0;
  235. p += len;
  236. }
  237. if (__put_user(0, argv))
  238. return -EFAULT;
  239. current->mm->arg_end = current->mm->env_start = p;
  240. while (envc-- > 0) {
  241. size_t len;
  242. if (__put_user((elf_addr_t)p, envp++))
  243. return -EFAULT;
  244. len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES);
  245. if (!len || len > PAGE_SIZE*MAX_ARG_PAGES)
  246. return 0;
  247. p += len;
  248. }
  249. if (__put_user(0, envp))
  250. return -EFAULT;
  251. current->mm->env_end = p;
  252. /* Put the elf_info on the stack in the right place. */
  253. sp = (elf_addr_t __user *)envp + 1;
  254. if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
  255. return -EFAULT;
  256. return 0;
  257. }
  258. #ifndef elf_map
  259. static unsigned long elf_map(struct file *filep, unsigned long addr,
  260. struct elf_phdr *eppnt, int prot, int type)
  261. {
  262. unsigned long map_addr;
  263. unsigned long pageoffset = ELF_PAGEOFFSET(eppnt->p_vaddr);
  264. down_write(&current->mm->mmap_sem);
  265. /* mmap() will return -EINVAL if given a zero size, but a
  266. * segment with zero filesize is perfectly valid */
  267. if (eppnt->p_filesz + pageoffset)
  268. map_addr = do_mmap(filep, ELF_PAGESTART(addr),
  269. eppnt->p_filesz + pageoffset, prot, type,
  270. eppnt->p_offset - pageoffset);
  271. else
  272. map_addr = ELF_PAGESTART(addr);
  273. up_write(&current->mm->mmap_sem);
  274. return(map_addr);
  275. }
  276. #endif /* !elf_map */
  277. /* This is much more generalized than the library routine read function,
  278. so we keep this separate. Technically the library read function
  279. is only provided so that we can read a.out libraries that have
  280. an ELF header */
  281. static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
  282. struct file *interpreter, unsigned long *interp_load_addr)
  283. {
  284. struct elf_phdr *elf_phdata;
  285. struct elf_phdr *eppnt;
  286. unsigned long load_addr = 0;
  287. int load_addr_set = 0;
  288. unsigned long last_bss = 0, elf_bss = 0;
  289. unsigned long error = ~0UL;
  290. int retval, i, size;
  291. /* First of all, some simple consistency checks */
  292. if (interp_elf_ex->e_type != ET_EXEC &&
  293. interp_elf_ex->e_type != ET_DYN)
  294. goto out;
  295. if (!elf_check_arch(interp_elf_ex))
  296. goto out;
  297. if (!interpreter->f_op || !interpreter->f_op->mmap)
  298. goto out;
  299. /*
  300. * If the size of this structure has changed, then punt, since
  301. * we will be doing the wrong thing.
  302. */
  303. if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr))
  304. goto out;
  305. if (interp_elf_ex->e_phnum < 1 ||
  306. interp_elf_ex->e_phnum > 65536U / sizeof(struct elf_phdr))
  307. goto out;
  308. /* Now read in all of the header information */
  309. size = sizeof(struct elf_phdr) * interp_elf_ex->e_phnum;
  310. if (size > ELF_MIN_ALIGN)
  311. goto out;
  312. elf_phdata = kmalloc(size, GFP_KERNEL);
  313. if (!elf_phdata)
  314. goto out;
  315. retval = kernel_read(interpreter, interp_elf_ex->e_phoff,
  316. (char *)elf_phdata,size);
  317. error = -EIO;
  318. if (retval != size) {
  319. if (retval < 0)
  320. error = retval;
  321. goto out_close;
  322. }
  323. eppnt = elf_phdata;
  324. for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
  325. if (eppnt->p_type == PT_LOAD) {
  326. int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
  327. int elf_prot = 0;
  328. unsigned long vaddr = 0;
  329. unsigned long k, map_addr;
  330. if (eppnt->p_flags & PF_R)
  331. elf_prot = PROT_READ;
  332. if (eppnt->p_flags & PF_W)
  333. elf_prot |= PROT_WRITE;
  334. if (eppnt->p_flags & PF_X)
  335. elf_prot |= PROT_EXEC;
  336. vaddr = eppnt->p_vaddr;
  337. if (interp_elf_ex->e_type == ET_EXEC || load_addr_set)
  338. elf_type |= MAP_FIXED;
  339. map_addr = elf_map(interpreter, load_addr + vaddr,
  340. eppnt, elf_prot, elf_type);
  341. error = map_addr;
  342. if (BAD_ADDR(map_addr))
  343. goto out_close;
  344. if (!load_addr_set &&
  345. interp_elf_ex->e_type == ET_DYN) {
  346. load_addr = map_addr - ELF_PAGESTART(vaddr);
  347. load_addr_set = 1;
  348. }
  349. /*
  350. * Check to see if the section's size will overflow the
  351. * allowed task size. Note that p_filesz must always be
  352. * <= p_memsize so it's only necessary to check p_memsz.
  353. */
  354. k = load_addr + eppnt->p_vaddr;
  355. if (BAD_ADDR(k) ||
  356. eppnt->p_filesz > eppnt->p_memsz ||
  357. eppnt->p_memsz > TASK_SIZE ||
  358. TASK_SIZE - eppnt->p_memsz < k) {
  359. error = -ENOMEM;
  360. goto out_close;
  361. }
  362. /*
  363. * Find the end of the file mapping for this phdr, and
  364. * keep track of the largest address we see for this.
  365. */
  366. k = load_addr + eppnt->p_vaddr + eppnt->p_filesz;
  367. if (k > elf_bss)
  368. elf_bss = k;
  369. /*
  370. * Do the same thing for the memory mapping - between
  371. * elf_bss and last_bss is the bss section.
  372. */
  373. k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
  374. if (k > last_bss)
  375. last_bss = k;
  376. }
  377. }
  378. /*
  379. * Now fill out the bss section. First pad the last page up
  380. * to the page boundary, and then perform a mmap to make sure
  381. * that there are zero-mapped pages up to and including the
  382. * last bss page.
  383. */
  384. if (padzero(elf_bss)) {
  385. error = -EFAULT;
  386. goto out_close;
  387. }
  388. /* What we have mapped so far */
  389. elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
  390. /* Map the last of the bss segment */
  391. if (last_bss > elf_bss) {
  392. down_write(&current->mm->mmap_sem);
  393. error = do_brk(elf_bss, last_bss - elf_bss);
  394. up_write(&current->mm->mmap_sem);
  395. if (BAD_ADDR(error))
  396. goto out_close;
  397. }
  398. *interp_load_addr = load_addr;
  399. error = ((unsigned long)interp_elf_ex->e_entry) + load_addr;
  400. out_close:
  401. kfree(elf_phdata);
  402. out:
  403. return error;
  404. }
  405. static unsigned long load_aout_interp(struct exec *interp_ex,
  406. struct file *interpreter)
  407. {
  408. unsigned long text_data, elf_entry = ~0UL;
  409. char __user * addr;
  410. loff_t offset;
  411. current->mm->end_code = interp_ex->a_text;
  412. text_data = interp_ex->a_text + interp_ex->a_data;
  413. current->mm->end_data = text_data;
  414. current->mm->brk = interp_ex->a_bss + text_data;
  415. switch (N_MAGIC(*interp_ex)) {
  416. case OMAGIC:
  417. offset = 32;
  418. addr = (char __user *)0;
  419. break;
  420. case ZMAGIC:
  421. case QMAGIC:
  422. offset = N_TXTOFF(*interp_ex);
  423. addr = (char __user *)N_TXTADDR(*interp_ex);
  424. break;
  425. default:
  426. goto out;
  427. }
  428. down_write(&current->mm->mmap_sem);
  429. do_brk(0, text_data);
  430. up_write(&current->mm->mmap_sem);
  431. if (!interpreter->f_op || !interpreter->f_op->read)
  432. goto out;
  433. if (interpreter->f_op->read(interpreter, addr, text_data, &offset) < 0)
  434. goto out;
  435. flush_icache_range((unsigned long)addr,
  436. (unsigned long)addr + text_data);
  437. down_write(&current->mm->mmap_sem);
  438. do_brk(ELF_PAGESTART(text_data + ELF_MIN_ALIGN - 1),
  439. interp_ex->a_bss);
  440. up_write(&current->mm->mmap_sem);
  441. elf_entry = interp_ex->a_entry;
  442. out:
  443. return elf_entry;
  444. }
  445. /*
  446. * These are the functions used to load ELF style executables and shared
  447. * libraries. There is no binary dependent code anywhere else.
  448. */
  449. #define INTERPRETER_NONE 0
  450. #define INTERPRETER_AOUT 1
  451. #define INTERPRETER_ELF 2
  452. #ifndef STACK_RND_MASK
  453. #define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) /* 8MB of VA */
  454. #endif
  455. static unsigned long randomize_stack_top(unsigned long stack_top)
  456. {
  457. unsigned int random_variable = 0;
  458. if ((current->flags & PF_RANDOMIZE) &&
  459. !(current->personality & ADDR_NO_RANDOMIZE)) {
  460. random_variable = get_random_int() & STACK_RND_MASK;
  461. random_variable <<= PAGE_SHIFT;
  462. }
  463. #ifdef CONFIG_STACK_GROWSUP
  464. return PAGE_ALIGN(stack_top) + random_variable;
  465. #else
  466. return PAGE_ALIGN(stack_top) - random_variable;
  467. #endif
  468. }
  469. static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
  470. {
  471. struct file *interpreter = NULL; /* to shut gcc up */
  472. unsigned long load_addr = 0, load_bias = 0;
  473. int load_addr_set = 0;
  474. char * elf_interpreter = NULL;
  475. unsigned int interpreter_type = INTERPRETER_NONE;
  476. unsigned char ibcs2_interpreter = 0;
  477. unsigned long error;
  478. struct elf_phdr *elf_ppnt, *elf_phdata;
  479. unsigned long elf_bss, elf_brk;
  480. int elf_exec_fileno;
  481. int retval, i;
  482. unsigned int size;
  483. unsigned long elf_entry, interp_load_addr = 0;
  484. unsigned long start_code, end_code, start_data, end_data;
  485. unsigned long reloc_func_desc = 0;
  486. char passed_fileno[6];
  487. struct files_struct *files;
  488. int executable_stack = EXSTACK_DEFAULT;
  489. unsigned long def_flags = 0;
  490. struct {
  491. struct elfhdr elf_ex;
  492. struct elfhdr interp_elf_ex;
  493. struct exec interp_ex;
  494. } *loc;
  495. loc = kmalloc(sizeof(*loc), GFP_KERNEL);
  496. if (!loc) {
  497. retval = -ENOMEM;
  498. goto out_ret;
  499. }
  500. /* Get the exec-header */
  501. loc->elf_ex = *((struct elfhdr *)bprm->buf);
  502. retval = -ENOEXEC;
  503. /* First of all, some simple consistency checks */
  504. if (memcmp(loc->elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
  505. goto out;
  506. if (loc->elf_ex.e_type != ET_EXEC && loc->elf_ex.e_type != ET_DYN)
  507. goto out;
  508. if (!elf_check_arch(&loc->elf_ex))
  509. goto out;
  510. if (!bprm->file->f_op||!bprm->file->f_op->mmap)
  511. goto out;
  512. /* Now read in all of the header information */
  513. if (loc->elf_ex.e_phentsize != sizeof(struct elf_phdr))
  514. goto out;
  515. if (loc->elf_ex.e_phnum < 1 ||
  516. loc->elf_ex.e_phnum > 65536U / sizeof(struct elf_phdr))
  517. goto out;
  518. size = loc->elf_ex.e_phnum * sizeof(struct elf_phdr);
  519. retval = -ENOMEM;
  520. elf_phdata = kmalloc(size, GFP_KERNEL);
  521. if (!elf_phdata)
  522. goto out;
  523. retval = kernel_read(bprm->file, loc->elf_ex.e_phoff,
  524. (char *)elf_phdata, size);
  525. if (retval != size) {
  526. if (retval >= 0)
  527. retval = -EIO;
  528. goto out_free_ph;
  529. }
  530. files = current->files; /* Refcounted so ok */
  531. retval = unshare_files();
  532. if (retval < 0)
  533. goto out_free_ph;
  534. if (files == current->files) {
  535. put_files_struct(files);
  536. files = NULL;
  537. }
  538. /* exec will make our files private anyway, but for the a.out
  539. loader stuff we need to do it earlier */
  540. retval = get_unused_fd();
  541. if (retval < 0)
  542. goto out_free_fh;
  543. get_file(bprm->file);
  544. fd_install(elf_exec_fileno = retval, bprm->file);
  545. elf_ppnt = elf_phdata;
  546. elf_bss = 0;
  547. elf_brk = 0;
  548. start_code = ~0UL;
  549. end_code = 0;
  550. start_data = 0;
  551. end_data = 0;
  552. for (i = 0; i < loc->elf_ex.e_phnum; i++) {
  553. if (elf_ppnt->p_type == PT_INTERP) {
  554. /* This is the program interpreter used for
  555. * shared libraries - for now assume that this
  556. * is an a.out format binary
  557. */
  558. retval = -ENOEXEC;
  559. if (elf_ppnt->p_filesz > PATH_MAX ||
  560. elf_ppnt->p_filesz < 2)
  561. goto out_free_file;
  562. retval = -ENOMEM;
  563. elf_interpreter = kmalloc(elf_ppnt->p_filesz,
  564. GFP_KERNEL);
  565. if (!elf_interpreter)
  566. goto out_free_file;
  567. retval = kernel_read(bprm->file, elf_ppnt->p_offset,
  568. elf_interpreter,
  569. elf_ppnt->p_filesz);
  570. if (retval != elf_ppnt->p_filesz) {
  571. if (retval >= 0)
  572. retval = -EIO;
  573. goto out_free_interp;
  574. }
  575. /* make sure path is NULL terminated */
  576. retval = -ENOEXEC;
  577. if (elf_interpreter[elf_ppnt->p_filesz - 1] != '\0')
  578. goto out_free_interp;
  579. /* If the program interpreter is one of these two,
  580. * then assume an iBCS2 image. Otherwise assume
  581. * a native linux image.
  582. */
  583. if (strcmp(elf_interpreter,"/usr/lib/libc.so.1") == 0 ||
  584. strcmp(elf_interpreter,"/usr/lib/ld.so.1") == 0)
  585. ibcs2_interpreter = 1;
  586. /*
  587. * The early SET_PERSONALITY here is so that the lookup
  588. * for the interpreter happens in the namespace of the
  589. * to-be-execed image. SET_PERSONALITY can select an
  590. * alternate root.
  591. *
  592. * However, SET_PERSONALITY is NOT allowed to switch
  593. * this task into the new images's memory mapping
  594. * policy - that is, TASK_SIZE must still evaluate to
  595. * that which is appropriate to the execing application.
  596. * This is because exit_mmap() needs to have TASK_SIZE
  597. * evaluate to the size of the old image.
  598. *
  599. * So if (say) a 64-bit application is execing a 32-bit
  600. * application it is the architecture's responsibility
  601. * to defer changing the value of TASK_SIZE until the
  602. * switch really is going to happen - do this in
  603. * flush_thread(). - akpm
  604. */
  605. SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);
  606. interpreter = open_exec(elf_interpreter);
  607. retval = PTR_ERR(interpreter);
  608. if (IS_ERR(interpreter))
  609. goto out_free_interp;
  610. /*
  611. * If the binary is not readable then enforce
  612. * mm->dumpable = 0 regardless of the interpreter's
  613. * permissions.
  614. */
  615. if (file_permission(interpreter, MAY_READ) < 0)
  616. bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
  617. retval = kernel_read(interpreter, 0, bprm->buf,
  618. BINPRM_BUF_SIZE);
  619. if (retval != BINPRM_BUF_SIZE) {
  620. if (retval >= 0)
  621. retval = -EIO;
  622. goto out_free_dentry;
  623. }
  624. /* Get the exec headers */
  625. loc->interp_ex = *((struct exec *)bprm->buf);
  626. loc->interp_elf_ex = *((struct elfhdr *)bprm->buf);
  627. break;
  628. }
  629. elf_ppnt++;
  630. }
  631. elf_ppnt = elf_phdata;
  632. for (i = 0; i < loc->elf_ex.e_phnum; i++, elf_ppnt++)
  633. if (elf_ppnt->p_type == PT_GNU_STACK) {
  634. if (elf_ppnt->p_flags & PF_X)
  635. executable_stack = EXSTACK_ENABLE_X;
  636. else
  637. executable_stack = EXSTACK_DISABLE_X;
  638. break;
  639. }
  640. /* Some simple consistency checks for the interpreter */
  641. if (elf_interpreter) {
  642. interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
  643. /* Now figure out which format our binary is */
  644. if ((N_MAGIC(loc->interp_ex) != OMAGIC) &&
  645. (N_MAGIC(loc->interp_ex) != ZMAGIC) &&
  646. (N_MAGIC(loc->interp_ex) != QMAGIC))
  647. interpreter_type = INTERPRETER_ELF;
  648. if (memcmp(loc->interp_elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
  649. interpreter_type &= ~INTERPRETER_ELF;
  650. retval = -ELIBBAD;
  651. if (!interpreter_type)
  652. goto out_free_dentry;
  653. /* Make sure only one type was selected */
  654. if ((interpreter_type & INTERPRETER_ELF) &&
  655. interpreter_type != INTERPRETER_ELF) {
  656. // FIXME - ratelimit this before re-enabling
  657. // printk(KERN_WARNING "ELF: Ambiguous type, using ELF\n");
  658. interpreter_type = INTERPRETER_ELF;
  659. }
  660. /* Verify the interpreter has a valid arch */
  661. if ((interpreter_type == INTERPRETER_ELF) &&
  662. !elf_check_arch(&loc->interp_elf_ex))
  663. goto out_free_dentry;
  664. } else {
  665. /* Executables without an interpreter also need a personality */
  666. SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);
  667. }
  668. /* OK, we are done with that, now set up the arg stuff,
  669. and then start this sucker up */
  670. if ((!bprm->sh_bang) && (interpreter_type == INTERPRETER_AOUT)) {
  671. char *passed_p = passed_fileno;
  672. sprintf(passed_fileno, "%d", elf_exec_fileno);
  673. if (elf_interpreter) {
  674. retval = copy_strings_kernel(1, &passed_p, bprm);
  675. if (retval)
  676. goto out_free_dentry;
  677. bprm->argc++;
  678. }
  679. }
  680. /* Flush all traces of the currently running executable */
  681. retval = flush_old_exec(bprm);
  682. if (retval)
  683. goto out_free_dentry;
  684. /* Discard our unneeded old files struct */
  685. if (files) {
  686. put_files_struct(files);
  687. files = NULL;
  688. }
  689. /* OK, This is the point of no return */
  690. current->mm->start_data = 0;
  691. current->mm->end_data = 0;
  692. current->mm->end_code = 0;
  693. current->mm->mmap = NULL;
  694. current->flags &= ~PF_FORKNOEXEC;
  695. current->mm->def_flags = def_flags;
  696. /* Do this immediately, since STACK_TOP as used in setup_arg_pages
  697. may depend on the personality. */
  698. SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);
  699. if (elf_read_implies_exec(loc->elf_ex, executable_stack))
  700. current->personality |= READ_IMPLIES_EXEC;
  701. if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  702. current->flags |= PF_RANDOMIZE;
  703. arch_pick_mmap_layout(current->mm);
  704. /* Do this so that we can load the interpreter, if need be. We will
  705. change some of these later */
  706. current->mm->free_area_cache = current->mm->mmap_base;
  707. current->mm->cached_hole_size = 0;
  708. retval = setup_arg_pages(bprm, randomize_stack_top(STACK_TOP),
  709. executable_stack);
  710. if (retval < 0) {
  711. send_sig(SIGKILL, current, 0);
  712. goto out_free_dentry;
  713. }
  714. current->mm->start_stack = bprm->p;
  715. /* Now we do a little grungy work by mmaping the ELF image into
  716. the correct location in memory. At this point, we assume that
  717. the image should be loaded at fixed address, not at a variable
  718. address. */
  719. for(i = 0, elf_ppnt = elf_phdata;
  720. i < loc->elf_ex.e_phnum; i++, elf_ppnt++) {
  721. int elf_prot = 0, elf_flags;
  722. unsigned long k, vaddr;
  723. if (elf_ppnt->p_type != PT_LOAD)
  724. continue;
  725. if (unlikely (elf_brk > elf_bss)) {
  726. unsigned long nbyte;
  727. /* There was a PT_LOAD segment with p_memsz > p_filesz
  728. before this one. Map anonymous pages, if needed,
  729. and clear the area. */
  730. retval = set_brk (elf_bss + load_bias,
  731. elf_brk + load_bias);
  732. if (retval) {
  733. send_sig(SIGKILL, current, 0);
  734. goto out_free_dentry;
  735. }
  736. nbyte = ELF_PAGEOFFSET(elf_bss);
  737. if (nbyte) {
  738. nbyte = ELF_MIN_ALIGN - nbyte;
  739. if (nbyte > elf_brk - elf_bss)
  740. nbyte = elf_brk - elf_bss;
  741. if (clear_user((void __user *)elf_bss +
  742. load_bias, nbyte)) {
  743. /*
  744. * This bss-zeroing can fail if the ELF
  745. * file specifies odd protections. So
  746. * we don't check the return value
  747. */
  748. }
  749. }
  750. }
  751. if (elf_ppnt->p_flags & PF_R)
  752. elf_prot |= PROT_READ;
  753. if (elf_ppnt->p_flags & PF_W)
  754. elf_prot |= PROT_WRITE;
  755. if (elf_ppnt->p_flags & PF_X)
  756. elf_prot |= PROT_EXEC;
  757. elf_flags = MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE;
  758. vaddr = elf_ppnt->p_vaddr;
  759. if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) {
  760. elf_flags |= MAP_FIXED;
  761. } else if (loc->elf_ex.e_type == ET_DYN) {
  762. /* Try and get dynamic programs out of the way of the
  763. * default mmap base, as well as whatever program they
  764. * might try to exec. This is because the brk will
  765. * follow the loader, and is not movable. */
  766. load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
  767. }
  768. error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
  769. elf_prot, elf_flags);
  770. if (BAD_ADDR(error)) {
  771. send_sig(SIGKILL, current, 0);
  772. goto out_free_dentry;
  773. }
  774. if (!load_addr_set) {
  775. load_addr_set = 1;
  776. load_addr = (elf_ppnt->p_vaddr - elf_ppnt->p_offset);
  777. if (loc->elf_ex.e_type == ET_DYN) {
  778. load_bias += error -
  779. ELF_PAGESTART(load_bias + vaddr);
  780. load_addr += load_bias;
  781. reloc_func_desc = load_bias;
  782. }
  783. }
  784. k = elf_ppnt->p_vaddr;
  785. if (k < start_code)
  786. start_code = k;
  787. if (start_data < k)
  788. start_data = k;
  789. /*
  790. * Check to see if the section's size will overflow the
  791. * allowed task size. Note that p_filesz must always be
  792. * <= p_memsz so it is only necessary to check p_memsz.
  793. */
  794. if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
  795. elf_ppnt->p_memsz > TASK_SIZE ||
  796. TASK_SIZE - elf_ppnt->p_memsz < k) {
  797. /* set_brk can never work. Avoid overflows. */
  798. send_sig(SIGKILL, current, 0);
  799. goto out_free_dentry;
  800. }
  801. k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
  802. if (k > elf_bss)
  803. elf_bss = k;
  804. if ((elf_ppnt->p_flags & PF_X) && end_code < k)
  805. end_code = k;
  806. if (end_data < k)
  807. end_data = k;
  808. k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
  809. if (k > elf_brk)
  810. elf_brk = k;
  811. }
  812. loc->elf_ex.e_entry += load_bias;
  813. elf_bss += load_bias;
  814. elf_brk += load_bias;
  815. start_code += load_bias;
  816. end_code += load_bias;
  817. start_data += load_bias;
  818. end_data += load_bias;
  819. /* Calling set_brk effectively mmaps the pages that we need
  820. * for the bss and break sections. We must do this before
  821. * mapping in the interpreter, to make sure it doesn't wind
  822. * up getting placed where the bss needs to go.
  823. */
  824. retval = set_brk(elf_bss, elf_brk);
  825. if (retval) {
  826. send_sig(SIGKILL, current, 0);
  827. goto out_free_dentry;
  828. }
  829. if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
  830. send_sig(SIGSEGV, current, 0);
  831. retval = -EFAULT; /* Nobody gets to see this, but.. */
  832. goto out_free_dentry;
  833. }
  834. if (elf_interpreter) {
  835. if (interpreter_type == INTERPRETER_AOUT)
  836. elf_entry = load_aout_interp(&loc->interp_ex,
  837. interpreter);
  838. else
  839. elf_entry = load_elf_interp(&loc->interp_elf_ex,
  840. interpreter,
  841. &interp_load_addr);
  842. if (BAD_ADDR(elf_entry)) {
  843. force_sig(SIGSEGV, current);
  844. retval = IS_ERR((void *)elf_entry) ?
  845. (int)elf_entry : -EINVAL;
  846. goto out_free_dentry;
  847. }
  848. reloc_func_desc = interp_load_addr;
  849. allow_write_access(interpreter);
  850. fput(interpreter);
  851. kfree(elf_interpreter);
  852. } else {
  853. elf_entry = loc->elf_ex.e_entry;
  854. if (BAD_ADDR(elf_entry)) {
  855. force_sig(SIGSEGV, current);
  856. retval = -EINVAL;
  857. goto out_free_dentry;
  858. }
  859. }
  860. kfree(elf_phdata);
  861. if (interpreter_type != INTERPRETER_AOUT)
  862. sys_close(elf_exec_fileno);
  863. set_binfmt(&elf_format);
  864. #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES
  865. retval = arch_setup_additional_pages(bprm, executable_stack);
  866. if (retval < 0) {
  867. send_sig(SIGKILL, current, 0);
  868. goto out;
  869. }
  870. #endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */
  871. compute_creds(bprm);
  872. current->flags &= ~PF_FORKNOEXEC;
  873. create_elf_tables(bprm, &loc->elf_ex,
  874. (interpreter_type == INTERPRETER_AOUT),
  875. load_addr, interp_load_addr);
  876. /* N.B. passed_fileno might not be initialized? */
  877. if (interpreter_type == INTERPRETER_AOUT)
  878. current->mm->arg_start += strlen(passed_fileno) + 1;
  879. current->mm->end_code = end_code;
  880. current->mm->start_code = start_code;
  881. current->mm->start_data = start_data;
  882. current->mm->end_data = end_data;
  883. current->mm->start_stack = bprm->p;
  884. if (current->personality & MMAP_PAGE_ZERO) {
  885. /* Why this, you ask??? Well SVr4 maps page 0 as read-only,
  886. and some applications "depend" upon this behavior.
  887. Since we do not have the power to recompile these, we
  888. emulate the SVr4 behavior. Sigh. */
  889. down_write(&current->mm->mmap_sem);
  890. error = do_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
  891. MAP_FIXED | MAP_PRIVATE, 0);
  892. up_write(&current->mm->mmap_sem);
  893. }
  894. #ifdef ELF_PLAT_INIT
  895. /*
  896. * The ABI may specify that certain registers be set up in special
  897. * ways (on i386 %edx is the address of a DT_FINI function, for
  898. * example. In addition, it may also specify (eg, PowerPC64 ELF)
  899. * that the e_entry field is the address of the function descriptor
  900. * for the startup routine, rather than the address of the startup
  901. * routine itself. This macro performs whatever initialization to
  902. * the regs structure is required as well as any relocations to the
  903. * function descriptor entries when executing dynamically links apps.
  904. */
  905. ELF_PLAT_INIT(regs, reloc_func_desc);
  906. #endif
  907. start_thread(regs, elf_entry, bprm->p);
  908. if (unlikely(current->ptrace & PT_PTRACED)) {
  909. if (current->ptrace & PT_TRACE_EXEC)
  910. ptrace_notify ((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
  911. else
  912. send_sig(SIGTRAP, current, 0);
  913. }
  914. retval = 0;
  915. out:
  916. kfree(loc);
  917. out_ret:
  918. return retval;
  919. /* error cleanup */
  920. out_free_dentry:
  921. allow_write_access(interpreter);
  922. if (interpreter)
  923. fput(interpreter);
  924. out_free_interp:
  925. kfree(elf_interpreter);
  926. out_free_file:
  927. sys_close(elf_exec_fileno);
  928. out_free_fh:
  929. if (files)
  930. reset_files_struct(current, files);
  931. out_free_ph:
  932. kfree(elf_phdata);
  933. goto out;
  934. }
  935. /* This is really simpleminded and specialized - we are loading an
  936. a.out library that is given an ELF header. */
  937. static int load_elf_library(struct file *file)
  938. {
  939. struct elf_phdr *elf_phdata;
  940. struct elf_phdr *eppnt;
  941. unsigned long elf_bss, bss, len;
  942. int retval, error, i, j;
  943. struct elfhdr elf_ex;
  944. error = -ENOEXEC;
  945. retval = kernel_read(file, 0, (char *)&elf_ex, sizeof(elf_ex));
  946. if (retval != sizeof(elf_ex))
  947. goto out;
  948. if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
  949. goto out;
  950. /* First of all, some simple consistency checks */
  951. if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
  952. !elf_check_arch(&elf_ex) || !file->f_op || !file->f_op->mmap)
  953. goto out;
  954. /* Now read in all of the header information */
  955. j = sizeof(struct elf_phdr) * elf_ex.e_phnum;
  956. /* j < ELF_MIN_ALIGN because elf_ex.e_phnum <= 2 */
  957. error = -ENOMEM;
  958. elf_phdata = kmalloc(j, GFP_KERNEL);
  959. if (!elf_phdata)
  960. goto out;
  961. eppnt = elf_phdata;
  962. error = -ENOEXEC;
  963. retval = kernel_read(file, elf_ex.e_phoff, (char *)eppnt, j);
  964. if (retval != j)
  965. goto out_free_ph;
  966. for (j = 0, i = 0; i<elf_ex.e_phnum; i++)
  967. if ((eppnt + i)->p_type == PT_LOAD)
  968. j++;
  969. if (j != 1)
  970. goto out_free_ph;
  971. while (eppnt->p_type != PT_LOAD)
  972. eppnt++;
  973. /* Now use mmap to map the library into memory. */
  974. down_write(&current->mm->mmap_sem);
  975. error = do_mmap(file,
  976. ELF_PAGESTART(eppnt->p_vaddr),
  977. (eppnt->p_filesz +
  978. ELF_PAGEOFFSET(eppnt->p_vaddr)),
  979. PROT_READ | PROT_WRITE | PROT_EXEC,
  980. MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
  981. (eppnt->p_offset -
  982. ELF_PAGEOFFSET(eppnt->p_vaddr)));
  983. up_write(&current->mm->mmap_sem);
  984. if (error != ELF_PAGESTART(eppnt->p_vaddr))
  985. goto out_free_ph;
  986. elf_bss = eppnt->p_vaddr + eppnt->p_filesz;
  987. if (padzero(elf_bss)) {
  988. error = -EFAULT;
  989. goto out_free_ph;
  990. }
  991. len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
  992. ELF_MIN_ALIGN - 1);
  993. bss = eppnt->p_memsz + eppnt->p_vaddr;
  994. if (bss > len) {
  995. down_write(&current->mm->mmap_sem);
  996. do_brk(len, bss - len);
  997. up_write(&current->mm->mmap_sem);
  998. }
  999. error = 0;
  1000. out_free_ph:
  1001. kfree(elf_phdata);
  1002. out:
  1003. return error;
  1004. }
  1005. /*
  1006. * Note that some platforms still use traditional core dumps and not
  1007. * the ELF core dump. Each platform can select it as appropriate.
  1008. */
  1009. #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
  1010. /*
  1011. * ELF core dumper
  1012. *
  1013. * Modelled on fs/exec.c:aout_core_dump()
  1014. * Jeremy Fitzhardinge <jeremy@sw.oz.au>
  1015. */
  1016. /*
  1017. * These are the only things you should do on a core-file: use only these
  1018. * functions to write out all the necessary info.
  1019. */
  1020. static int dump_write(struct file *file, const void *addr, int nr)
  1021. {
  1022. return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
  1023. }
  1024. static int dump_seek(struct file *file, loff_t off)
  1025. {
  1026. if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
  1027. if (file->f_op->llseek(file, off, SEEK_CUR) < 0)
  1028. return 0;
  1029. } else {
  1030. char *buf = (char *)get_zeroed_page(GFP_KERNEL);
  1031. if (!buf)
  1032. return 0;
  1033. while (off > 0) {
  1034. unsigned long n = off;
  1035. if (n > PAGE_SIZE)
  1036. n = PAGE_SIZE;
  1037. if (!dump_write(file, buf, n))
  1038. return 0;
  1039. off -= n;
  1040. }
  1041. free_page((unsigned long)buf);
  1042. }
  1043. return 1;
  1044. }
  1045. /*
  1046. * Decide whether a segment is worth dumping; default is yes to be
  1047. * sure (missing info is worse than too much; etc).
  1048. * Personally I'd include everything, and use the coredump limit...
  1049. *
  1050. * I think we should skip something. But I am not sure how. H.J.
  1051. */
  1052. static int maydump(struct vm_area_struct *vma)
  1053. {
  1054. /* The vma can be set up to tell us the answer directly. */
  1055. if (vma->vm_flags & VM_ALWAYSDUMP)
  1056. return 1;
  1057. /* Do not dump I/O mapped devices or special mappings */
  1058. if (vma->vm_flags & (VM_IO | VM_RESERVED))
  1059. return 0;
  1060. /* Dump shared memory only if mapped from an anonymous file. */
  1061. if (vma->vm_flags & VM_SHARED)
  1062. return vma->vm_file->f_path.dentry->d_inode->i_nlink == 0;
  1063. /* If it hasn't been written to, don't write it out */
  1064. if (!vma->anon_vma)
  1065. return 0;
  1066. return 1;
  1067. }
  1068. /* An ELF note in memory */
  1069. struct memelfnote
  1070. {
  1071. const char *name;
  1072. int type;
  1073. unsigned int datasz;
  1074. void *data;
  1075. };
  1076. static int notesize(struct memelfnote *en)
  1077. {
  1078. int sz;
  1079. sz = sizeof(struct elf_note);
  1080. sz += roundup(strlen(en->name) + 1, 4);
  1081. sz += roundup(en->datasz, 4);
  1082. return sz;
  1083. }
  1084. #define DUMP_WRITE(addr, nr, foffset) \
  1085. do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0)
  1086. static int alignfile(struct file *file, loff_t *foffset)
  1087. {
  1088. static const char buf[4] = { 0, };
  1089. DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset);
  1090. return 1;
  1091. }
  1092. static int writenote(struct memelfnote *men, struct file *file,
  1093. loff_t *foffset)
  1094. {
  1095. struct elf_note en;
  1096. en.n_namesz = strlen(men->name) + 1;
  1097. en.n_descsz = men->datasz;
  1098. en.n_type = men->type;
  1099. DUMP_WRITE(&en, sizeof(en), foffset);
  1100. DUMP_WRITE(men->name, en.n_namesz, foffset);
  1101. if (!alignfile(file, foffset))
  1102. return 0;
  1103. DUMP_WRITE(men->data, men->datasz, foffset);
  1104. if (!alignfile(file, foffset))
  1105. return 0;
  1106. return 1;
  1107. }
  1108. #undef DUMP_WRITE
  1109. #define DUMP_WRITE(addr, nr) \
  1110. if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
  1111. goto end_coredump;
  1112. #define DUMP_SEEK(off) \
  1113. if (!dump_seek(file, (off))) \
  1114. goto end_coredump;
  1115. static void fill_elf_header(struct elfhdr *elf, int segs)
  1116. {
  1117. memcpy(elf->e_ident, ELFMAG, SELFMAG);
  1118. elf->e_ident[EI_CLASS] = ELF_CLASS;
  1119. elf->e_ident[EI_DATA] = ELF_DATA;
  1120. elf->e_ident[EI_VERSION] = EV_CURRENT;
  1121. elf->e_ident[EI_OSABI] = ELF_OSABI;
  1122. memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
  1123. elf->e_type = ET_CORE;
  1124. elf->e_machine = ELF_ARCH;
  1125. elf->e_version = EV_CURRENT;
  1126. elf->e_entry = 0;
  1127. elf->e_phoff = sizeof(struct elfhdr);
  1128. elf->e_shoff = 0;
  1129. elf->e_flags = ELF_CORE_EFLAGS;
  1130. elf->e_ehsize = sizeof(struct elfhdr);
  1131. elf->e_phentsize = sizeof(struct elf_phdr);
  1132. elf->e_phnum = segs;
  1133. elf->e_shentsize = 0;
  1134. elf->e_shnum = 0;
  1135. elf->e_shstrndx = 0;
  1136. return;
  1137. }
  1138. static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset)
  1139. {
  1140. phdr->p_type = PT_NOTE;
  1141. phdr->p_offset = offset;
  1142. phdr->p_vaddr = 0;
  1143. phdr->p_paddr = 0;
  1144. phdr->p_filesz = sz;
  1145. phdr->p_memsz = 0;
  1146. phdr->p_flags = 0;
  1147. phdr->p_align = 0;
  1148. return;
  1149. }
  1150. static void fill_note(struct memelfnote *note, const char *name, int type,
  1151. unsigned int sz, void *data)
  1152. {
  1153. note->name = name;
  1154. note->type = type;
  1155. note->datasz = sz;
  1156. note->data = data;
  1157. return;
  1158. }
  1159. /*
  1160. * fill up all the fields in prstatus from the given task struct, except
  1161. * registers which need to be filled up separately.
  1162. */
  1163. static void fill_prstatus(struct elf_prstatus *prstatus,
  1164. struct task_struct *p, long signr)
  1165. {
  1166. prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
  1167. prstatus->pr_sigpend = p->pending.signal.sig[0];
  1168. prstatus->pr_sighold = p->blocked.sig[0];
  1169. prstatus->pr_pid = p->pid;
  1170. prstatus->pr_ppid = p->parent->pid;
  1171. prstatus->pr_pgrp = process_group(p);
  1172. prstatus->pr_sid = process_session(p);
  1173. if (thread_group_leader(p)) {
  1174. /*
  1175. * This is the record for the group leader. Add in the
  1176. * cumulative times of previous dead threads. This total
  1177. * won't include the time of each live thread whose state
  1178. * is included in the core dump. The final total reported
  1179. * to our parent process when it calls wait4 will include
  1180. * those sums as well as the little bit more time it takes
  1181. * this and each other thread to finish dying after the
  1182. * core dump synchronization phase.
  1183. */
  1184. cputime_to_timeval(cputime_add(p->utime, p->signal->utime),
  1185. &prstatus->pr_utime);
  1186. cputime_to_timeval(cputime_add(p->stime, p->signal->stime),
  1187. &prstatus->pr_stime);
  1188. } else {
  1189. cputime_to_timeval(p->utime, &prstatus->pr_utime);
  1190. cputime_to_timeval(p->stime, &prstatus->pr_stime);
  1191. }
  1192. cputime_to_timeval(p->signal->cutime, &prstatus->pr_cutime);
  1193. cputime_to_timeval(p->signal->cstime, &prstatus->pr_cstime);
  1194. }
  1195. static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
  1196. struct mm_struct *mm)
  1197. {
  1198. unsigned int i, len;
  1199. /* first copy the parameters from user space */
  1200. memset(psinfo, 0, sizeof(struct elf_prpsinfo));
  1201. len = mm->arg_end - mm->arg_start;
  1202. if (len >= ELF_PRARGSZ)
  1203. len = ELF_PRARGSZ-1;
  1204. if (copy_from_user(&psinfo->pr_psargs,
  1205. (const char __user *)mm->arg_start, len))
  1206. return -EFAULT;
  1207. for(i = 0; i < len; i++)
  1208. if (psinfo->pr_psargs[i] == 0)
  1209. psinfo->pr_psargs[i] = ' ';
  1210. psinfo->pr_psargs[len] = 0;
  1211. psinfo->pr_pid = p->pid;
  1212. psinfo->pr_ppid = p->parent->pid;
  1213. psinfo->pr_pgrp = process_group(p);
  1214. psinfo->pr_sid = process_session(p);
  1215. i = p->state ? ffz(~p->state) + 1 : 0;
  1216. psinfo->pr_state = i;
  1217. psinfo->pr_sname = (i > 5) ? '.' : "RSDTZW"[i];
  1218. psinfo->pr_zomb = psinfo->pr_sname == 'Z';
  1219. psinfo->pr_nice = task_nice(p);
  1220. psinfo->pr_flag = p->flags;
  1221. SET_UID(psinfo->pr_uid, p->uid);
  1222. SET_GID(psinfo->pr_gid, p->gid);
  1223. strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname));
  1224. return 0;
  1225. }
  1226. /* Here is the structure in which status of each thread is captured. */
  1227. struct elf_thread_status
  1228. {
  1229. struct list_head list;
  1230. struct elf_prstatus prstatus; /* NT_PRSTATUS */
  1231. elf_fpregset_t fpu; /* NT_PRFPREG */
  1232. struct task_struct *thread;
  1233. #ifdef ELF_CORE_COPY_XFPREGS
  1234. elf_fpxregset_t xfpu; /* NT_PRXFPREG */
  1235. #endif
  1236. struct memelfnote notes[3];
  1237. int num_notes;
  1238. };
  1239. /*
  1240. * In order to add the specific thread information for the elf file format,
  1241. * we need to keep a linked list of every threads pr_status and then create
  1242. * a single section for them in the final core file.
  1243. */
  1244. static int elf_dump_thread_status(long signr, struct elf_thread_status *t)
  1245. {
  1246. int sz = 0;
  1247. struct task_struct *p = t->thread;
  1248. t->num_notes = 0;
  1249. fill_prstatus(&t->prstatus, p, signr);
  1250. elf_core_copy_task_regs(p, &t->prstatus.pr_reg);
  1251. fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus),
  1252. &(t->prstatus));
  1253. t->num_notes++;
  1254. sz += notesize(&t->notes[0]);
  1255. if ((t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL,
  1256. &t->fpu))) {
  1257. fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu),
  1258. &(t->fpu));
  1259. t->num_notes++;
  1260. sz += notesize(&t->notes[1]);
  1261. }
  1262. #ifdef ELF_CORE_COPY_XFPREGS
  1263. if (elf_core_copy_task_xfpregs(p, &t->xfpu)) {
  1264. fill_note(&t->notes[2], "LINUX", NT_PRXFPREG, sizeof(t->xfpu),
  1265. &t->xfpu);
  1266. t->num_notes++;
  1267. sz += notesize(&t->notes[2]);
  1268. }
  1269. #endif
  1270. return sz;
  1271. }
  1272. static struct vm_area_struct *first_vma(struct task_struct *tsk,
  1273. struct vm_area_struct *gate_vma)
  1274. {
  1275. struct vm_area_struct *ret = tsk->mm->mmap;
  1276. if (ret)
  1277. return ret;
  1278. return gate_vma;
  1279. }
  1280. /*
  1281. * Helper function for iterating across a vma list. It ensures that the caller
  1282. * will visit `gate_vma' prior to terminating the search.
  1283. */
  1284. static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
  1285. struct vm_area_struct *gate_vma)
  1286. {
  1287. struct vm_area_struct *ret;
  1288. ret = this_vma->vm_next;
  1289. if (ret)
  1290. return ret;
  1291. if (this_vma == gate_vma)
  1292. return NULL;
  1293. return gate_vma;
  1294. }
  1295. /*
  1296. * Actual dumper
  1297. *
  1298. * This is a two-pass process; first we find the offsets of the bits,
  1299. * and then they are actually written out. If we run out of core limit
  1300. * we just truncate.
  1301. */
  1302. static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file)
  1303. {
  1304. #define NUM_NOTES 6
  1305. int has_dumped = 0;
  1306. mm_segment_t fs;
  1307. int segs;
  1308. size_t size = 0;
  1309. int i;
  1310. struct vm_area_struct *vma, *gate_vma;
  1311. struct elfhdr *elf = NULL;
  1312. loff_t offset = 0, dataoff, foffset;
  1313. unsigned long limit = current->signal->rlim[RLIMIT_CORE].rlim_cur;
  1314. int numnote;
  1315. struct memelfnote *notes = NULL;
  1316. struct elf_prstatus *prstatus = NULL; /* NT_PRSTATUS */
  1317. struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
  1318. struct task_struct *g, *p;
  1319. LIST_HEAD(thread_list);
  1320. struct list_head *t;
  1321. elf_fpregset_t *fpu = NULL;
  1322. #ifdef ELF_CORE_COPY_XFPREGS
  1323. elf_fpxregset_t *xfpu = NULL;
  1324. #endif
  1325. int thread_status_size = 0;
  1326. elf_addr_t *auxv;
  1327. /*
  1328. * We no longer stop all VM operations.
  1329. *
  1330. * This is because those proceses that could possibly change map_count
  1331. * or the mmap / vma pages are now blocked in do_exit on current
  1332. * finishing this core dump.
  1333. *
  1334. * Only ptrace can touch these memory addresses, but it doesn't change
  1335. * the map_count or the pages allocated. So no possibility of crashing
  1336. * exists while dumping the mm->vm_next areas to the core file.
  1337. */
  1338. /* alloc memory for large data structures: too large to be on stack */
  1339. elf = kmalloc(sizeof(*elf), GFP_KERNEL);
  1340. if (!elf)
  1341. goto cleanup;
  1342. prstatus = kmalloc(sizeof(*prstatus), GFP_KERNEL);
  1343. if (!prstatus)
  1344. goto cleanup;
  1345. psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
  1346. if (!psinfo)
  1347. goto cleanup;
  1348. notes = kmalloc(NUM_NOTES * sizeof(struct memelfnote), GFP_KERNEL);
  1349. if (!notes)
  1350. goto cleanup;
  1351. fpu = kmalloc(sizeof(*fpu), GFP_KERNEL);
  1352. if (!fpu)
  1353. goto cleanup;
  1354. #ifdef ELF_CORE_COPY_XFPREGS
  1355. xfpu = kmalloc(sizeof(*xfpu), GFP_KERNEL);
  1356. if (!xfpu)
  1357. goto cleanup;
  1358. #endif
  1359. if (signr) {
  1360. struct elf_thread_status *tmp;
  1361. rcu_read_lock();
  1362. do_each_thread(g,p)
  1363. if (current->mm == p->mm && current != p) {
  1364. tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC);
  1365. if (!tmp) {
  1366. rcu_read_unlock();
  1367. goto cleanup;
  1368. }
  1369. tmp->thread = p;
  1370. list_add(&tmp->list, &thread_list);
  1371. }
  1372. while_each_thread(g,p);
  1373. rcu_read_unlock();
  1374. list_for_each(t, &thread_list) {
  1375. struct elf_thread_status *tmp;
  1376. int sz;
  1377. tmp = list_entry(t, struct elf_thread_status, list);
  1378. sz = elf_dump_thread_status(signr, tmp);
  1379. thread_status_size += sz;
  1380. }
  1381. }
  1382. /* now collect the dump for the current */
  1383. memset(prstatus, 0, sizeof(*prstatus));
  1384. fill_prstatus(prstatus, current, signr);
  1385. elf_core_copy_regs(&prstatus->pr_reg, regs);
  1386. segs = current->mm->map_count;
  1387. #ifdef ELF_CORE_EXTRA_PHDRS
  1388. segs += ELF_CORE_EXTRA_PHDRS;
  1389. #endif
  1390. gate_vma = get_gate_vma(current);
  1391. if (gate_vma != NULL)
  1392. segs++;
  1393. /* Set up header */
  1394. fill_elf_header(elf, segs + 1); /* including notes section */
  1395. has_dumped = 1;
  1396. current->flags |= PF_DUMPCORE;
  1397. /*
  1398. * Set up the notes in similar form to SVR4 core dumps made
  1399. * with info from their /proc.
  1400. */
  1401. fill_note(notes + 0, "CORE", NT_PRSTATUS, sizeof(*prstatus), prstatus);
  1402. fill_psinfo(psinfo, current->group_leader, current->mm);
  1403. fill_note(notes + 1, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
  1404. numnote = 2;
  1405. auxv = (elf_addr_t *)current->mm->saved_auxv;
  1406. i = 0;
  1407. do
  1408. i += 2;
  1409. while (auxv[i - 2] != AT_NULL);
  1410. fill_note(&notes[numnote++], "CORE", NT_AUXV,
  1411. i * sizeof(elf_addr_t), auxv);
  1412. /* Try to dump the FPU. */
  1413. if ((prstatus->pr_fpvalid =
  1414. elf_core_copy_task_fpregs(current, regs, fpu)))
  1415. fill_note(notes + numnote++,
  1416. "CORE", NT_PRFPREG, sizeof(*fpu), fpu);
  1417. #ifdef ELF_CORE_COPY_XFPREGS
  1418. if (elf_core_copy_task_xfpregs(current, xfpu))
  1419. fill_note(notes + numnote++,
  1420. "LINUX", NT_PRXFPREG, sizeof(*xfpu), xfpu);
  1421. #endif
  1422. fs = get_fs();
  1423. set_fs(KERNEL_DS);
  1424. DUMP_WRITE(elf, sizeof(*elf));
  1425. offset += sizeof(*elf); /* Elf header */
  1426. offset += (segs + 1) * sizeof(struct elf_phdr); /* Program headers */
  1427. foffset = offset;
  1428. /* Write notes phdr entry */
  1429. {
  1430. struct elf_phdr phdr;
  1431. int sz = 0;
  1432. for (i = 0; i < numnote; i++)
  1433. sz += notesize(notes + i);
  1434. sz += thread_status_size;
  1435. #ifdef ELF_CORE_WRITE_EXTRA_NOTES
  1436. sz += ELF_CORE_EXTRA_NOTES_SIZE;
  1437. #endif
  1438. fill_elf_note_phdr(&phdr, sz, offset);
  1439. offset += sz;
  1440. DUMP_WRITE(&phdr, sizeof(phdr));
  1441. }
  1442. dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
  1443. /* Write program headers for segments dump */
  1444. for (vma = first_vma(current, gate_vma); vma != NULL;
  1445. vma = next_vma(vma, gate_vma)) {
  1446. struct elf_phdr phdr;
  1447. size_t sz;
  1448. sz = vma->vm_end - vma->vm_start;
  1449. phdr.p_type = PT_LOAD;
  1450. phdr.p_offset = offset;
  1451. phdr.p_vaddr = vma->vm_start;
  1452. phdr.p_paddr = 0;
  1453. phdr.p_filesz = maydump(vma) ? sz : 0;
  1454. phdr.p_memsz = sz;
  1455. offset += phdr.p_filesz;
  1456. phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
  1457. if (vma->vm_flags & VM_WRITE)
  1458. phdr.p_flags |= PF_W;
  1459. if (vma->vm_flags & VM_EXEC)
  1460. phdr.p_flags |= PF_X;
  1461. phdr.p_align = ELF_EXEC_PAGESIZE;
  1462. DUMP_WRITE(&phdr, sizeof(phdr));
  1463. }
  1464. #ifdef ELF_CORE_WRITE_EXTRA_PHDRS
  1465. ELF_CORE_WRITE_EXTRA_PHDRS;
  1466. #endif
  1467. /* write out the notes section */
  1468. for (i = 0; i < numnote; i++)
  1469. if (!writenote(notes + i, file, &foffset))
  1470. goto end_coredump;
  1471. #ifdef ELF_CORE_WRITE_EXTRA_NOTES
  1472. ELF_CORE_WRITE_EXTRA_NOTES;
  1473. #endif
  1474. /* write out the thread status notes section */
  1475. list_for_each(t, &thread_list) {
  1476. struct elf_thread_status *tmp =
  1477. list_entry(t, struct elf_thread_status, list);
  1478. for (i = 0; i < tmp->num_notes; i++)
  1479. if (!writenote(&tmp->notes[i], file, &foffset))
  1480. goto end_coredump;
  1481. }
  1482. /* Align to page */
  1483. DUMP_SEEK(dataoff - foffset);
  1484. for (vma = first_vma(current, gate_vma); vma != NULL;
  1485. vma = next_vma(vma, gate_vma)) {
  1486. unsigned long addr;
  1487. if (!maydump(vma))
  1488. continue;
  1489. for (addr = vma->vm_start;
  1490. addr < vma->vm_end;
  1491. addr += PAGE_SIZE) {
  1492. struct page *page;
  1493. struct vm_area_struct *vma;
  1494. if (get_user_pages(current, current->mm, addr, 1, 0, 1,
  1495. &page, &vma) <= 0) {
  1496. DUMP_SEEK(PAGE_SIZE);
  1497. } else {
  1498. if (page == ZERO_PAGE(addr)) {
  1499. if (!dump_seek(file, PAGE_SIZE)) {
  1500. page_cache_release(page);
  1501. goto end_coredump;
  1502. }
  1503. } else {
  1504. void *kaddr;
  1505. flush_cache_page(vma, addr,
  1506. page_to_pfn(page));
  1507. kaddr = kmap(page);
  1508. if ((size += PAGE_SIZE) > limit ||
  1509. !dump_write(file, kaddr,
  1510. PAGE_SIZE)) {
  1511. kunmap(page);
  1512. page_cache_release(page);
  1513. goto end_coredump;
  1514. }
  1515. kunmap(page);
  1516. }
  1517. page_cache_release(page);
  1518. }
  1519. }
  1520. }
  1521. #ifdef ELF_CORE_WRITE_EXTRA_DATA
  1522. ELF_CORE_WRITE_EXTRA_DATA;
  1523. #endif
  1524. end_coredump:
  1525. set_fs(fs);
  1526. cleanup:
  1527. while (!list_empty(&thread_list)) {
  1528. struct list_head *tmp = thread_list.next;
  1529. list_del(tmp);
  1530. kfree(list_entry(tmp, struct elf_thread_status, list));
  1531. }
  1532. kfree(elf);
  1533. kfree(prstatus);
  1534. kfree(psinfo);
  1535. kfree(notes);
  1536. kfree(fpu);
  1537. #ifdef ELF_CORE_COPY_XFPREGS
  1538. kfree(xfpu);
  1539. #endif
  1540. return has_dumped;
  1541. #undef NUM_NOTES
  1542. }
  1543. #endif /* USE_ELF_CORE_DUMP */
  1544. static int __init init_elf_binfmt(void)
  1545. {
  1546. return register_binfmt(&elf_format);
  1547. }
  1548. static void __exit exit_elf_binfmt(void)
  1549. {
  1550. /* Remove the COFF and ELF loaders. */
  1551. unregister_binfmt(&elf_format);
  1552. }
  1553. core_initcall(init_elf_binfmt);
  1554. module_exit(exit_elf_binfmt);
  1555. MODULE_LICENSE("GPL");