binfmt_elf_fdpic.c 47 KB

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