From: Mark Wielaard Date: Mon, 23 Mar 2015 21:19:12 +0000 (+0100) Subject: libelf: Don't extend ELF file size with SHT_NOBITS sh_offset. X-Git-Tag: elfutils-0.162~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5370bb0a6492cb4669c8375e53748a4303997ed7;p=thirdparty%2Felfutils.git 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 --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 5739c77d1..dc9892f85 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2015-03-23 Mark Wielaard + + * elf32_updatenull.c (updatenull_wrlock): Don't extend size with + SHT_NOBITS sh_offset. + 2015-02-18 Mark Wielaard * libelfP.h (__libelf_set_data_list_rdlock): Make internal_function. diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c index 5e809b79f..d873a309c 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 , 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