summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2015-03-23 22:19:12 +0100
committerMark Wielaard <[email protected]>2015-03-27 23:04:34 +0100
commit5370bb0a6492cb4669c8375e53748a4303997ed7 (patch)
treee476cc098d83be0417850ed8ac0bfb384d143e32
parentd4852fab1c8ed9ce1780815616abc596b19ac7d8 (diff)
libelf: Don't extend ELF file size with SHT_NOBITS sh_offset.
Don't explicitly extend the file size for SHT_NOBITS sections. Since that could cause a size beyond any actual file content it will cause issues when the underlying ELF file has been mmapped or will extend the file size to increase (writing fill bytes) when not mmapped. The sh_offset value is essentially meaningless for SHT_NOBITS. gabi says that a NOBITS section sh_offset member locates the "conceptual placement" in the file. But it doesn't say this cannot be beyond the enf of the file. When ELF_F_LAYOUT is set we should trust sh_offset as given is what is wanted for an SHT_NOBITS section without extending the file size. https://bugzilla.redhat.com/show_bug.cgi?id=1020842 Buggy binutils ld could generate files where SHT_NOBITS sections have sh_offset outside the file. https://sourceware.org/bugzilla/show_bug.cgi?id=12921 Signed-off-by: Mark Wielaard <[email protected]>
-rw-r--r--libelf/ChangeLog5
-rw-r--r--libelf/elf32_updatenull.c7
2 files changed, 8 insertions, 4 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 5739c77d..dc9892f8 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-23 Mark Wielaard <[email protected]>
+
+ * elf32_updatenull.c (updatenull_wrlock): Don't extend size with
+ SHT_NOBITS sh_offset.
+
2015-02-18 Mark Wielaard <[email protected]>
* libelfP.h (__libelf_set_data_list_rdlock): Make internal_function.
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index 5e809b79..d873a309 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -1,5 +1,5 @@
/* Update data structures for changes.
- Copyright (C) 2000-2010 Red Hat, Inc.
+ Copyright (C) 2000-2010, 2015 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <[email protected]>, 2000.
@@ -318,9 +318,8 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
if (elf->flags & ELF_F_LAYOUT)
{
size = MAX ((GElf_Word) size,
- shdr->sh_offset
- + (shdr->sh_type != SHT_NOBITS
- ? shdr->sh_size : 0));
+ (shdr->sh_type != SHT_NOBITS
+ ? shdr->sh_offset + shdr->sh_size : 0));
/* The alignment must be a power of two. This is a
requirement from the ELF specification. Additionally