gencore: Allocate ELF header to heap instead of stack

coredump() proceeds as follows:

1. coredump() calls gencore()
2. gencore() allocates ELF header to stack
3. gencore() prepares the core table and record the address of the ELF
   header to the table and return to coredump()
4. coredump() offloads __NR_coredump with the address of the core
   table

This fix prevents the ELF header from getting destroyed in the 3rd
step.

Change-Id: I770418c1658a6fdb640bb491fc076a31dfd41c22
Fujitsu: POSTK_TEMP_FIX_39
This commit is contained in:
Masamichi Takagi
2019-01-29 13:40:37 +09:00
committed by Dominique Martinet
parent 63d15f7dfc
commit 62772c8a24

View File

@ -228,11 +228,7 @@ int gencore(struct thread *thread, void *regs,
struct coretable **coretable, int *chunks)
{
struct coretable *ct = NULL;
#ifdef POSTK_DEBUG_TEMP_FIX_39
Elf64_Ehdr *eh = NULL;
#else
Elf64_Ehdr eh;
#endif /*POSTK_DEBUG_TEMP_FIX_39*/
Elf64_Phdr *ph = NULL;
void *note = NULL;
struct vm_range *range, *next;
@ -304,7 +300,6 @@ int gencore(struct thread *thread, void *regs,
dkprintf("now generate a core file image\n");
#ifdef POSTK_DEBUG_TEMP_FIX_39
eh = kmalloc(sizeof(*eh), IHK_MC_AP_NOWAIT);
if (eh == NULL) {
dkprintf("could not alloc a elf header table.\n");
@ -314,10 +309,6 @@ int gencore(struct thread *thread, void *regs,
offset += sizeof(*eh);
fill_elf_header(eh, segs);
#else
offset += sizeof(eh);
fill_elf_header(&eh, segs);
#endif /* POSTK_DEBUG_TEMP_FIX_39 */
/* program header table */
phsize = sizeof(Elf64_Phdr) * segs;
@ -391,15 +382,9 @@ int gencore(struct thread *thread, void *regs,
}
memset(ct, 0, sizeof(*ct));
#ifdef POSTK_DEBUG_TEMP_FIX_39
ct[0].addr = virt_to_phys(eh); /* ELF header */
ct[0].len = 64;
dkprintf("coretable[0]: %lx@%lx(%lx)\n", ct[0].len, ct[0].addr, eh);
#else
ct[0].addr = virt_to_phys(&eh); /* ELF header */
ct[0].len = 64;
dkprintf("coretable[0]: %lx@%lx(%lx)\n", ct[0].len, ct[0].addr, &eh);
#endif /* POSTK_DEBUG_TEMP_FIX_39 */
ct[1].addr = virt_to_phys(ph); /* program header table */
ct[1].len = phsize;
@ -511,8 +496,6 @@ void freecore(struct coretable **coretable)
kfree(phys_to_virt(ct[2].addr)); /* NOTE segment */
kfree(phys_to_virt(ct[1].addr)); /* ph */
#ifdef POSTK_DEBUG_TEMP_FIX_39
kfree(phys_to_virt(ct[0].addr)); /* eh */
#endif /*POSTK_DEBUG_TEMP_FIX_39*/
kfree(*coretable);
}