aboutsummaryrefslogtreecommitdiffstats
path: root/fs/binfmt_elf.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.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.c')
-rw-r--r--fs/binfmt_elf.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index c1a499599b7d..6fc49b6ed936 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1856,6 +1856,7 @@ static int elf_core_dump(struct coredump_params *cprm)
1856 loff_t offset = 0, dataoff, foffset; 1856 loff_t offset = 0, dataoff, foffset;
1857 unsigned long mm_flags; 1857 unsigned long mm_flags;
1858 struct elf_note_info info; 1858 struct elf_note_info info;
1859 struct elf_phdr *phdr4note = NULL;
1859 1860
1860 /* 1861 /*
1861 * We no longer stop all VM operations. 1862 * We no longer stop all VM operations.
@@ -1898,28 +1899,22 @@ static int elf_core_dump(struct coredump_params *cprm)
1898 fs = get_fs(); 1899 fs = get_fs();
1899 set_fs(KERNEL_DS); 1900 set_fs(KERNEL_DS);
1900 1901
1901 size += sizeof(*elf);
1902 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
1903 goto end_coredump;
1904
1905 offset += sizeof(*elf); /* Elf header */ 1902 offset += sizeof(*elf); /* Elf header */
1906 offset += (segs + 1) * sizeof(struct elf_phdr); /* Program headers */ 1903 offset += (segs + 1) * sizeof(struct elf_phdr); /* Program headers */
1907 foffset = offset; 1904 foffset = offset;
1908 1905
1909 /* Write notes phdr entry */ 1906 /* Write notes phdr entry */
1910 { 1907 {
1911 struct elf_phdr phdr;
1912 size_t sz = get_note_info_size(&info); 1908 size_t sz = get_note_info_size(&info);
1913 1909
1914 sz += elf_coredump_extra_notes_size(); 1910 sz += elf_coredump_extra_notes_size();
1915 1911
1916 fill_elf_note_phdr(&phdr, sz, offset); 1912 phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
1917 offset += sz; 1913 if (!phdr4note)
1918
1919 size += sizeof(phdr);
1920 if (size > cprm->limit
1921 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
1922 goto end_coredump; 1914 goto end_coredump;
1915
1916 fill_elf_note_phdr(phdr4note, sz, offset);
1917 offset += sz;
1923 } 1918 }
1924 1919
1925 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); 1920 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
@@ -1931,6 +1926,15 @@ static int elf_core_dump(struct coredump_params *cprm)
1931 */ 1926 */
1932 mm_flags = current->mm->flags; 1927 mm_flags = current->mm->flags;
1933 1928
1929 size += sizeof(*elf);
1930 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
1931 goto end_coredump;
1932
1933 size += sizeof(*phdr4note);
1934 if (size > cprm->limit
1935 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
1936 goto end_coredump;
1937
1934 /* Write program headers for segments dump */ 1938 /* Write program headers for segments dump */
1935 for (vma = first_vma(current, gate_vma); vma != NULL; 1939 for (vma = first_vma(current, gate_vma); vma != NULL;
1936 vma = next_vma(vma, gate_vma)) { 1940 vma = next_vma(vma, gate_vma)) {
@@ -2004,6 +2008,7 @@ end_coredump:
2004 2008
2005cleanup: 2009cleanup:
2006 free_note_info(&info); 2010 free_note_info(&info);
2011 kfree(phdr4note);
2007 kfree(elf); 2012 kfree(elf);
2008out: 2013out:
2009 return has_dumped; 2014 return has_dumped;