Skip to content

Commit d2f5816

Browse files
author
Al Viro
committed
[elf-fdpic] use elf_dump_thread_status() for the dumper thread as well
the only reason to have it open-coded for the first (dumper) thread is that coredump has a couple of process-wide notes stuck right after the first (NT_PRSTATUS) note of the first thread. But we don't need to make the data collection side irregular for the first thread to handle that - it's only the logics ordering the calls of writenote() that needs to take care of that. Signed-off-by: Al Viro <[email protected]>
1 parent 38a6277 commit d2f5816

File tree

1 file changed

+28
-53
lines changed

1 file changed

+28
-53
lines changed

fs/binfmt_elf_fdpic.c

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,8 @@ static struct elf_thread_status *elf_dump_thread_status(long signr, struct task_
14821482
t->num_notes++;
14831483
*sz += notesize(&t->notes[0]);
14841484

1485-
t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, &t->fpu);
1485+
t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, task_pt_regs(p),
1486+
&t->fpu);
14861487
if (t->prstatus.pr_fpvalid) {
14871488
fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu),
14881489
&t->fpu);
@@ -1568,19 +1569,15 @@ static size_t elf_core_vma_data_size(unsigned long mm_flags)
15681569
*/
15691570
static int elf_fdpic_core_dump(struct coredump_params *cprm)
15701571
{
1571-
#define NUM_NOTES 6
15721572
int has_dumped = 0;
15731573
int segs;
15741574
int i;
15751575
struct vm_area_struct *vma;
15761576
struct elfhdr *elf = NULL;
15771577
loff_t offset = 0, dataoff;
1578-
int numnote;
1579-
struct memelfnote *notes = NULL;
1580-
struct elf_prstatus_fdpic *prstatus = NULL; /* NT_PRSTATUS */
1578+
struct memelfnote psinfo_note, auxv_note;
15811579
struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
15821580
struct elf_thread_status *thread_list = NULL;
1583-
elf_fpregset_t *fpu = NULL;
15841581
int thread_status_size = 0;
15851582
elf_addr_t *auxv;
15861583
struct elf_phdr *phdr4note = NULL;
@@ -1606,19 +1603,9 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
16061603
elf = kmalloc(sizeof(*elf), GFP_KERNEL);
16071604
if (!elf)
16081605
goto end_coredump;
1609-
prstatus = kzalloc(sizeof(*prstatus), GFP_KERNEL);
1610-
if (!prstatus)
1611-
goto end_coredump;
16121606
psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
16131607
if (!psinfo)
16141608
goto end_coredump;
1615-
notes = kmalloc_array(NUM_NOTES, sizeof(struct memelfnote),
1616-
GFP_KERNEL);
1617-
if (!notes)
1618-
goto end_coredump;
1619-
fpu = kmalloc(sizeof(*fpu), GFP_KERNEL);
1620-
if (!fpu)
1621-
goto end_coredump;
16221609

16231610
for (ct = current->mm->core_state->dumper.next;
16241611
ct; ct = ct->next) {
@@ -1632,8 +1619,12 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
16321619
}
16331620

16341621
/* now collect the dump for the current */
1635-
fill_prstatus(prstatus, current, cprm->siginfo->si_signo);
1636-
elf_core_copy_regs(&prstatus->pr_reg, cprm->regs);
1622+
tmp = elf_dump_thread_status(cprm->siginfo->si_signo,
1623+
current, &thread_status_size);
1624+
if (!tmp)
1625+
goto end_coredump;
1626+
tmp->next = thread_list;
1627+
thread_list = tmp;
16371628

16381629
segs = current->mm->map_count;
16391630
segs += elf_core_extra_phdrs();
@@ -1655,46 +1646,28 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
16551646
* with info from their /proc.
16561647
*/
16571648

1658-
fill_note(notes + 0, "CORE", NT_PRSTATUS, sizeof(*prstatus), prstatus);
16591649
fill_psinfo(psinfo, current->group_leader, current->mm);
1660-
fill_note(notes + 1, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
1661-
1662-
numnote = 2;
1650+
fill_note(&psinfo_note, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
1651+
thread_status_size += notesize(&psinfo_note);
16631652

16641653
auxv = (elf_addr_t *) current->mm->saved_auxv;
1665-
16661654
i = 0;
16671655
do
16681656
i += 2;
16691657
while (auxv[i - 2] != AT_NULL);
1670-
fill_note(&notes[numnote++], "CORE", NT_AUXV,
1671-
i * sizeof(elf_addr_t), auxv);
1658+
fill_note(&auxv_note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
1659+
thread_status_size += notesize(&auxv_note);
16721660

1673-
/* Try to dump the FPU. */
1674-
if ((prstatus->pr_fpvalid =
1675-
elf_core_copy_task_fpregs(current, cprm->regs, fpu)))
1676-
fill_note(notes + numnote++,
1677-
"CORE", NT_PRFPREG, sizeof(*fpu), fpu);
1678-
1679-
offset += sizeof(*elf); /* Elf header */
1661+
offset = sizeof(*elf); /* Elf header */
16801662
offset += segs * sizeof(struct elf_phdr); /* Program headers */
16811663

16821664
/* Write notes phdr entry */
1683-
{
1684-
int sz = 0;
1685-
1686-
for (i = 0; i < numnote; i++)
1687-
sz += notesize(notes + i);
1688-
1689-
sz += thread_status_size;
1690-
1691-
phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
1692-
if (!phdr4note)
1693-
goto end_coredump;
1665+
phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
1666+
if (!phdr4note)
1667+
goto end_coredump;
16941668

1695-
fill_elf_note_phdr(phdr4note, sz, offset);
1696-
offset += sz;
1697-
}
1669+
fill_elf_note_phdr(phdr4note, thread_status_size, offset);
1670+
offset += thread_status_size;
16981671

16991672
/* Page-align dumped data */
17001673
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
@@ -1747,12 +1720,18 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
17471720
goto end_coredump;
17481721

17491722
/* write out the notes section */
1750-
for (i = 0; i < numnote; i++)
1751-
if (!writenote(notes + i, cprm))
1723+
if (!writenote(thread_list->notes, cprm))
1724+
goto end_coredump;
1725+
if (!writenote(&psinfo_note, cprm))
1726+
goto end_coredump;
1727+
if (!writenote(&auxv_note, cprm))
1728+
goto end_coredump;
1729+
for (i = 1; i < thread_list->num_notes; i++)
1730+
if (!writenote(thread_list->notes + i, cprm))
17521731
goto end_coredump;
17531732

17541733
/* write out the thread status notes section */
1755-
for (tmp = thread_list; tmp; tmp = tmp->next) {
1734+
for (tmp = thread_list->next; tmp; tmp = tmp->next) {
17561735
for (i = 0; i < tmp->num_notes; i++)
17571736
if (!writenote(&tmp->notes[i], cprm))
17581737
goto end_coredump;
@@ -1787,13 +1766,9 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
17871766
}
17881767
kfree(phdr4note);
17891768
kfree(elf);
1790-
kfree(prstatus);
17911769
kfree(psinfo);
1792-
kfree(notes);
1793-
kfree(fpu);
17941770
kfree(shdr4extnum);
17951771
return has_dumped;
1796-
#undef NUM_NOTES
17971772
}
17981773

17991774
#endif /* CONFIG_ELF_CORE */

0 commit comments

Comments
 (0)