aboutsummaryrefslogtreecommitdiffstats
path: root/fs/binfmt_elf_fdpic.c
diff options
context:
space:
mode:
authorDaisuke HATAYAMA <d.hatayama@jp.fujitsu.com>2010-03-05 16:44:09 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 14:26:46 -0500
commit93eb211e6c9ff6054fcf9c5b9e344d8d9ad29175 (patch)
tree424990890a34e626df8e2c68f4952d4d4734b63b /fs/binfmt_elf_fdpic.c
parent1fcccbac89f5bbc5e41aa72086960059fce372da (diff)
elf coredump: make offset calculation process and writing process explicit
By the next patch, elf_core_dump() and elf_fdpic_core_dump() will support extended numbering and so will produce the corefiles with section header table in a special case. The problem is the process of writing a file header offset of the section header table into e_shoff field of the ELF header. ELF header is positioned at the beginning of the corefile, while section header at the end. So, we need to take which of the following ways: 1. Seek backward to retry writing operation for ELF header after writing process for a whole part 2. Make offset calculation process and writing process totally sequential The clause 1. is not always possible: one cannot assume that file system supports seek function. Consider the no_llseek case. Therefore, this patch adopts the clause 2. Signed-off-by: Daisuke HATAYAMA <d.hatayama@jp.fujitsu.com> Cc: "Luck, Tony" <tony.luck@intel.com> Cc: Jeff Dike <jdike@addtoit.com> Cc: David Howells <dhowells@redhat.com> Cc: Greg Ungerer <gerg@snapgear.com> Cc: Roland McGrath <roland@redhat.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andi Kleen <andi@firstfloor.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/binfmt_elf_fdpic.c')
-rw-r--r--fs/binfmt_elf_fdpic.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 952699a86ec3..112da491d75d 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1600,6 +1600,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1600 int thread_status_size = 0; 1600 int thread_status_size = 0;
1601 elf_addr_t *auxv; 1601 elf_addr_t *auxv;
1602 unsigned long mm_flags; 1602 unsigned long mm_flags;
1603 struct elf_phdr *phdr4note = NULL;
1603 1604
1604 /* 1605 /*
1605 * We no longer stop all VM operations. 1606 * We no longer stop all VM operations.
@@ -1706,18 +1707,12 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1706 fs = get_fs(); 1707 fs = get_fs();
1707 set_fs(KERNEL_DS); 1708 set_fs(KERNEL_DS);
1708 1709
1709 size += sizeof(*elf);
1710 if (size > cprm->limit
1711 || !dump_write(cprm->file, elf, sizeof(*elf)))
1712 goto end_coredump;
1713
1714 offset += sizeof(*elf); /* Elf header */ 1710 offset += sizeof(*elf); /* Elf header */
1715 offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */ 1711 offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */
1716 foffset = offset; 1712 foffset = offset;
1717 1713
1718 /* Write notes phdr entry */ 1714 /* Write notes phdr entry */
1719 { 1715 {
1720 struct elf_phdr phdr;
1721 int sz = 0; 1716 int sz = 0;
1722 1717
1723 for (i = 0; i < numnote; i++) 1718 for (i = 0; i < numnote; i++)
@@ -1725,13 +1720,12 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1725 1720
1726 sz += thread_status_size; 1721 sz += thread_status_size;
1727 1722
1728 fill_elf_note_phdr(&phdr, sz, offset); 1723 phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
1729 offset += sz; 1724 if (!phdr4note)
1730
1731 size += sizeof(phdr);
1732 if (size > cprm->limit
1733 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
1734 goto end_coredump; 1725 goto end_coredump;
1726
1727 fill_elf_note_phdr(phdr4note, sz, offset);
1728 offset += sz;
1735 } 1729 }
1736 1730
1737 /* Page-align dumped data */ 1731 /* Page-align dumped data */
@@ -1744,6 +1738,15 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1744 */ 1738 */
1745 mm_flags = current->mm->flags; 1739 mm_flags = current->mm->flags;
1746 1740
1741 size += sizeof(*elf);
1742 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
1743 goto end_coredump;
1744
1745 size += sizeof(*phdr4note);
1746 if (size > cprm->limit
1747 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
1748 goto end_coredump;
1749
1747 /* write program headers for segments dump */ 1750 /* write program headers for segments dump */
1748 for (vma = current->mm->mmap; vma; vma = vma->vm_next) { 1751 for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
1749 struct elf_phdr phdr; 1752 struct elf_phdr phdr;
@@ -1815,7 +1818,7 @@ cleanup:
1815 list_del(tmp); 1818 list_del(tmp);
1816 kfree(list_entry(tmp, struct elf_thread_status, list)); 1819 kfree(list_entry(tmp, struct elf_thread_status, list));
1817 } 1820 }
1818 1821 kfree(phdr4note);
1819 kfree(elf); 1822 kfree(elf);
1820 kfree(prstatus); 1823 kfree(prstatus);
1821 kfree(psinfo); 1824 kfree(psinfo);