All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC, PATCH 3/4] elf_core_dump(): make offset calculation and writing processes explicit
@ 2009-12-15  2:41 Daisuke HATAYAMA
  2009-12-15 14:07 ` Andi Kleen
  0 siblings, 1 reply; 3+ messages in thread
From: Daisuke HATAYAMA @ 2009-12-15  2:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, jdike, tony.luck, mhiramat

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC, PATCH 3/4] elf_core_dump(): make offset calculation and writing processes explicit
  2009-12-15  2:41 [RFC, PATCH 3/4] elf_core_dump(): make offset calculation and writing processes explicit Daisuke HATAYAMA
@ 2009-12-15 14:07 ` Andi Kleen
  2009-12-16  2:27   ` Daisuke HATAYAMA
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2009-12-15 14:07 UTC (permalink / raw)
  To: Daisuke HATAYAMA; +Cc: linux-kernel, akpm, jdike, tony.luck, mhiramat

Daisuke HATAYAMA <d.hatayama@jp.fujitsu.com> 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

-- 
ak@linux.intel.com -- Speaking for myself only.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC, PATCH 3/4] elf_core_dump(): make offset calculation and writing processes explicit
  2009-12-15 14:07 ` Andi Kleen
@ 2009-12-16  2:27   ` Daisuke HATAYAMA
  0 siblings, 0 replies; 3+ messages in thread
From: Daisuke HATAYAMA @ 2009-12-16  2:27 UTC (permalink / raw)
  To: andi; +Cc: linux-kernel, akpm, jdike, tony.luck, mhiramat

> Daisuke HATAYAMA <d.hatayama@jp.fujitsu.com> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-16  2:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-15  2:41 [RFC, PATCH 3/4] elf_core_dump(): make offset calculation and writing processes explicit Daisuke HATAYAMA
2009-12-15 14:07 ` Andi Kleen
2009-12-16  2:27   ` Daisuke HATAYAMA

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.