]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Don't extend ELF file size with SHT_NOBITS sh_offset.
authorMark Wielaard <mjw@redhat.com>
Mon, 23 Mar 2015 21:19:12 +0000 (22:19 +0100)
committerMark Wielaard <mjw@redhat.com>
Fri, 27 Mar 2015 22:04:34 +0000 (23:04 +0100)
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 <mjw@redhat.com>
libelf/ChangeLog
libelf/elf32_updatenull.c

index 5739c77d13cb45776bf479002643bda6b67c3d1e..dc9892f8558da8c9644e5bb67f53bdfbab949ae1 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-23  Mark Wielaard  <mjw@redhat.com>
+
+       * elf32_updatenull.c (updatenull_wrlock): Don't extend size with
+       SHT_NOBITS sh_offset.
+
 2015-02-18  Mark Wielaard  <mjw@redhat.com>
 
        * libelfP.h (__libelf_set_data_list_rdlock): Make internal_function.
index 5e809b79fcbb9f363a4035b0e9d58e05b56508fe..d873a309c1f08c0bb3513338049dc65b2b6d8ade 100644 (file)
@@ -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 <drepper@redhat.com>, 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