From 510fcad8b0159f71e83037e1d85a6efa90fdf8f1 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 26 Aug 2020 00:11:50 +0200 Subject: [PATCH] 0.180-7 - Add elfutils-0.180-shf-compressed.patch --- elfutils-0.180-shf-compressed.patch | 68 +++++++++++++++++++++++++++++ elfutils.spec | 7 ++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 elfutils-0.180-shf-compressed.patch diff --git a/elfutils-0.180-shf-compressed.patch b/elfutils-0.180-shf-compressed.patch new file mode 100644 index 0000000..1a91d98 --- /dev/null +++ b/elfutils-0.180-shf-compressed.patch @@ -0,0 +1,68 @@ +commit 55c5c9a568ed707bcea1388bf3a525212d8cf4b8 +Author: Mark Wielaard +Date: Wed Aug 19 23:41:24 2020 +0200 + + libelf: Fixup SHF_COMPRESSED sh_addralign in elf_update if necessary. + + In elf_getdata.c we have the following to compensate for possibly + bad sh_addralign values of compressed sections: + + /* Compressed data has a header, but then compressed data. + Make sure to set the alignment of the header explicitly, + don't trust the file alignment for the section, it is + often wrong. */ + if ((flags & SHF_COMPRESSED) != 0) + { + entsize = 1; + align = __libelf_type_align (elf->class, ELF_T_CHDR); + } + + Which makes sure the d_data alignment is correct for the Chdr struct + at the start of the compressed section. + + But this means that if a user just reads such a compressed section + without changing it, and then tries to write it out again using + elf_update they get an error message about d_align and sh_addralign + being out of sync. + + We already correct obviously incorrect sh_entsize fields. + Do the same for the sh_addralign field of a SHF_COMPRESSED section. + + Signed-off-by: Mark Wielaard + +diff --git a/libelf/ChangeLog b/libelf/ChangeLog +index 8f6d2d2d..77044c1c 100644 +--- a/libelf/ChangeLog ++++ b/libelf/ChangeLog +@@ -1,3 +1,8 @@ ++2020-08-19 Mark Wielaard ++ ++ * elf32_updatenull.c (updatenull_wrlock): Fixup the sh_addralign ++ of an SHF_COMPRESSED section if necessary. ++ + 2020-06-04 Mark Wielaard + + * elf.h: Update from glibc. +diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c +index 5f3cdbf6..d0d4d1eb 100644 +--- a/libelf/elf32_updatenull.c ++++ b/libelf/elf32_updatenull.c +@@ -267,6 +267,18 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum) + update_if_changed (shdr->sh_entsize, sh_entsize, + scn->shdr_flags); + ++ /* Likewise for the alignment of a compressed section. ++ For a SHF_COMPRESSED section set the correct ++ sh_addralign value, which must match the d_align of ++ the data (see __libelf_set_rawdata in elf_getdata.c). */ ++ if ((shdr->sh_flags & SHF_COMPRESSED) != 0) ++ { ++ sh_align = __libelf_type_align (ELFW(ELFCLASS,LIBELFBITS), ++ ELF_T_CHDR); ++ update_if_changed (shdr->sh_addralign, sh_align, ++ scn->shdr_flags); ++ } ++ + if (scn->data_read == 0 + && __libelf_set_rawdata_wrlock (scn) != 0) + /* Something went wrong. The error value is already set. */ diff --git a/elfutils.spec b/elfutils.spec index ce301d0..1a9aa78 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,6 +1,6 @@ Name: elfutils Version: 0.180 -%global baserelease 4 +%global baserelease 7 Release: %{baserelease}%{?dist} URL: http://elfutils.org/ %global source_url ftp://sourceware.org/pub/elfutils/%{version}/ @@ -56,6 +56,7 @@ BuildRequires: curl # Patches Patch1: elfutils-0.180-mhd-result.patch +Patch2: elfutils-0.180-shf-compressed.patch %description Elfutils is a collection of utilities, including stack (to show @@ -248,6 +249,7 @@ such servers to download those files on demand. # Apply patches %patch1 -p1 -b .mhd_result +%patch2 -p1 -b .shf_compressed # In case the above patches added any new test scripts, make sure they # are executable. @@ -432,6 +434,9 @@ exit 0 %systemd_postun_with_restart debuginfod.service %changelog +* Tue Aug 25 2020 Mark Wielaard - 0.180-7 +- Add elfutils-0.180-shf-compressed.patch + * Wed Jul 22 2020 Mark Wielaard - 0.180-5 - Remove duplicate listing of sysconfig/debuginfod (config) file.