binfmt_elf_fdpic.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. /* binfmt_elf_fdpic.c: FDPIC ELF binary format
  2. *
  3. * Copyright (C) 2003, 2004, 2006 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. * Derived from binfmt_elf.c
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/fs.h>
  14. #include <linux/stat.h>
  15. #include <linux/sched.h>
  16. #include <linux/mm.h>
  17. #include <linux/mman.h>
  18. #include <linux/errno.h>
  19. #include <linux/signal.h>
  20. #include <linux/binfmts.h>
  21. #include <linux/string.h>
  22. #include <linux/file.h>
  23. #include <linux/fcntl.h>
  24. #include <linux/slab.h>
  25. #include <linux/pagemap.h>
  26. #include <linux/highmem.h>
  27. #include <linux/highuid.h>
  28. #include <linux/personality.h>
  29. #include <linux/ptrace.h>
  30. #include <linux/init.h>
  31. #include <linux/smp_lock.h>
  32. #include <linux/elf.h>
  33. #include <linux/elf-fdpic.h>
  34. #include <linux/elfcore.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/param.h>
  37. #include <asm/pgalloc.h>
  38. typedef char *elf_caddr_t;
  39. #ifndef elf_addr_t
  40. #define elf_addr_t unsigned long
  41. #endif
  42. #if 0
  43. #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ )
  44. #else
  45. #define kdebug(fmt, ...) do {} while(0)
  46. #endif
  47. #if 0
  48. #define kdcore(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ )
  49. #else
  50. #define kdcore(fmt, ...) do {} while(0)
  51. #endif
  52. MODULE_LICENSE("GPL");
  53. static int load_elf_fdpic_binary(struct linux_binprm *, struct pt_regs *);
  54. static int elf_fdpic_fetch_phdrs(struct elf_fdpic_params *, struct file *);
  55. static int elf_fdpic_map_file(struct elf_fdpic_params *, struct file *,
  56. struct mm_struct *, const char *);
  57. static int create_elf_fdpic_tables(struct linux_binprm *, struct mm_struct *,
  58. struct elf_fdpic_params *,
  59. struct elf_fdpic_params *);
  60. #ifndef CONFIG_MMU
  61. static int elf_fdpic_transfer_args_to_stack(struct linux_binprm *,
  62. unsigned long *);
  63. static int elf_fdpic_map_file_constdisp_on_uclinux(struct elf_fdpic_params *,
  64. struct file *,
  65. struct mm_struct *);
  66. #endif
  67. static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *,
  68. struct file *, struct mm_struct *);
  69. #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
  70. static int elf_fdpic_core_dump(long, struct pt_regs *, struct file *);
  71. #endif
  72. static struct linux_binfmt elf_fdpic_format = {
  73. .module = THIS_MODULE,
  74. .load_binary = load_elf_fdpic_binary,
  75. #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
  76. .core_dump = elf_fdpic_core_dump,
  77. #endif
  78. .min_coredump = ELF_EXEC_PAGESIZE,
  79. };
  80. static int __init init_elf_fdpic_binfmt(void)
  81. {
  82. return register_binfmt(&elf_fdpic_format);
  83. }
  84. static void __exit exit_elf_fdpic_binfmt(void)
  85. {
  86. unregister_binfmt(&elf_fdpic_format);
  87. }
  88. core_initcall(init_elf_fdpic_binfmt);
  89. module_exit(exit_elf_fdpic_binfmt);
  90. static int is_elf_fdpic(struct elfhdr *hdr, struct file *file)
  91. {
  92. if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0)
  93. return 0;
  94. if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN)
  95. return 0;
  96. if (!elf_check_arch(hdr) || !elf_check_fdpic(hdr))
  97. return 0;
  98. if (!file->f_op || !file->f_op->mmap)
  99. return 0;
  100. return 1;
  101. }
  102. /*****************************************************************************/
  103. /*
  104. * read the program headers table into memory
  105. */
  106. static int elf_fdpic_fetch_phdrs(struct elf_fdpic_params *params,
  107. struct file *file)
  108. {
  109. struct elf32_phdr *phdr;
  110. unsigned long size;
  111. int retval, loop;
  112. if (params->hdr.e_phentsize != sizeof(struct elf_phdr))
  113. return -ENOMEM;
  114. if (params->hdr.e_phnum > 65536U / sizeof(struct elf_phdr))
  115. return -ENOMEM;
  116. size = params->hdr.e_phnum * sizeof(struct elf_phdr);
  117. params->phdrs = kmalloc(size, GFP_KERNEL);
  118. if (!params->phdrs)
  119. return -ENOMEM;
  120. retval = kernel_read(file, params->hdr.e_phoff,
  121. (char *) params->phdrs, size);
  122. if (retval < 0)
  123. return retval;
  124. /* determine stack size for this binary */
  125. phdr = params->phdrs;
  126. for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
  127. if (phdr->p_type != PT_GNU_STACK)
  128. continue;
  129. if (phdr->p_flags & PF_X)
  130. params->flags |= ELF_FDPIC_FLAG_EXEC_STACK;
  131. else
  132. params->flags |= ELF_FDPIC_FLAG_NOEXEC_STACK;
  133. params->stack_size = phdr->p_memsz;
  134. break;
  135. }
  136. return 0;
  137. }
  138. /*****************************************************************************/
  139. /*
  140. * load an fdpic binary into various bits of memory
  141. */
  142. static int load_elf_fdpic_binary(struct linux_binprm *bprm,
  143. struct pt_regs *regs)
  144. {
  145. struct elf_fdpic_params exec_params, interp_params;
  146. struct elf_phdr *phdr;
  147. unsigned long stack_size, entryaddr;
  148. #ifndef CONFIG_MMU
  149. unsigned long fullsize;
  150. #endif
  151. #ifdef ELF_FDPIC_PLAT_INIT
  152. unsigned long dynaddr;
  153. #endif
  154. struct file *interpreter = NULL; /* to shut gcc up */
  155. char *interpreter_name = NULL;
  156. int executable_stack;
  157. int retval, i;
  158. memset(&exec_params, 0, sizeof(exec_params));
  159. memset(&interp_params, 0, sizeof(interp_params));
  160. exec_params.hdr = *(struct elfhdr *) bprm->buf;
  161. exec_params.flags = ELF_FDPIC_FLAG_PRESENT | ELF_FDPIC_FLAG_EXECUTABLE;
  162. /* check that this is a binary we know how to deal with */
  163. retval = -ENOEXEC;
  164. if (!is_elf_fdpic(&exec_params.hdr, bprm->file))
  165. goto error;
  166. /* read the program header table */
  167. retval = elf_fdpic_fetch_phdrs(&exec_params, bprm->file);
  168. if (retval < 0)
  169. goto error;
  170. /* scan for a program header that specifies an interpreter */
  171. phdr = exec_params.phdrs;
  172. for (i = 0; i < exec_params.hdr.e_phnum; i++, phdr++) {
  173. switch (phdr->p_type) {
  174. case PT_INTERP:
  175. retval = -ENOMEM;
  176. if (phdr->p_filesz > PATH_MAX)
  177. goto error;
  178. retval = -ENOENT;
  179. if (phdr->p_filesz < 2)
  180. goto error;
  181. /* read the name of the interpreter into memory */
  182. interpreter_name = kmalloc(phdr->p_filesz, GFP_KERNEL);
  183. if (!interpreter_name)
  184. goto error;
  185. retval = kernel_read(bprm->file,
  186. phdr->p_offset,
  187. interpreter_name,
  188. phdr->p_filesz);
  189. if (retval < 0)
  190. goto error;
  191. retval = -ENOENT;
  192. if (interpreter_name[phdr->p_filesz - 1] != '\0')
  193. goto error;
  194. kdebug("Using ELF interpreter %s", interpreter_name);
  195. /* replace the program with the interpreter */
  196. interpreter = open_exec(interpreter_name);
  197. retval = PTR_ERR(interpreter);
  198. if (IS_ERR(interpreter)) {
  199. interpreter = NULL;
  200. goto error;
  201. }
  202. retval = kernel_read(interpreter, 0, bprm->buf,
  203. BINPRM_BUF_SIZE);
  204. if (retval < 0)
  205. goto error;
  206. interp_params.hdr = *((struct elfhdr *) bprm->buf);
  207. break;
  208. case PT_LOAD:
  209. #ifdef CONFIG_MMU
  210. if (exec_params.load_addr == 0)
  211. exec_params.load_addr = phdr->p_vaddr;
  212. #endif
  213. break;
  214. }
  215. }
  216. if (elf_check_const_displacement(&exec_params.hdr))
  217. exec_params.flags |= ELF_FDPIC_FLAG_CONSTDISP;
  218. /* perform insanity checks on the interpreter */
  219. if (interpreter_name) {
  220. retval = -ELIBBAD;
  221. if (!is_elf_fdpic(&interp_params.hdr, interpreter))
  222. goto error;
  223. interp_params.flags = ELF_FDPIC_FLAG_PRESENT;
  224. /* read the interpreter's program header table */
  225. retval = elf_fdpic_fetch_phdrs(&interp_params, interpreter);
  226. if (retval < 0)
  227. goto error;
  228. }
  229. stack_size = exec_params.stack_size;
  230. if (stack_size < interp_params.stack_size)
  231. stack_size = interp_params.stack_size;
  232. if (exec_params.flags & ELF_FDPIC_FLAG_EXEC_STACK)
  233. executable_stack = EXSTACK_ENABLE_X;
  234. else if (exec_params.flags & ELF_FDPIC_FLAG_NOEXEC_STACK)
  235. executable_stack = EXSTACK_DISABLE_X;
  236. else if (interp_params.flags & ELF_FDPIC_FLAG_EXEC_STACK)
  237. executable_stack = EXSTACK_ENABLE_X;
  238. else if (interp_params.flags & ELF_FDPIC_FLAG_NOEXEC_STACK)
  239. executable_stack = EXSTACK_DISABLE_X;
  240. else
  241. executable_stack = EXSTACK_DEFAULT;
  242. retval = -ENOEXEC;
  243. if (stack_size == 0)
  244. goto error;
  245. if (elf_check_const_displacement(&interp_params.hdr))
  246. interp_params.flags |= ELF_FDPIC_FLAG_CONSTDISP;
  247. /* flush all traces of the currently running executable */
  248. retval = flush_old_exec(bprm);
  249. if (retval)
  250. goto error;
  251. /* there's now no turning back... the old userspace image is dead,
  252. * defunct, deceased, etc. after this point we have to exit via
  253. * error_kill */
  254. set_personality(PER_LINUX_FDPIC);
  255. set_binfmt(&elf_fdpic_format);
  256. current->mm->start_code = 0;
  257. current->mm->end_code = 0;
  258. current->mm->start_stack = 0;
  259. current->mm->start_data = 0;
  260. current->mm->end_data = 0;
  261. current->mm->context.exec_fdpic_loadmap = 0;
  262. current->mm->context.interp_fdpic_loadmap = 0;
  263. current->flags &= ~PF_FORKNOEXEC;
  264. #ifdef CONFIG_MMU
  265. elf_fdpic_arch_lay_out_mm(&exec_params,
  266. &interp_params,
  267. &current->mm->start_stack,
  268. &current->mm->start_brk);
  269. retval = setup_arg_pages(bprm, current->mm->start_stack,
  270. executable_stack);
  271. if (retval < 0) {
  272. send_sig(SIGKILL, current, 0);
  273. goto error_kill;
  274. }
  275. #endif
  276. /* load the executable and interpreter into memory */
  277. retval = elf_fdpic_map_file(&exec_params, bprm->file, current->mm,
  278. "executable");
  279. if (retval < 0)
  280. goto error_kill;
  281. if (interpreter_name) {
  282. retval = elf_fdpic_map_file(&interp_params, interpreter,
  283. current->mm, "interpreter");
  284. if (retval < 0) {
  285. printk(KERN_ERR "Unable to load interpreter\n");
  286. goto error_kill;
  287. }
  288. allow_write_access(interpreter);
  289. fput(interpreter);
  290. interpreter = NULL;
  291. }
  292. #ifdef CONFIG_MMU
  293. if (!current->mm->start_brk)
  294. current->mm->start_brk = current->mm->end_data;
  295. current->mm->brk = current->mm->start_brk =
  296. PAGE_ALIGN(current->mm->start_brk);
  297. #else
  298. /* create a stack and brk area big enough for everyone
  299. * - the brk heap starts at the bottom and works up
  300. * - the stack starts at the top and works down
  301. */
  302. stack_size = (stack_size + PAGE_SIZE - 1) & PAGE_MASK;
  303. if (stack_size < PAGE_SIZE * 2)
  304. stack_size = PAGE_SIZE * 2;
  305. down_write(&current->mm->mmap_sem);
  306. current->mm->start_brk = do_mmap(NULL, 0, stack_size,
  307. PROT_READ | PROT_WRITE | PROT_EXEC,
  308. MAP_PRIVATE | MAP_ANON | MAP_GROWSDOWN,
  309. 0);
  310. if (IS_ERR_VALUE(current->mm->start_brk)) {
  311. up_write(&current->mm->mmap_sem);
  312. retval = current->mm->start_brk;
  313. current->mm->start_brk = 0;
  314. goto error_kill;
  315. }
  316. /* expand the stack mapping to use up the entire allocation granule */
  317. fullsize = ksize((char *) current->mm->start_brk);
  318. if (!IS_ERR_VALUE(do_mremap(current->mm->start_brk, stack_size,
  319. fullsize, 0, 0)))
  320. stack_size = fullsize;
  321. up_write(&current->mm->mmap_sem);
  322. current->mm->brk = current->mm->start_brk;
  323. current->mm->context.end_brk = current->mm->start_brk;
  324. current->mm->context.end_brk +=
  325. (stack_size > PAGE_SIZE) ? (stack_size - PAGE_SIZE) : 0;
  326. current->mm->start_stack = current->mm->start_brk + stack_size;
  327. #endif
  328. compute_creds(bprm);
  329. current->flags &= ~PF_FORKNOEXEC;
  330. if (create_elf_fdpic_tables(bprm, current->mm,
  331. &exec_params, &interp_params) < 0)
  332. goto error_kill;
  333. kdebug("- start_code %lx", current->mm->start_code);
  334. kdebug("- end_code %lx", current->mm->end_code);
  335. kdebug("- start_data %lx", current->mm->start_data);
  336. kdebug("- end_data %lx", current->mm->end_data);
  337. kdebug("- start_brk %lx", current->mm->start_brk);
  338. kdebug("- brk %lx", current->mm->brk);
  339. kdebug("- start_stack %lx", current->mm->start_stack);
  340. #ifdef ELF_FDPIC_PLAT_INIT
  341. /*
  342. * The ABI may specify that certain registers be set up in special
  343. * ways (on i386 %edx is the address of a DT_FINI function, for
  344. * example. This macro performs whatever initialization to
  345. * the regs structure is required.
  346. */
  347. dynaddr = interp_params.dynamic_addr ?: exec_params.dynamic_addr;
  348. ELF_FDPIC_PLAT_INIT(regs, exec_params.map_addr, interp_params.map_addr,
  349. dynaddr);
  350. #endif
  351. /* everything is now ready... get the userspace context ready to roll */
  352. entryaddr = interp_params.entry_addr ?: exec_params.entry_addr;
  353. start_thread(regs, entryaddr, current->mm->start_stack);
  354. if (unlikely(current->ptrace & PT_PTRACED)) {
  355. if (current->ptrace & PT_TRACE_EXEC)
  356. ptrace_notify((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
  357. else
  358. send_sig(SIGTRAP, current, 0);
  359. }
  360. retval = 0;
  361. error:
  362. if (interpreter) {
  363. allow_write_access(interpreter);
  364. fput(interpreter);
  365. }
  366. kfree(interpreter_name);
  367. kfree(exec_params.phdrs);
  368. kfree(exec_params.loadmap);
  369. kfree(interp_params.phdrs);
  370. kfree(interp_params.loadmap);
  371. return retval;
  372. /* unrecoverable error - kill the process */
  373. error_kill:
  374. send_sig(SIGSEGV, current, 0);
  375. goto error;
  376. }
  377. /*****************************************************************************/
  378. /*
  379. * present useful information to the program
  380. */
  381. static int create_elf_fdpic_tables(struct linux_binprm *bprm,
  382. struct mm_struct *mm,
  383. struct elf_fdpic_params *exec_params,
  384. struct elf_fdpic_params *interp_params)
  385. {
  386. unsigned long sp, csp, nitems;
  387. elf_caddr_t __user *argv, *envp;
  388. size_t platform_len = 0, len;
  389. char *k_platform;
  390. char __user *u_platform, *p;
  391. long hwcap;
  392. int loop;
  393. /* we're going to shovel a whole load of stuff onto the stack */
  394. #ifdef CONFIG_MMU
  395. sp = bprm->p;
  396. #else
  397. sp = mm->start_stack;
  398. /* stack the program arguments and environment */
  399. if (elf_fdpic_transfer_args_to_stack(bprm, &sp) < 0)
  400. return -EFAULT;
  401. #endif
  402. /* get hold of platform and hardware capabilities masks for the machine
  403. * we are running on. In some cases (Sparc), this info is impossible
  404. * to get, in others (i386) it is merely difficult.
  405. */
  406. hwcap = ELF_HWCAP;
  407. k_platform = ELF_PLATFORM;
  408. u_platform = NULL;
  409. if (k_platform) {
  410. platform_len = strlen(k_platform) + 1;
  411. sp -= platform_len;
  412. u_platform = (char __user *) sp;
  413. if (__copy_to_user(u_platform, k_platform, platform_len) != 0)
  414. return -EFAULT;
  415. }
  416. #if defined(__i386__) && defined(CONFIG_SMP)
  417. /* in some cases (e.g. Hyper-Threading), we want to avoid L1 evictions
  418. * by the processes running on the same package. One thing we can do is
  419. * to shuffle the initial stack for them.
  420. *
  421. * the conditionals here are unneeded, but kept in to make the code
  422. * behaviour the same as pre change unless we have hyperthreaded
  423. * processors. This keeps Mr Marcelo Person happier but should be
  424. * removed for 2.5
  425. */
  426. if (smp_num_siblings > 1)
  427. sp = sp - ((current->pid % 64) << 7);
  428. #endif
  429. sp &= ~7UL;
  430. /* stack the load map(s) */
  431. len = sizeof(struct elf32_fdpic_loadmap);
  432. len += sizeof(struct elf32_fdpic_loadseg) * exec_params->loadmap->nsegs;
  433. sp = (sp - len) & ~7UL;
  434. exec_params->map_addr = sp;
  435. if (copy_to_user((void __user *) sp, exec_params->loadmap, len) != 0)
  436. return -EFAULT;
  437. current->mm->context.exec_fdpic_loadmap = (unsigned long) sp;
  438. if (interp_params->loadmap) {
  439. len = sizeof(struct elf32_fdpic_loadmap);
  440. len += sizeof(struct elf32_fdpic_loadseg) *
  441. interp_params->loadmap->nsegs;
  442. sp = (sp - len) & ~7UL;
  443. interp_params->map_addr = sp;
  444. if (copy_to_user((void __user *) sp, interp_params->loadmap,
  445. len) != 0)
  446. return -EFAULT;
  447. current->mm->context.interp_fdpic_loadmap = (unsigned long) sp;
  448. }
  449. /* force 16 byte _final_ alignment here for generality */
  450. #define DLINFO_ITEMS 13
  451. nitems = 1 + DLINFO_ITEMS + (k_platform ? 1 : 0);
  452. #ifdef DLINFO_ARCH_ITEMS
  453. nitems += DLINFO_ARCH_ITEMS;
  454. #endif
  455. csp = sp;
  456. sp -= nitems * 2 * sizeof(unsigned long);
  457. sp -= (bprm->envc + 1) * sizeof(char *); /* envv[] */
  458. sp -= (bprm->argc + 1) * sizeof(char *); /* argv[] */
  459. sp -= 1 * sizeof(unsigned long); /* argc */
  460. csp -= sp & 15UL;
  461. sp -= sp & 15UL;
  462. /* put the ELF interpreter info on the stack */
  463. #define NEW_AUX_ENT(nr, id, val) \
  464. do { \
  465. struct { unsigned long _id, _val; } __user *ent; \
  466. \
  467. ent = (void __user *) csp; \
  468. __put_user((id), &ent[nr]._id); \
  469. __put_user((val), &ent[nr]._val); \
  470. } while (0)
  471. csp -= 2 * sizeof(unsigned long);
  472. NEW_AUX_ENT(0, AT_NULL, 0);
  473. if (k_platform) {
  474. csp -= 2 * sizeof(unsigned long);
  475. NEW_AUX_ENT(0, AT_PLATFORM,
  476. (elf_addr_t) (unsigned long) u_platform);
  477. }
  478. csp -= DLINFO_ITEMS * 2 * sizeof(unsigned long);
  479. NEW_AUX_ENT( 0, AT_HWCAP, hwcap);
  480. NEW_AUX_ENT( 1, AT_PAGESZ, PAGE_SIZE);
  481. NEW_AUX_ENT( 2, AT_CLKTCK, CLOCKS_PER_SEC);
  482. NEW_AUX_ENT( 3, AT_PHDR, exec_params->ph_addr);
  483. NEW_AUX_ENT( 4, AT_PHENT, sizeof(struct elf_phdr));
  484. NEW_AUX_ENT( 5, AT_PHNUM, exec_params->hdr.e_phnum);
  485. NEW_AUX_ENT( 6, AT_BASE, interp_params->elfhdr_addr);
  486. NEW_AUX_ENT( 7, AT_FLAGS, 0);
  487. NEW_AUX_ENT( 8, AT_ENTRY, exec_params->entry_addr);
  488. NEW_AUX_ENT( 9, AT_UID, (elf_addr_t) current->uid);
  489. NEW_AUX_ENT(10, AT_EUID, (elf_addr_t) current->euid);
  490. NEW_AUX_ENT(11, AT_GID, (elf_addr_t) current->gid);
  491. NEW_AUX_ENT(12, AT_EGID, (elf_addr_t) current->egid);
  492. #ifdef ARCH_DLINFO
  493. /* ARCH_DLINFO must come last so platform specific code can enforce
  494. * special alignment requirements on the AUXV if necessary (eg. PPC).
  495. */
  496. ARCH_DLINFO;
  497. #endif
  498. #undef NEW_AUX_ENT
  499. /* allocate room for argv[] and envv[] */
  500. csp -= (bprm->envc + 1) * sizeof(elf_caddr_t);
  501. envp = (elf_caddr_t __user *) csp;
  502. csp -= (bprm->argc + 1) * sizeof(elf_caddr_t);
  503. argv = (elf_caddr_t __user *) csp;
  504. /* stack argc */
  505. csp -= sizeof(unsigned long);
  506. __put_user(bprm->argc, (unsigned long __user *) csp);
  507. BUG_ON(csp != sp);
  508. /* fill in the argv[] array */
  509. #ifdef CONFIG_MMU
  510. current->mm->arg_start = bprm->p;
  511. #else
  512. current->mm->arg_start = current->mm->start_stack -
  513. (MAX_ARG_PAGES * PAGE_SIZE - bprm->p);
  514. #endif
  515. p = (char __user *) current->mm->arg_start;
  516. for (loop = bprm->argc; loop > 0; loop--) {
  517. __put_user((elf_caddr_t) p, argv++);
  518. len = strnlen_user(p, PAGE_SIZE * MAX_ARG_PAGES);
  519. if (!len || len > PAGE_SIZE * MAX_ARG_PAGES)
  520. return -EINVAL;
  521. p += len;
  522. }
  523. __put_user(NULL, argv);
  524. current->mm->arg_end = (unsigned long) p;
  525. /* fill in the envv[] array */
  526. current->mm->env_start = (unsigned long) p;
  527. for (loop = bprm->envc; loop > 0; loop--) {
  528. __put_user((elf_caddr_t)(unsigned long) p, envp++);
  529. len = strnlen_user(p, PAGE_SIZE * MAX_ARG_PAGES);
  530. if (!len || len > PAGE_SIZE * MAX_ARG_PAGES)
  531. return -EINVAL;
  532. p += len;
  533. }
  534. __put_user(NULL, envp);
  535. current->mm->env_end = (unsigned long) p;
  536. mm->start_stack = (unsigned long) sp;
  537. return 0;
  538. }
  539. /*****************************************************************************/
  540. /*
  541. * transfer the program arguments and environment from the holding pages onto
  542. * the stack
  543. */
  544. #ifndef CONFIG_MMU
  545. static int elf_fdpic_transfer_args_to_stack(struct linux_binprm *bprm,
  546. unsigned long *_sp)
  547. {
  548. unsigned long index, stop, sp;
  549. char *src;
  550. int ret = 0;
  551. stop = bprm->p >> PAGE_SHIFT;
  552. sp = *_sp;
  553. for (index = MAX_ARG_PAGES - 1; index >= stop; index--) {
  554. src = kmap(bprm->page[index]);
  555. sp -= PAGE_SIZE;
  556. if (copy_to_user((void *) sp, src, PAGE_SIZE) != 0)
  557. ret = -EFAULT;
  558. kunmap(bprm->page[index]);
  559. if (ret < 0)
  560. goto out;
  561. }
  562. *_sp = (*_sp - (MAX_ARG_PAGES * PAGE_SIZE - bprm->p)) & ~15;
  563. out:
  564. return ret;
  565. }
  566. #endif
  567. /*****************************************************************************/
  568. /*
  569. * load the appropriate binary image (executable or interpreter) into memory
  570. * - we assume no MMU is available
  571. * - if no other PIC bits are set in params->hdr->e_flags
  572. * - we assume that the LOADable segments in the binary are independently relocatable
  573. * - we assume R/O executable segments are shareable
  574. * - else
  575. * - we assume the loadable parts of the image to require fixed displacement
  576. * - the image is not shareable
  577. */
  578. static int elf_fdpic_map_file(struct elf_fdpic_params *params,
  579. struct file *file,
  580. struct mm_struct *mm,
  581. const char *what)
  582. {
  583. struct elf32_fdpic_loadmap *loadmap;
  584. #ifdef CONFIG_MMU
  585. struct elf32_fdpic_loadseg *mseg;
  586. #endif
  587. struct elf32_fdpic_loadseg *seg;
  588. struct elf32_phdr *phdr;
  589. unsigned long load_addr, stop;
  590. unsigned nloads, tmp;
  591. size_t size;
  592. int loop, ret;
  593. /* allocate a load map table */
  594. nloads = 0;
  595. for (loop = 0; loop < params->hdr.e_phnum; loop++)
  596. if (params->phdrs[loop].p_type == PT_LOAD)
  597. nloads++;
  598. if (nloads == 0)
  599. return -ELIBBAD;
  600. size = sizeof(*loadmap) + nloads * sizeof(*seg);
  601. loadmap = kmalloc(size, GFP_KERNEL);
  602. if (!loadmap)
  603. return -ENOMEM;
  604. params->loadmap = loadmap;
  605. memset(loadmap, 0, size);
  606. loadmap->version = ELF32_FDPIC_LOADMAP_VERSION;
  607. loadmap->nsegs = nloads;
  608. load_addr = params->load_addr;
  609. seg = loadmap->segs;
  610. /* map the requested LOADs into the memory space */
  611. switch (params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) {
  612. case ELF_FDPIC_FLAG_CONSTDISP:
  613. case ELF_FDPIC_FLAG_CONTIGUOUS:
  614. #ifndef CONFIG_MMU
  615. ret = elf_fdpic_map_file_constdisp_on_uclinux(params, file, mm);
  616. if (ret < 0)
  617. return ret;
  618. break;
  619. #endif
  620. default:
  621. ret = elf_fdpic_map_file_by_direct_mmap(params, file, mm);
  622. if (ret < 0)
  623. return ret;
  624. break;
  625. }
  626. /* map the entry point */
  627. if (params->hdr.e_entry) {
  628. seg = loadmap->segs;
  629. for (loop = loadmap->nsegs; loop > 0; loop--, seg++) {
  630. if (params->hdr.e_entry >= seg->p_vaddr &&
  631. params->hdr.e_entry < seg->p_vaddr + seg->p_memsz) {
  632. params->entry_addr =
  633. (params->hdr.e_entry - seg->p_vaddr) +
  634. seg->addr;
  635. break;
  636. }
  637. }
  638. }
  639. /* determine where the program header table has wound up if mapped */
  640. stop = params->hdr.e_phoff;
  641. stop += params->hdr.e_phnum * sizeof (struct elf_phdr);
  642. phdr = params->phdrs;
  643. for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
  644. if (phdr->p_type != PT_LOAD)
  645. continue;
  646. if (phdr->p_offset > params->hdr.e_phoff ||
  647. phdr->p_offset + phdr->p_filesz < stop)
  648. continue;
  649. seg = loadmap->segs;
  650. for (loop = loadmap->nsegs; loop > 0; loop--, seg++) {
  651. if (phdr->p_vaddr >= seg->p_vaddr &&
  652. phdr->p_vaddr + phdr->p_filesz <=
  653. seg->p_vaddr + seg->p_memsz) {
  654. params->ph_addr =
  655. (phdr->p_vaddr - seg->p_vaddr) +
  656. seg->addr +
  657. params->hdr.e_phoff - phdr->p_offset;
  658. break;
  659. }
  660. }
  661. break;
  662. }
  663. /* determine where the dynamic section has wound up if there is one */
  664. phdr = params->phdrs;
  665. for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
  666. if (phdr->p_type != PT_DYNAMIC)
  667. continue;
  668. seg = loadmap->segs;
  669. for (loop = loadmap->nsegs; loop > 0; loop--, seg++) {
  670. if (phdr->p_vaddr >= seg->p_vaddr &&
  671. phdr->p_vaddr + phdr->p_memsz <=
  672. seg->p_vaddr + seg->p_memsz) {
  673. params->dynamic_addr =
  674. (phdr->p_vaddr - seg->p_vaddr) +
  675. seg->addr;
  676. /* check the dynamic section contains at least
  677. * one item, and that the last item is a NULL
  678. * entry */
  679. if (phdr->p_memsz == 0 ||
  680. phdr->p_memsz % sizeof(Elf32_Dyn) != 0)
  681. goto dynamic_error;
  682. tmp = phdr->p_memsz / sizeof(Elf32_Dyn);
  683. if (((Elf32_Dyn *)
  684. params->dynamic_addr)[tmp - 1].d_tag != 0)
  685. goto dynamic_error;
  686. break;
  687. }
  688. }
  689. break;
  690. }
  691. /* now elide adjacent segments in the load map on MMU linux
  692. * - on uClinux the holes between may actually be filled with system
  693. * stuff or stuff from other processes
  694. */
  695. #ifdef CONFIG_MMU
  696. nloads = loadmap->nsegs;
  697. mseg = loadmap->segs;
  698. seg = mseg + 1;
  699. for (loop = 1; loop < nloads; loop++) {
  700. /* see if we have a candidate for merging */
  701. if (seg->p_vaddr - mseg->p_vaddr == seg->addr - mseg->addr) {
  702. load_addr = PAGE_ALIGN(mseg->addr + mseg->p_memsz);
  703. if (load_addr == (seg->addr & PAGE_MASK)) {
  704. mseg->p_memsz +=
  705. load_addr -
  706. (mseg->addr + mseg->p_memsz);
  707. mseg->p_memsz += seg->addr & ~PAGE_MASK;
  708. mseg->p_memsz += seg->p_memsz;
  709. loadmap->nsegs--;
  710. continue;
  711. }
  712. }
  713. mseg++;
  714. if (mseg != seg)
  715. *mseg = *seg;
  716. }
  717. #endif
  718. kdebug("Mapped Object [%s]:", what);
  719. kdebug("- elfhdr : %lx", params->elfhdr_addr);
  720. kdebug("- entry : %lx", params->entry_addr);
  721. kdebug("- PHDR[] : %lx", params->ph_addr);
  722. kdebug("- DYNAMIC[]: %lx", params->dynamic_addr);
  723. seg = loadmap->segs;
  724. for (loop = 0; loop < loadmap->nsegs; loop++, seg++)
  725. kdebug("- LOAD[%d] : %08x-%08x [va=%x ms=%x]",
  726. loop,
  727. seg->addr, seg->addr + seg->p_memsz - 1,
  728. seg->p_vaddr, seg->p_memsz);
  729. return 0;
  730. dynamic_error:
  731. printk("ELF FDPIC %s with invalid DYNAMIC section (inode=%lu)\n",
  732. what, file->f_dentry->d_inode->i_ino);
  733. return -ELIBBAD;
  734. }
  735. /*****************************************************************************/
  736. /*
  737. * map a file with constant displacement under uClinux
  738. */
  739. #ifndef CONFIG_MMU
  740. static int elf_fdpic_map_file_constdisp_on_uclinux(
  741. struct elf_fdpic_params *params,
  742. struct file *file,
  743. struct mm_struct *mm)
  744. {
  745. struct elf32_fdpic_loadseg *seg;
  746. struct elf32_phdr *phdr;
  747. unsigned long load_addr, base = ULONG_MAX, top = 0, maddr = 0, mflags;
  748. loff_t fpos;
  749. int loop, ret;
  750. load_addr = params->load_addr;
  751. seg = params->loadmap->segs;
  752. /* determine the bounds of the contiguous overall allocation we must
  753. * make */
  754. phdr = params->phdrs;
  755. for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
  756. if (params->phdrs[loop].p_type != PT_LOAD)
  757. continue;
  758. if (base > phdr->p_vaddr)
  759. base = phdr->p_vaddr;
  760. if (top < phdr->p_vaddr + phdr->p_memsz)
  761. top = phdr->p_vaddr + phdr->p_memsz;
  762. }
  763. /* allocate one big anon block for everything */
  764. mflags = MAP_PRIVATE;
  765. if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE)
  766. mflags |= MAP_EXECUTABLE;
  767. down_write(&mm->mmap_sem);
  768. maddr = do_mmap(NULL, load_addr, top - base,
  769. PROT_READ | PROT_WRITE | PROT_EXEC, mflags, 0);
  770. up_write(&mm->mmap_sem);
  771. if (IS_ERR_VALUE(maddr))
  772. return (int) maddr;
  773. if (load_addr != 0)
  774. load_addr += PAGE_ALIGN(top - base);
  775. /* and then load the file segments into it */
  776. phdr = params->phdrs;
  777. for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
  778. if (params->phdrs[loop].p_type != PT_LOAD)
  779. continue;
  780. fpos = phdr->p_offset;
  781. seg->addr = maddr + (phdr->p_vaddr - base);
  782. seg->p_vaddr = phdr->p_vaddr;
  783. seg->p_memsz = phdr->p_memsz;
  784. ret = file->f_op->read(file, (void *) seg->addr,
  785. phdr->p_filesz, &fpos);
  786. if (ret < 0)
  787. return ret;
  788. /* map the ELF header address if in this segment */
  789. if (phdr->p_offset == 0)
  790. params->elfhdr_addr = seg->addr;
  791. /* clear any space allocated but not loaded */
  792. if (phdr->p_filesz < phdr->p_memsz)
  793. clear_user((void *) (seg->addr + phdr->p_filesz),
  794. phdr->p_memsz - phdr->p_filesz);
  795. if (mm) {
  796. if (phdr->p_flags & PF_X) {
  797. mm->start_code = seg->addr;
  798. mm->end_code = seg->addr + phdr->p_memsz;
  799. } else if (!mm->start_data) {
  800. mm->start_data = seg->addr;
  801. #ifndef CONFIG_MMU
  802. mm->end_data = seg->addr + phdr->p_memsz;
  803. #endif
  804. }
  805. #ifdef CONFIG_MMU
  806. if (seg->addr + phdr->p_memsz > mm->end_data)
  807. mm->end_data = seg->addr + phdr->p_memsz;
  808. #endif
  809. }
  810. seg++;
  811. }
  812. return 0;
  813. }
  814. #endif
  815. /*****************************************************************************/
  816. /*
  817. * map a binary by direct mmap() of the individual PT_LOAD segments
  818. */
  819. static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
  820. struct file *file,
  821. struct mm_struct *mm)
  822. {
  823. struct elf32_fdpic_loadseg *seg;
  824. struct elf32_phdr *phdr;
  825. unsigned long load_addr, delta_vaddr;
  826. int loop, dvset;
  827. load_addr = params->load_addr;
  828. delta_vaddr = 0;
  829. dvset = 0;
  830. seg = params->loadmap->segs;
  831. /* deal with each load segment separately */
  832. phdr = params->phdrs;
  833. for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
  834. unsigned long maddr, disp, excess, excess1;
  835. int prot = 0, flags;
  836. if (phdr->p_type != PT_LOAD)
  837. continue;
  838. kdebug("[LOAD] va=%lx of=%lx fs=%lx ms=%lx",
  839. (unsigned long) phdr->p_vaddr,
  840. (unsigned long) phdr->p_offset,
  841. (unsigned long) phdr->p_filesz,
  842. (unsigned long) phdr->p_memsz);
  843. /* determine the mapping parameters */
  844. if (phdr->p_flags & PF_R) prot |= PROT_READ;
  845. if (phdr->p_flags & PF_W) prot |= PROT_WRITE;
  846. if (phdr->p_flags & PF_X) prot |= PROT_EXEC;
  847. flags = MAP_PRIVATE | MAP_DENYWRITE;
  848. if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE)
  849. flags |= MAP_EXECUTABLE;
  850. maddr = 0;
  851. switch (params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) {
  852. case ELF_FDPIC_FLAG_INDEPENDENT:
  853. /* PT_LOADs are independently locatable */
  854. break;
  855. case ELF_FDPIC_FLAG_HONOURVADDR:
  856. /* the specified virtual address must be honoured */
  857. maddr = phdr->p_vaddr;
  858. flags |= MAP_FIXED;
  859. break;
  860. case ELF_FDPIC_FLAG_CONSTDISP:
  861. /* constant displacement
  862. * - can be mapped anywhere, but must be mapped as a
  863. * unit
  864. */
  865. if (!dvset) {
  866. maddr = load_addr;
  867. delta_vaddr = phdr->p_vaddr;
  868. dvset = 1;
  869. } else {
  870. maddr = load_addr + phdr->p_vaddr - delta_vaddr;
  871. flags |= MAP_FIXED;
  872. }
  873. break;
  874. case ELF_FDPIC_FLAG_CONTIGUOUS:
  875. /* contiguity handled later */
  876. break;
  877. default:
  878. BUG();
  879. }
  880. maddr &= PAGE_MASK;
  881. /* create the mapping */
  882. disp = phdr->p_vaddr & ~PAGE_MASK;
  883. down_write(&mm->mmap_sem);
  884. maddr = do_mmap(file, maddr, phdr->p_memsz + disp, prot, flags,
  885. phdr->p_offset - disp);
  886. up_write(&mm->mmap_sem);
  887. kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx",
  888. loop, phdr->p_memsz + disp, prot, flags,
  889. phdr->p_offset - disp, maddr);
  890. if (IS_ERR_VALUE(maddr))
  891. return (int) maddr;
  892. if ((params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) ==
  893. ELF_FDPIC_FLAG_CONTIGUOUS)
  894. load_addr += PAGE_ALIGN(phdr->p_memsz + disp);
  895. seg->addr = maddr + disp;
  896. seg->p_vaddr = phdr->p_vaddr;
  897. seg->p_memsz = phdr->p_memsz;
  898. /* map the ELF header address if in this segment */
  899. if (phdr->p_offset == 0)
  900. params->elfhdr_addr = seg->addr;
  901. /* clear the bit between beginning of mapping and beginning of
  902. * PT_LOAD */
  903. if (prot & PROT_WRITE && disp > 0) {
  904. kdebug("clear[%d] ad=%lx sz=%lx", loop, maddr, disp);
  905. clear_user((void __user *) maddr, disp);
  906. maddr += disp;
  907. }
  908. /* clear any space allocated but not loaded
  909. * - on uClinux we can just clear the lot
  910. * - on MMU linux we'll get a SIGBUS beyond the last page
  911. * extant in the file
  912. */
  913. excess = phdr->p_memsz - phdr->p_filesz;
  914. excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
  915. #ifdef CONFIG_MMU
  916. if (excess > excess1) {
  917. unsigned long xaddr = maddr + phdr->p_filesz + excess1;
  918. unsigned long xmaddr;
  919. flags |= MAP_FIXED | MAP_ANONYMOUS;
  920. down_write(&mm->mmap_sem);
  921. xmaddr = do_mmap(NULL, xaddr, excess - excess1,
  922. prot, flags, 0);
  923. up_write(&mm->mmap_sem);
  924. kdebug("mmap[%d] <anon>"
  925. " ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx",
  926. loop, xaddr, excess - excess1, prot, flags,
  927. xmaddr);
  928. if (xmaddr != xaddr)
  929. return -ENOMEM;
  930. }
  931. if (prot & PROT_WRITE && excess1 > 0) {
  932. kdebug("clear[%d] ad=%lx sz=%lx",
  933. loop, maddr + phdr->p_filesz, excess1);
  934. clear_user((void __user *) maddr + phdr->p_filesz,
  935. excess1);
  936. }
  937. #else
  938. if (excess > 0) {
  939. kdebug("clear[%d] ad=%lx sz=%lx",
  940. loop, maddr + phdr->p_filesz, excess);
  941. clear_user((void *) maddr + phdr->p_filesz, excess);
  942. }
  943. #endif
  944. if (mm) {
  945. if (phdr->p_flags & PF_X) {
  946. mm->start_code = maddr;
  947. mm->end_code = maddr + phdr->p_memsz;
  948. } else if (!mm->start_data) {
  949. mm->start_data = maddr;
  950. mm->end_data = maddr + phdr->p_memsz;
  951. }
  952. }
  953. seg++;
  954. }
  955. return 0;
  956. }
  957. /*****************************************************************************/
  958. /*
  959. * ELF-FDPIC core dumper
  960. *
  961. * Modelled on fs/exec.c:aout_core_dump()
  962. * Jeremy Fitzhardinge <jeremy@sw.oz.au>
  963. *
  964. * Modelled on fs/binfmt_elf.c core dumper
  965. */
  966. #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
  967. /*
  968. * These are the only things you should do on a core-file: use only these
  969. * functions to write out all the necessary info.
  970. */
  971. static int dump_write(struct file *file, const void *addr, int nr)
  972. {
  973. return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
  974. }
  975. static int dump_seek(struct file *file, loff_t off)
  976. {
  977. if (file->f_op->llseek) {
  978. if (file->f_op->llseek(file, off, SEEK_SET) != off)
  979. return 0;
  980. } else {
  981. file->f_pos = off;
  982. }
  983. return 1;
  984. }
  985. /*
  986. * Decide whether a segment is worth dumping; default is yes to be
  987. * sure (missing info is worse than too much; etc).
  988. * Personally I'd include everything, and use the coredump limit...
  989. *
  990. * I think we should skip something. But I am not sure how. H.J.
  991. */
  992. static int maydump(struct vm_area_struct *vma)
  993. {
  994. /* Do not dump I/O mapped devices or special mappings */
  995. if (vma->vm_flags & (VM_IO | VM_RESERVED)) {
  996. kdcore("%08lx: %08lx: no (IO)", vma->vm_start, vma->vm_flags);
  997. return 0;
  998. }
  999. /* If we may not read the contents, don't allow us to dump
  1000. * them either. "dump_write()" can't handle it anyway.
  1001. */
  1002. if (!(vma->vm_flags & VM_READ)) {
  1003. kdcore("%08lx: %08lx: no (!read)", vma->vm_start, vma->vm_flags);
  1004. return 0;
  1005. }
  1006. /* Dump shared memory only if mapped from an anonymous file. */
  1007. if (vma->vm_flags & VM_SHARED) {
  1008. if (vma->vm_file->f_dentry->d_inode->i_nlink == 0) {
  1009. kdcore("%08lx: %08lx: no (share)", vma->vm_start, vma->vm_flags);
  1010. return 1;
  1011. }
  1012. kdcore("%08lx: %08lx: no (share)", vma->vm_start, vma->vm_flags);
  1013. return 0;
  1014. }
  1015. #ifdef CONFIG_MMU
  1016. /* If it hasn't been written to, don't write it out */
  1017. if (!vma->anon_vma) {
  1018. kdcore("%08lx: %08lx: no (!anon)", vma->vm_start, vma->vm_flags);
  1019. return 0;
  1020. }
  1021. #endif
  1022. kdcore("%08lx: %08lx: yes", vma->vm_start, vma->vm_flags);
  1023. return 1;
  1024. }
  1025. /* An ELF note in memory */
  1026. struct memelfnote
  1027. {
  1028. const char *name;
  1029. int type;
  1030. unsigned int datasz;
  1031. void *data;
  1032. };
  1033. static int notesize(struct memelfnote *en)
  1034. {
  1035. int sz;
  1036. sz = sizeof(struct elf_note);
  1037. sz += roundup(strlen(en->name) + 1, 4);
  1038. sz += roundup(en->datasz, 4);
  1039. return sz;
  1040. }
  1041. /* #define DEBUG */
  1042. #define DUMP_WRITE(addr, nr) \
  1043. do { if (!dump_write(file, (addr), (nr))) return 0; } while(0)
  1044. #define DUMP_SEEK(off) \
  1045. do { if (!dump_seek(file, (off))) return 0; } while(0)
  1046. static int writenote(struct memelfnote *men, struct file *file)
  1047. {
  1048. struct elf_note en;
  1049. en.n_namesz = strlen(men->name) + 1;
  1050. en.n_descsz = men->datasz;
  1051. en.n_type = men->type;
  1052. DUMP_WRITE(&en, sizeof(en));
  1053. DUMP_WRITE(men->name, en.n_namesz);
  1054. /* XXX - cast from long long to long to avoid need for libgcc.a */
  1055. DUMP_SEEK(roundup((unsigned long)file->f_pos, 4)); /* XXX */
  1056. DUMP_WRITE(men->data, men->datasz);
  1057. DUMP_SEEK(roundup((unsigned long)file->f_pos, 4)); /* XXX */
  1058. return 1;
  1059. }
  1060. #undef DUMP_WRITE
  1061. #undef DUMP_SEEK
  1062. #define DUMP_WRITE(addr, nr) \
  1063. if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
  1064. goto end_coredump;
  1065. #define DUMP_SEEK(off) \
  1066. if (!dump_seek(file, (off))) \
  1067. goto end_coredump;
  1068. static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs)
  1069. {
  1070. memcpy(elf->e_ident, ELFMAG, SELFMAG);
  1071. elf->e_ident[EI_CLASS] = ELF_CLASS;
  1072. elf->e_ident[EI_DATA] = ELF_DATA;
  1073. elf->e_ident[EI_VERSION] = EV_CURRENT;
  1074. elf->e_ident[EI_OSABI] = ELF_OSABI;
  1075. memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
  1076. elf->e_type = ET_CORE;
  1077. elf->e_machine = ELF_ARCH;
  1078. elf->e_version = EV_CURRENT;
  1079. elf->e_entry = 0;
  1080. elf->e_phoff = sizeof(struct elfhdr);
  1081. elf->e_shoff = 0;
  1082. elf->e_flags = ELF_FDPIC_CORE_EFLAGS;
  1083. elf->e_ehsize = sizeof(struct elfhdr);
  1084. elf->e_phentsize = sizeof(struct elf_phdr);
  1085. elf->e_phnum = segs;
  1086. elf->e_shentsize = 0;
  1087. elf->e_shnum = 0;
  1088. elf->e_shstrndx = 0;
  1089. return;
  1090. }
  1091. static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset)
  1092. {
  1093. phdr->p_type = PT_NOTE;
  1094. phdr->p_offset = offset;
  1095. phdr->p_vaddr = 0;
  1096. phdr->p_paddr = 0;
  1097. phdr->p_filesz = sz;
  1098. phdr->p_memsz = 0;
  1099. phdr->p_flags = 0;
  1100. phdr->p_align = 0;
  1101. return;
  1102. }
  1103. static inline void fill_note(struct memelfnote *note, const char *name, int type,
  1104. unsigned int sz, void *data)
  1105. {
  1106. note->name = name;
  1107. note->type = type;
  1108. note->datasz = sz;
  1109. note->data = data;
  1110. return;
  1111. }
  1112. /*
  1113. * fill up all the fields in prstatus from the given task struct, except
  1114. * registers which need to be filled up seperately.
  1115. */
  1116. static void fill_prstatus(struct elf_prstatus *prstatus,
  1117. struct task_struct *p, long signr)
  1118. {
  1119. prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
  1120. prstatus->pr_sigpend = p->pending.signal.sig[0];
  1121. prstatus->pr_sighold = p->blocked.sig[0];
  1122. prstatus->pr_pid = p->pid;
  1123. prstatus->pr_ppid = p->parent->pid;
  1124. prstatus->pr_pgrp = process_group(p);
  1125. prstatus->pr_sid = p->signal->session;
  1126. if (thread_group_leader(p)) {
  1127. /*
  1128. * This is the record for the group leader. Add in the
  1129. * cumulative times of previous dead threads. This total
  1130. * won't include the time of each live thread whose state
  1131. * is included in the core dump. The final total reported
  1132. * to our parent process when it calls wait4 will include
  1133. * those sums as well as the little bit more time it takes
  1134. * this and each other thread to finish dying after the
  1135. * core dump synchronization phase.
  1136. */
  1137. cputime_to_timeval(cputime_add(p->utime, p->signal->utime),
  1138. &prstatus->pr_utime);
  1139. cputime_to_timeval(cputime_add(p->stime, p->signal->stime),
  1140. &prstatus->pr_stime);
  1141. } else {
  1142. cputime_to_timeval(p->utime, &prstatus->pr_utime);
  1143. cputime_to_timeval(p->stime, &prstatus->pr_stime);
  1144. }
  1145. cputime_to_timeval(p->signal->cutime, &prstatus->pr_cutime);
  1146. cputime_to_timeval(p->signal->cstime, &prstatus->pr_cstime);
  1147. prstatus->pr_exec_fdpic_loadmap = p->mm->context.exec_fdpic_loadmap;
  1148. prstatus->pr_interp_fdpic_loadmap = p->mm->context.interp_fdpic_loadmap;
  1149. }
  1150. static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
  1151. struct mm_struct *mm)
  1152. {
  1153. unsigned int i, len;
  1154. /* first copy the parameters from user space */
  1155. memset(psinfo, 0, sizeof(struct elf_prpsinfo));
  1156. len = mm->arg_end - mm->arg_start;
  1157. if (len >= ELF_PRARGSZ)
  1158. len = ELF_PRARGSZ - 1;
  1159. if (copy_from_user(&psinfo->pr_psargs,
  1160. (const char __user *) mm->arg_start, len))
  1161. return -EFAULT;
  1162. for (i = 0; i < len; i++)
  1163. if (psinfo->pr_psargs[i] == 0)
  1164. psinfo->pr_psargs[i] = ' ';
  1165. psinfo->pr_psargs[len] = 0;
  1166. psinfo->pr_pid = p->pid;
  1167. psinfo->pr_ppid = p->parent->pid;
  1168. psinfo->pr_pgrp = process_group(p);
  1169. psinfo->pr_sid = p->signal->session;
  1170. i = p->state ? ffz(~p->state) + 1 : 0;
  1171. psinfo->pr_state = i;
  1172. psinfo->pr_sname = (i > 5) ? '.' : "RSDTZW"[i];
  1173. psinfo->pr_zomb = psinfo->pr_sname == 'Z';
  1174. psinfo->pr_nice = task_nice(p);
  1175. psinfo->pr_flag = p->flags;
  1176. SET_UID(psinfo->pr_uid, p->uid);
  1177. SET_GID(psinfo->pr_gid, p->gid);
  1178. strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname));
  1179. return 0;
  1180. }
  1181. /* Here is the structure in which status of each thread is captured. */
  1182. struct elf_thread_status
  1183. {
  1184. struct list_head list;
  1185. struct elf_prstatus prstatus; /* NT_PRSTATUS */
  1186. elf_fpregset_t fpu; /* NT_PRFPREG */
  1187. struct task_struct *thread;
  1188. #ifdef ELF_CORE_COPY_XFPREGS
  1189. elf_fpxregset_t xfpu; /* NT_PRXFPREG */
  1190. #endif
  1191. struct memelfnote notes[3];
  1192. int num_notes;
  1193. };
  1194. /*
  1195. * In order to add the specific thread information for the elf file format,
  1196. * we need to keep a linked list of every thread's pr_status and then create
  1197. * a single section for them in the final core file.
  1198. */
  1199. static int elf_dump_thread_status(long signr, struct elf_thread_status *t)
  1200. {
  1201. struct task_struct *p = t->thread;
  1202. int sz = 0;
  1203. t->num_notes = 0;
  1204. fill_prstatus(&t->prstatus, p, signr);
  1205. elf_core_copy_task_regs(p, &t->prstatus.pr_reg);
  1206. fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus),
  1207. &t->prstatus);
  1208. t->num_notes++;
  1209. sz += notesize(&t->notes[0]);
  1210. t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, &t->fpu);
  1211. if (t->prstatus.pr_fpvalid) {
  1212. fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu),
  1213. &t->fpu);
  1214. t->num_notes++;
  1215. sz += notesize(&t->notes[1]);
  1216. }
  1217. #ifdef ELF_CORE_COPY_XFPREGS
  1218. if (elf_core_copy_task_xfpregs(p, &t->xfpu)) {
  1219. fill_note(&t->notes[2], "LINUX", NT_PRXFPREG, sizeof(t->xfpu),
  1220. &t->xfpu);
  1221. t->num_notes++;
  1222. sz += notesize(&t->notes[2]);
  1223. }
  1224. #endif
  1225. return sz;
  1226. }
  1227. /*
  1228. * dump the segments for an MMU process
  1229. */
  1230. #ifdef CONFIG_MMU
  1231. static int elf_fdpic_dump_segments(struct file *file, struct mm_struct *mm,
  1232. size_t *size, unsigned long *limit)
  1233. {
  1234. struct vm_area_struct *vma;
  1235. for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
  1236. unsigned long addr;
  1237. if (!maydump(vma))
  1238. continue;
  1239. for (addr = vma->vm_start;
  1240. addr < vma->vm_end;
  1241. addr += PAGE_SIZE
  1242. ) {
  1243. struct vm_area_struct *vma;
  1244. struct page *page;
  1245. if (get_user_pages(current, current->mm, addr, 1, 0, 1,
  1246. &page, &vma) <= 0) {
  1247. DUMP_SEEK(file->f_pos + PAGE_SIZE);
  1248. }
  1249. else if (page == ZERO_PAGE(addr)) {
  1250. DUMP_SEEK(file->f_pos + PAGE_SIZE);
  1251. page_cache_release(page);
  1252. }
  1253. else {
  1254. void *kaddr;
  1255. flush_cache_page(vma, addr, page_to_pfn(page));
  1256. kaddr = kmap(page);
  1257. if ((*size += PAGE_SIZE) > *limit ||
  1258. !dump_write(file, kaddr, PAGE_SIZE)
  1259. ) {
  1260. kunmap(page);
  1261. page_cache_release(page);
  1262. return -EIO;
  1263. }
  1264. kunmap(page);
  1265. page_cache_release(page);
  1266. }
  1267. }
  1268. }
  1269. return 0;
  1270. end_coredump:
  1271. return -EFBIG;
  1272. }
  1273. #endif
  1274. /*
  1275. * dump the segments for a NOMMU process
  1276. */
  1277. #ifndef CONFIG_MMU
  1278. static int elf_fdpic_dump_segments(struct file *file, struct mm_struct *mm,
  1279. size_t *size, unsigned long *limit)
  1280. {
  1281. struct vm_list_struct *vml;
  1282. for (vml = current->mm->context.vmlist; vml; vml = vml->next) {
  1283. struct vm_area_struct *vma = vml->vma;
  1284. if (!maydump(vma))
  1285. continue;
  1286. if ((*size += PAGE_SIZE) > *limit)
  1287. return -EFBIG;
  1288. if (!dump_write(file, (void *) vma->vm_start,
  1289. vma->vm_end - vma->vm_start))
  1290. return -EIO;
  1291. }
  1292. return 0;
  1293. }
  1294. #endif
  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_fdpic_core_dump(long signr, struct pt_regs *regs,
  1303. struct file *file)
  1304. {
  1305. #define NUM_NOTES 6
  1306. int has_dumped = 0;
  1307. mm_segment_t fs;
  1308. int segs;
  1309. size_t size = 0;
  1310. int i;
  1311. struct vm_area_struct *vma;
  1312. struct elfhdr *elf = NULL;
  1313. loff_t offset = 0, dataoff;
  1314. unsigned long limit = current->signal->rlim[RLIMIT_CORE].rlim_cur;
  1315. int numnote;
  1316. struct memelfnote *notes = NULL;
  1317. struct elf_prstatus *prstatus = NULL; /* NT_PRSTATUS */
  1318. struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
  1319. struct task_struct *g, *p;
  1320. LIST_HEAD(thread_list);
  1321. struct list_head *t;
  1322. elf_fpregset_t *fpu = NULL;
  1323. #ifdef ELF_CORE_COPY_XFPREGS
  1324. elf_fpxregset_t *xfpu = NULL;
  1325. #endif
  1326. int thread_status_size = 0;
  1327. #ifndef CONFIG_MMU
  1328. struct vm_list_struct *vml;
  1329. #endif
  1330. elf_addr_t *auxv;
  1331. /*
  1332. * We no longer stop all VM operations.
  1333. *
  1334. * This is because those proceses that could possibly change map_count
  1335. * or the mmap / vma pages are now blocked in do_exit on current
  1336. * finishing this core dump.
  1337. *
  1338. * Only ptrace can touch these memory addresses, but it doesn't change
  1339. * the map_count or the pages allocated. So no possibility of crashing
  1340. * exists while dumping the mm->vm_next areas to the core file.
  1341. */
  1342. /* alloc memory for large data structures: too large to be on stack */
  1343. elf = kmalloc(sizeof(*elf), GFP_KERNEL);
  1344. if (!elf)
  1345. goto cleanup;
  1346. prstatus = kzalloc(sizeof(*prstatus), GFP_KERNEL);
  1347. if (!prstatus)
  1348. goto cleanup;
  1349. psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
  1350. if (!psinfo)
  1351. goto cleanup;
  1352. notes = kmalloc(NUM_NOTES * sizeof(struct memelfnote), GFP_KERNEL);
  1353. if (!notes)
  1354. goto cleanup;
  1355. fpu = kmalloc(sizeof(*fpu), GFP_KERNEL);
  1356. if (!fpu)
  1357. goto cleanup;
  1358. #ifdef ELF_CORE_COPY_XFPREGS
  1359. xfpu = kmalloc(sizeof(*xfpu), GFP_KERNEL);
  1360. if (!xfpu)
  1361. goto cleanup;
  1362. #endif
  1363. if (signr) {
  1364. struct elf_thread_status *tmp;
  1365. read_lock(&tasklist_lock);
  1366. do_each_thread(g,p)
  1367. if (current->mm == p->mm && current != p) {
  1368. tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC);
  1369. if (!tmp) {
  1370. read_unlock(&tasklist_lock);
  1371. goto cleanup;
  1372. }
  1373. INIT_LIST_HEAD(&tmp->list);
  1374. tmp->thread = p;
  1375. list_add(&tmp->list, &thread_list);
  1376. }
  1377. while_each_thread(g,p);
  1378. read_unlock(&tasklist_lock);
  1379. list_for_each(t, &thread_list) {
  1380. struct elf_thread_status *tmp;
  1381. int sz;
  1382. tmp = list_entry(t, struct elf_thread_status, list);
  1383. sz = elf_dump_thread_status(signr, tmp);
  1384. thread_status_size += sz;
  1385. }
  1386. }
  1387. /* now collect the dump for the current */
  1388. fill_prstatus(prstatus, current, signr);
  1389. elf_core_copy_regs(&prstatus->pr_reg, regs);
  1390. #ifdef CONFIG_MMU
  1391. segs = current->mm->map_count;
  1392. #else
  1393. segs = 0;
  1394. for (vml = current->mm->context.vmlist; vml; vml = vml->next)
  1395. segs++;
  1396. #endif
  1397. #ifdef ELF_CORE_EXTRA_PHDRS
  1398. segs += ELF_CORE_EXTRA_PHDRS;
  1399. #endif
  1400. /* Set up header */
  1401. fill_elf_fdpic_header(elf, segs + 1); /* including notes section */
  1402. has_dumped = 1;
  1403. current->flags |= PF_DUMPCORE;
  1404. /*
  1405. * Set up the notes in similar form to SVR4 core dumps made
  1406. * with info from their /proc.
  1407. */
  1408. fill_note(notes + 0, "CORE", NT_PRSTATUS, sizeof(*prstatus), prstatus);
  1409. fill_psinfo(psinfo, current->group_leader, current->mm);
  1410. fill_note(notes + 1, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
  1411. numnote = 2;
  1412. auxv = (elf_addr_t *) current->mm->saved_auxv;
  1413. i = 0;
  1414. do
  1415. i += 2;
  1416. while (auxv[i - 2] != AT_NULL);
  1417. fill_note(&notes[numnote++], "CORE", NT_AUXV,
  1418. i * sizeof(elf_addr_t), auxv);
  1419. /* Try to dump the FPU. */
  1420. if ((prstatus->pr_fpvalid =
  1421. elf_core_copy_task_fpregs(current, regs, fpu)))
  1422. fill_note(notes + numnote++,
  1423. "CORE", NT_PRFPREG, sizeof(*fpu), fpu);
  1424. #ifdef ELF_CORE_COPY_XFPREGS
  1425. if (elf_core_copy_task_xfpregs(current, xfpu))
  1426. fill_note(notes + numnote++,
  1427. "LINUX", NT_PRXFPREG, sizeof(*xfpu), xfpu);
  1428. #endif
  1429. fs = get_fs();
  1430. set_fs(KERNEL_DS);
  1431. DUMP_WRITE(elf, sizeof(*elf));
  1432. offset += sizeof(*elf); /* Elf header */
  1433. offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */
  1434. /* Write notes phdr entry */
  1435. {
  1436. struct elf_phdr phdr;
  1437. int sz = 0;
  1438. for (i = 0; i < numnote; i++)
  1439. sz += notesize(notes + i);
  1440. sz += thread_status_size;
  1441. fill_elf_note_phdr(&phdr, sz, offset);
  1442. offset += sz;
  1443. DUMP_WRITE(&phdr, sizeof(phdr));
  1444. }
  1445. /* Page-align dumped data */
  1446. dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
  1447. /* write program headers for segments dump */
  1448. for (
  1449. #ifdef CONFIG_MMU
  1450. vma = current->mm->mmap; vma; vma = vma->vm_next
  1451. #else
  1452. vml = current->mm->context.vmlist; vml; vml = vml->next
  1453. #endif
  1454. ) {
  1455. struct elf_phdr phdr;
  1456. size_t sz;
  1457. #ifndef CONFIG_MMU
  1458. vma = vml->vma;
  1459. #endif
  1460. sz = vma->vm_end - vma->vm_start;
  1461. phdr.p_type = PT_LOAD;
  1462. phdr.p_offset = offset;
  1463. phdr.p_vaddr = vma->vm_start;
  1464. phdr.p_paddr = 0;
  1465. phdr.p_filesz = maydump(vma) ? sz : 0;
  1466. phdr.p_memsz = sz;
  1467. offset += phdr.p_filesz;
  1468. phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
  1469. if (vma->vm_flags & VM_WRITE)
  1470. phdr.p_flags |= PF_W;
  1471. if (vma->vm_flags & VM_EXEC)
  1472. phdr.p_flags |= PF_X;
  1473. phdr.p_align = ELF_EXEC_PAGESIZE;
  1474. DUMP_WRITE(&phdr, sizeof(phdr));
  1475. }
  1476. #ifdef ELF_CORE_WRITE_EXTRA_PHDRS
  1477. ELF_CORE_WRITE_EXTRA_PHDRS;
  1478. #endif
  1479. /* write out the notes section */
  1480. for (i = 0; i < numnote; i++)
  1481. if (!writenote(notes + i, file))
  1482. goto end_coredump;
  1483. /* write out the thread status notes section */
  1484. list_for_each(t, &thread_list) {
  1485. struct elf_thread_status *tmp =
  1486. list_entry(t, struct elf_thread_status, list);
  1487. for (i = 0; i < tmp->num_notes; i++)
  1488. if (!writenote(&tmp->notes[i], file))
  1489. goto end_coredump;
  1490. }
  1491. DUMP_SEEK(dataoff);
  1492. if (elf_fdpic_dump_segments(file, current->mm, &size, &limit) < 0)
  1493. goto end_coredump;
  1494. #ifdef ELF_CORE_WRITE_EXTRA_DATA
  1495. ELF_CORE_WRITE_EXTRA_DATA;
  1496. #endif
  1497. if (file->f_pos != offset) {
  1498. /* Sanity check */
  1499. printk(KERN_WARNING
  1500. "elf_core_dump: file->f_pos (%lld) != offset (%lld)\n",
  1501. file->f_pos, offset);
  1502. }
  1503. end_coredump:
  1504. set_fs(fs);
  1505. cleanup:
  1506. while (!list_empty(&thread_list)) {
  1507. struct list_head *tmp = thread_list.next;
  1508. list_del(tmp);
  1509. kfree(list_entry(tmp, struct elf_thread_status, list));
  1510. }
  1511. kfree(elf);
  1512. kfree(prstatus);
  1513. kfree(psinfo);
  1514. kfree(notes);
  1515. kfree(fpu);
  1516. #ifdef ELF_CORE_COPY_XFPREGS
  1517. kfree(xfpu);
  1518. #endif
  1519. return has_dumped;
  1520. #undef NUM_NOTES
  1521. }
  1522. #endif /* USE_ELF_CORE_DUMP */