diff options
author | Mark Wielaard <mark@klomp.org> | 2022-03-17 13:58:56 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2022-03-18 00:54:51 +0100 |
commit | 1b09e67353f46f2ff9039da78a37d7717155df08 (patch) | |
tree | 96a93a626311940ca3496289db2da8f2729075ac /libelf | |
parent | 9a36370010df049b1d301a5531246ec7a693b95b (diff) | |
download | elfutils-1b09e67353f46f2ff9039da78a37d7717155df08.tar.gz |
libelf: Take map offset into account for Shdr alignment check in elf_begin
The sh_num function tries to get at the zero section Shdr directly.
When the file is mmapped it has to make sure the offset into the file
to the start of the Elf structure is taken into account when trying to
cast the address to make sure the alignment is correct.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libelf')
-rw-r--r-- | libelf/ChangeLog | 5 | ||||
-rw-r--r-- | libelf/elf_begin.c | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 29a8aae1..1883af07 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2022-03-17 Mark Wielaard <mark@klomp.org> + + * elf_begin.c (get_shnum): Take offset into account for Shdr + alignment check. + 2021-12-19 Mark Wielaard <mark@klomp.org> * elf_begin.c (file_read_elf): Cast ehdr to uintptr_t before e_shoff diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index 0c9a988d..53bbff40 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -1,6 +1,6 @@ /* Create descriptor for processing file. Copyright (C) 1998-2010, 2012, 2014, 2015, 2016 Red Hat, Inc. - Copyright (C) 2021 Mark J. Wielaard <mark@klomp.org> + Copyright (C) 2021, 2022 Mark J. Wielaard <mark@klomp.org> This file is part of elfutils. Written by Ulrich Drepper <drepper@redhat.com>, 1998. @@ -158,7 +158,8 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes, if (likely (map_address != NULL) && e_ident[EI_DATA] == MY_ELFDATA && (ALLOW_UNALIGNED - || (((size_t) ((char *) map_address + ehdr.e32->e_shoff)) + || (((size_t) ((char *) (map_address + ehdr.e32->e_shoff + + offset))) & (__alignof__ (Elf32_Shdr) - 1)) == 0)) /* We can directly access the memory. */ result = ((Elf32_Shdr *) ((char *) map_address + ehdr.e32->e_shoff @@ -218,7 +219,8 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes, Elf64_Xword size; if (likely (map_address != NULL) && e_ident[EI_DATA] == MY_ELFDATA && (ALLOW_UNALIGNED - || (((size_t) ((char *) map_address + ehdr.e64->e_shoff)) + || (((size_t) ((char *) (map_address + ehdr.e64->e_shoff + + offset))) & (__alignof__ (Elf64_Shdr) - 1)) == 0)) /* We can directly access the memory. */ size = ((Elf64_Shdr *) ((char *) map_address + ehdr.e64->e_shoff |