From: HATAYAMA Daisuke <d.hatayama@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: tony.luck@intel.com, jdike@addtoit.com, dhowells@redhat.com,
gerg@snapgear.com, roland@redhat.com, oleg@redhat.com,
mingo@elte.hu, viro@zeniv.linux.org.uk, andi@firstfloor.org,
alan@lxorguk.ukuu.org.uk, akpm@linux-foundation.org,
kosaki.motohiro@jp.fujitsu.com, kamezawa.hiroyu@jp.fujitsu.com,
suzuki@in.ibm.com, linux-arch@vger.kernel.org
Subject: [PATCH 1/4] elf core: Write section header table first
Date: Thu, 30 Dec 2010 06:19:51 +0900 [thread overview]
Message-ID: <AANLkTimKUAH3VA6-=moR5nTrmn-yi4D_yoLQtU1ygYAh@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimK9gh_LVW2faCbVMpwMeBFOJLRXHJkA4_3Oi6=@mail.gmail.com>
Change a position of section header table from the last to the next to
ELF header. Because section header table offset is located at next to
ELF header and ELF header size is constant, section header table
offset is also constant if exists; so is program header table
offset. We no longer need to calculate vma data size in advance.
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
---
fs/binfmt_elf.c | 42 ++++++++++++++++++++++--------------------
fs/binfmt_elf_fdpic.c | 43 +++++++++++++++++++++++--------------------
2 files changed, 45 insertions(+), 40 deletions(-)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 6884e19..5ab062c 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1234,11 +1234,17 @@ static void fill_elf_header(struct elfhdr
*elf, int segs,
elf->e_type = ET_CORE;
elf->e_machine = machine;
elf->e_version = EV_CURRENT;
- elf->e_phoff = sizeof(struct elfhdr);
elf->e_flags = flags;
elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize = sizeof(struct elf_phdr);
- elf->e_phnum = segs;
+
+ if (segs < PN_XNUM) {
+ elf->e_phoff = sizeof(struct elfhdr);
+ elf->e_phnum = segs;
+ } else {
+ elf->e_phoff = sizeof(struct elfhdr) + sizeof(struct elf_shdr);
+ elf->e_phnum = PN_XNUM;
+ }
return;
}
@@ -1839,12 +1845,13 @@ static struct vm_area_struct *next_vma(struct
vm_area_struct *this_vma,
}
static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
- elf_addr_t e_shoff, int segs)
+ int segs)
{
- elf->e_shoff = e_shoff;
+ elf->e_shoff = sizeof(*elf);
elf->e_shentsize = sizeof(*shdr4extnum);
elf->e_shnum = 1;
elf->e_shstrndx = SHN_UNDEF;
+ elf->e_phoff = elf->e_shoff + elf->e_shnum * elf->e_shentsize;
memset(shdr4extnum, 0, sizeof(*shdr4extnum));
@@ -1886,7 +1893,6 @@ static int elf_core_dump(struct coredump_params *cprm)
struct elf_phdr *phdr4note = NULL;
struct elf_shdr *shdr4extnum = NULL;
Elf_Half e_phnum;
- elf_addr_t e_shoff;
/*
* We no longer stop all VM operations.
@@ -1937,6 +1943,8 @@ static int elf_core_dump(struct coredump_params *cprm)
set_fs(KERNEL_DS);
offset += sizeof(*elf); /* Elf header */
+ if (e_phnum == PN_XNUM) /* Section header */
+ offset += sizeof(struct elf_shdr);
offset += segs * sizeof(struct elf_phdr); /* Program headers */
foffset = offset;
@@ -1956,23 +1964,25 @@ static int elf_core_dump(struct coredump_params *cprm)
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
- offset += elf_core_extra_data_size();
- e_shoff = offset;
-
if (e_phnum == PN_XNUM) {
shdr4extnum = kmalloc(sizeof(*shdr4extnum), GFP_KERNEL);
if (!shdr4extnum)
goto end_coredump;
- fill_extnum_info(elf, shdr4extnum, e_shoff, segs);
+ fill_extnum_info(elf, shdr4extnum, segs);
}
- offset = dataoff;
-
size += sizeof(*elf);
if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
goto end_coredump;
+ if (e_phnum == PN_XNUM) {
+ size += sizeof(*shdr4extnum);
+ if (size > cprm->limit
+ || !dump_write(cprm->file, shdr4extnum,
+ sizeof(*shdr4extnum)))
+ goto end_coredump;
+ }
+
size += sizeof(*phdr4note);
if (size > cprm->limit
|| !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
@@ -2046,14 +2056,6 @@ static int elf_core_dump(struct coredump_params *cprm)
if (!elf_core_write_extra_data(cprm->file, &size, cprm->limit))
goto end_coredump;
- if (e_phnum == PN_XNUM) {
- size += sizeof(*shdr4extnum);
- if (size > cprm->limit
- || !dump_write(cprm->file, shdr4extnum,
- sizeof(*shdr4extnum)))
- goto end_coredump;
- }
-
end_coredump:
set_fs(fs);
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 63039ed..9ff6bef 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1326,15 +1326,22 @@ static inline void
fill_elf_fdpic_header(struct elfhdr *elf, int segs)
elf->e_machine = ELF_ARCH;
elf->e_version = EV_CURRENT;
elf->e_entry = 0;
- elf->e_phoff = sizeof(struct elfhdr);
elf->e_shoff = 0;
elf->e_flags = ELF_FDPIC_CORE_EFLAGS;
elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize = sizeof(struct elf_phdr);
- elf->e_phnum = segs;
elf->e_shentsize = 0;
elf->e_shnum = 0;
elf->e_shstrndx = 0;
+
+ if (segs < PN_XNUM) {
+ elf->e_phoff = sizeof(struct elfhdr);
+ elf->e_phnum = segs;
+ } else {
+ elf->e_phoff = sizeof(struct elfhdr) + sizeof(struct elf_shdr);
+ elf->e_phnum = PN_XNUM;
+ }
+
return;
}
@@ -1495,12 +1502,13 @@ static int elf_dump_thread_status(long signr,
struct elf_thread_status *t)
}
static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
- elf_addr_t e_shoff, int segs)
+ int segs)
{
- elf->e_shoff = e_shoff;
+ elf->e_shoff = sizeof(*elf);
elf->e_shentsize = sizeof(*shdr4extnum);
elf->e_shnum = 1;
elf->e_shstrndx = SHN_UNDEF;
+ elf->e_phoff = elf->e_shoff + elf->e_shnum * elf->e_shentsize;
memset(shdr4extnum, 0, sizeof(*shdr4extnum));
@@ -1618,7 +1626,6 @@ static int elf_fdpic_core_dump(struct
coredump_params *cprm)
struct elf_phdr *phdr4note = NULL;
struct elf_shdr *shdr4extnum = NULL;
Elf_Half e_phnum;
- elf_addr_t e_shoff;
/*
* We no longer stop all VM operations.
@@ -1734,6 +1741,8 @@ static int elf_fdpic_core_dump(struct
coredump_params *cprm)
set_fs(KERNEL_DS);
offset += sizeof(*elf); /* Elf header */
+ if (e_phnum == PN_XNUM) /* Section header */
+ offset += sizeof(struct elf_shdr);
offset += segs * sizeof(struct elf_phdr); /* Program headers */
foffset = offset;
@@ -1757,23 +1766,25 @@ static int elf_fdpic_core_dump(struct
coredump_params *cprm)
/* Page-align dumped data */
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
- offset += elf_core_vma_data_size(cprm->mm_flags);
- offset += elf_core_extra_data_size();
- e_shoff = offset;
-
if (e_phnum == PN_XNUM) {
shdr4extnum = kmalloc(sizeof(*shdr4extnum), GFP_KERNEL);
if (!shdr4extnum)
goto end_coredump;
- fill_extnum_info(elf, shdr4extnum, e_shoff, segs);
+ fill_extnum_info(elf, shdr4extnum, segs);
}
- offset = dataoff;
-
size += sizeof(*elf);
if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
goto end_coredump;
+ if (e_phnum == PN_XNUM) {
+ size += sizeof(*shdr4extnum);
+ if (size > cprm->limit
+ || !dump_write(cprm->file, shdr4extnum,
+ sizeof(*shdr4extnum)))
+ goto end_coredump;
+ }
+
size += sizeof(*phdr4note);
if (size > cprm->limit
|| !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
@@ -1834,14 +1845,6 @@ static int elf_fdpic_core_dump(struct
coredump_params *cprm)
if (!elf_core_write_extra_data(cprm->file, &size, cprm->limit))
goto end_coredump;
- if (e_phnum == PN_XNUM) {
- size += sizeof(*shdr4extnum);
- if (size > cprm->limit
- || !dump_write(cprm->file, shdr4extnum,
- sizeof(*shdr4extnum)))
- goto end_coredump;
- }
-
if (cprm->file->f_pos != offset) {
/* Sanity check */
printk(KERN_WARNING
--
1.7.1
next prev parent reply other threads:[~2010-12-29 21:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-29 21:16 [PATCH 0/4] elf core: Write section header table first HATAYAMA Daisuke
2010-12-29 21:19 ` HATAYAMA Daisuke [this message]
2011-01-04 1:02 ` KAMEZAWA Hiroyuki
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='AANLkTimKUAH3VA6-=moR5nTrmn-yi4D_yoLQtU1ygYAh@mail.gmail.com' \
--to=d.hatayama@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=andi@firstfloor.org \
--cc=dhowells@redhat.com \
--cc=gerg@snapgear.com \
--cc=jdike@addtoit.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=roland@redhat.com \
--cc=suzuki@in.ibm.com \
--cc=tony.luck@intel.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).