|
|
bb3be4 |
From cb83c302eb77748a99940fa41026d5f373976478 Mon Sep 17 00:00:00 2001
|
|
|
bb3be4 |
From: Paul Eggert <eggert@cs.ucla.edu>
|
|
|
bb3be4 |
Date: Mon, 16 Nov 2015 17:48:08 -0800
|
|
|
bb3be4 |
Subject: [PATCH 11/11] ELF unexec: align section header
|
|
|
bb3be4 |
MIME-Version: 1.0
|
|
|
bb3be4 |
Content-Type: text/plain; charset=UTF-8
|
|
|
bb3be4 |
Content-Transfer-Encoding: 8bit
|
|
|
bb3be4 |
|
|
|
bb3be4 |
This ports the recent unexelf.c changes to Fedora x86-64
|
|
|
bb3be4 |
when configured with GCC’s -fsanitize=undefined option.
|
|
|
bb3be4 |
* src/unexelf.c (unexec): Align new_data2_size to a multiple
|
|
|
bb3be4 |
of ElfW (Shdr)’s alignment, so that NEW_SECTION_H returns a
|
|
|
bb3be4 |
pointer aligned appropriately for its type.
|
|
|
bb3be4 |
---
|
|
|
bb3be4 |
src/unexelf.c | 11 ++++++++---
|
|
|
bb3be4 |
1 file changed, 8 insertions(+), 3 deletions(-)
|
|
|
bb3be4 |
|
|
|
bb3be4 |
diff --git a/src/unexelf.c b/src/unexelf.c
|
|
|
bb3be4 |
index c10c7f2..03e6daf 100644
|
|
|
bb3be4 |
--- a/src/unexelf.c
|
|
|
bb3be4 |
+++ b/src/unexelf.c
|
|
|
bb3be4 |
@@ -247,7 +247,7 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
|
|
|
bb3be4 |
ElfW (Phdr) *old_bss_seg, *new_bss_seg;
|
|
|
bb3be4 |
ElfW (Addr) old_bss_addr, new_bss_addr;
|
|
|
bb3be4 |
- ElfW (Word) old_bss_size, new_data2_size;
|
|
|
bb3be4 |
+ ElfW (Word) old_bss_size, bss_size_growth, new_data2_size;
|
|
|
bb3be4 |
ElfW (Off) old_bss_offset, new_data2_offset;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
ptrdiff_t n;
|
|
|
bb3be4 |
@@ -331,7 +331,11 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
|
|
|
bb3be4 |
new_break = sbrk (0);
|
|
|
bb3be4 |
new_bss_addr = (ElfW (Addr)) new_break;
|
|
|
bb3be4 |
- new_data2_size = new_bss_addr - old_bss_addr;
|
|
|
bb3be4 |
+ bss_size_growth = new_bss_addr - old_bss_addr;
|
|
|
bb3be4 |
+ new_data2_size = bss_size_growth;
|
|
|
bb3be4 |
+ new_data2_size += alignof (ElfW (Shdr)) - 1;
|
|
|
bb3be4 |
+ new_data2_size -= new_data2_size % alignof (ElfW (Shdr));
|
|
|
bb3be4 |
+
|
|
|
bb3be4 |
new_data2_offset = old_bss_offset;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
#ifdef UNEXELF_DEBUG
|
|
|
bb3be4 |
@@ -399,7 +403,8 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
new_bss_seg->p_memsz = new_bss_seg->p_filesz;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Copy over what we have in memory now for the bss area. */
|
|
|
bb3be4 |
- memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr, new_data2_size);
|
|
|
bb3be4 |
+ memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr,
|
|
|
bb3be4 |
+ bss_size_growth);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Walk through all section headers, copying data and updating. */
|
|
|
bb3be4 |
for (n = 1; n < old_file_h->e_shnum; n++)
|
|
|
bb3be4 |
--
|
|
|
bb3be4 |
2.7.4
|
|
|
bb3be4 |
|