binfmt_elf_fdpic.c 46 KB

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