Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933474Ab3CSCaf (ORCPT ); Mon, 18 Mar 2013 22:30:35 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:46211 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933377Ab3CSCad (ORCPT ); Mon, 18 Mar 2013 22:30:33 -0400 From: HATAYAMA Daisuke Subject: [PATCH v3 06/21] vmcore: round up buffer size of ELF headers by PAGE_SIZE To: vgoyal@redhat.com, ebiederm@xmission.com, cpw@sgi.com, kumagai-atsushi@mxc.nes.nec.co.jp, lisa.mitchell@hp.com, heiko.carstens@de.ibm.com, akpm@linux-foundation.org Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, zhangyanfei@cn.fujitsu.com Date: Sat, 16 Mar 2013 13:01:21 +0900 Message-ID: <20130316040121.15064.35279.stgit@localhost6.localdomain6> In-Reply-To: <20130316040003.15064.62308.stgit@localhost6.localdomain6> References: <20130316040003.15064.62308.stgit@localhost6.localdomain6> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3168 Lines: 82 To satisfy mmap() page-size boundary requirement, round up buffer size of ELF headers by PAGE_SIZE. The resulting value becomes offset of ELF note segments and it's assigned in unique PT_NOTE program header entry. Also, some part that assumes past ELF headers' size is replaced by this new rounded-up value. Signed-off-by: HATAYAMA Daisuke --- fs/proc/vmcore.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 17e2501..dd9769d 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -339,7 +339,7 @@ static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz, phdr.p_flags = 0; note_off = ehdr_ptr->e_phoff + (ehdr_ptr->e_phnum - nr_ptnote +1) * sizeof(Elf64_Phdr); - phdr.p_offset = note_off; + phdr.p_offset = roundup(note_off, PAGE_SIZE); phdr.p_vaddr = phdr.p_paddr = 0; phdr.p_filesz = phdr.p_memsz = phdr_sz; phdr.p_align = 0; @@ -352,6 +352,7 @@ static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz, /* Modify e_phnum to reflect merged headers. */ ehdr_ptr->e_phnum = ehdr_ptr->e_phnum - nr_ptnote + 1; + *elfsz = roundup(*elfsz, PAGE_SIZE); out: return 0; } @@ -447,7 +448,7 @@ static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz, phdr.p_flags = 0; note_off = ehdr_ptr->e_phoff + (ehdr_ptr->e_phnum - nr_ptnote +1) * sizeof(Elf32_Phdr); - phdr.p_offset = note_off; + phdr.p_offset = roundup(note_off, PAGE_SIZE); phdr.p_vaddr = phdr.p_paddr = 0; phdr.p_filesz = phdr.p_memsz = phdr_sz; phdr.p_align = 0; @@ -460,6 +461,7 @@ static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz, /* Modify e_phnum to reflect merged headers. */ ehdr_ptr->e_phnum = ehdr_ptr->e_phnum - nr_ptnote + 1; + *elfsz = roundup(*elfsz, PAGE_SIZE); out: return 0; } @@ -480,9 +482,8 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, phdr_ptr = (Elf64_Phdr*)(elfptr + ehdr_ptr->e_phoff); /* PT_NOTE hdr */ /* First program header is PT_NOTE header. */ - vmcore_off = ehdr_ptr->e_phoff + - (ehdr_ptr->e_phnum) * sizeof(Elf64_Phdr) + - phdr_ptr->p_memsz; /* Note sections */ + vmcore_off = phdr_ptr->p_offset + roundup(phdr_ptr->p_memsz, + PAGE_SIZE); for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) { if (phdr_ptr->p_type != PT_LOAD) @@ -517,9 +518,8 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, phdr_ptr = (Elf32_Phdr*)(elfptr + ehdr_ptr->e_phoff); /* PT_NOTE hdr */ /* First program header is PT_NOTE header. */ - vmcore_off = ehdr_ptr->e_phoff + - (ehdr_ptr->e_phnum) * sizeof(Elf32_Phdr) + - phdr_ptr->p_memsz; /* Note sections */ + vmcore_off = phdr_ptr->p_offset + roundup(phdr_ptr->p_memsz, + PAGE_SIZE); for (i = 0; i < ehdr_ptr->e_phnum; i++, phdr_ptr++) { if (phdr_ptr->p_type != PT_LOAD) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/