From: Daisuke HATAYAMA <d.hatayama@jp.fujitsu.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, jdike@addtoit.com,
tony.luck@intel.com, mhiramat@redhat.com
Subject: [RFC, PATCH 3/4] elf_core_dump(): make offset calculation and writing processes explicit
Date: Tue, 15 Dec 2009 11:41:37 +0900 (JST) [thread overview]
Message-ID: <20091215.114137.104035145.d.hatayama@jp.fujitsu.com> (raw)
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 <d.hatayama@jp.fujitsu.com>
---
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
next reply other threads:[~2009-12-15 2:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-15 2:41 Daisuke HATAYAMA [this message]
2009-12-15 14:07 ` Andi Kleen
2009-12-16 2:27 ` Daisuke HATAYAMA
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091215.114137.104035145.d.hatayama@jp.fujitsu.com \
--to=d.hatayama@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=jdike@addtoit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@redhat.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®