My next patch will change elf_core_dump() so that the produced
corefile may include section header table. But here is a problem.
If the corefile contains section header table, one needs to
write its file header to e_shoff field of the ELF header. It
is impossible to implement it while keeping the current
implementation.
Currently, writing operation for ELF header is done at very
early stage, where the file offset cannot be calculated. So,
one needs to choose which of the following ways:
1. Seeking back to retry writing operation for ELF header
after completing writing process for a whole part
2. Making offset calculation process and writing process
totally sequential
However, the clause 1. is not always possible, since one
cannot assume that dump_seek() function always supports
the seek in the minus direction. Consider no_llseek.
Therefore, this patch adopts the clause 2.
Signed-off-by: Daisuke HATAYAMA <[email protected]>
---
fs/binfmt_elf.c | 24 +++++++++++++++---------
1 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 9666a8a..cded1ba 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1935,6 +1935,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
loff_t offset = 0, dataoff, foffset;
unsigned long mm_flags;
struct elf_note_info info;
+ struct elf_phdr *phdr4note = NULL;
/*
* We no longer stop all VM operations.
@@ -1977,30 +1978,34 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
fs = get_fs();
set_fs(KERNEL_DS);
- size += sizeof(*elf);
- if (size > limit || !dump_write(file, elf, sizeof(*elf)))
- goto end_coredump;
-
offset += sizeof(*elf); /* Elf header */
offset += (segs + 1) * sizeof(struct elf_phdr); /* Program headers */
foffset = offset;
/* Write notes phdr entry */
{
- struct elf_phdr phdr;
size_t sz = get_note_info_size(&info);
sz += elf_coredump_extra_notes_size();
- fill_elf_note_phdr(&phdr, sz, offset);
- offset += sz;
- size += sizeof(phdr);
- if (size > limit || !dump_write(file, &phdr, sizeof(phdr)))
+ phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
+ if (!phdr4note)
goto end_coredump;
+
+ fill_elf_note_phdr(phdr4note, sz, offset);
+ offset += sz;
}
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
+ size += sizeof(*elf);
+ if (size > limit || !dump_write(file, elf, sizeof(*elf)))
+ goto end_coredump;
+
+ size += sizeof(*phdr4note);
+ if (size > limit || !dump_write(file, phdr4note, sizeof(*phdr4note)))
+ goto end_coredump;
+
/*
* We must use the same mm->flags while dumping core to avoid
* inconsistency between the program headers and bodies, otherwise an
@@ -2079,6 +2084,7 @@ end_coredump:
cleanup:
free_note_info(&info);
+ kfree(phdr4note);
kfree(elf);
out:
return has_dumped;
--
1.6.5.1
Daisuke HATAYAMA <[email protected]> writes:
>
> However, the clause 1. is not always possible, since one
> cannot assume that dump_seek() function always supports
> the seek in the minus direction. Consider no_llseek.
Not even forward seek is always supported, consider core dumping
to a pipe.
-Andi
--
[email protected] -- Speaking for myself only.
> Daisuke HATAYAMA <[email protected]> writes:
> >
> > However, the clause 1. is not always possible, since one
> > cannot assume that dump_seek() function always supports
> > the seek in the minus direction. Consider no_llseek.
>
> Not even forward seek is always supported, consider core dumping
> to a pipe.
>
> -Andi
I may need to use backward seeking here, not forward. So, I stressed
here for the backward one.
Thanks.