Hi, As pointed out in https://bugzilla.redhat.com/show_bug.cgi?id=807053 relocating a compressed section will corrupt it. To more properly support compressed sections we should finish the roland/relocate branch for lazy relocations work. The best we can do for now is to not corrupt the contents of the compressed sections and not crash when we don't have all Dwarf debug section data. The attached two patches do that.
Cheers, Mark
From ce12994c215b08758e5c79fcd1af8b8b3d069acc Mon Sep 17 00:00:00 2001 From: Mark Wielaard <[email protected]> Date: Wed, 28 Mar 2012 11:20:36 +0200 Subject: [PATCH 1/2] readelf.c: Check debug section data before trying to print abbrev or str. * readelf.c (print_debug_abbrev_section): Check there is Dwarf section data. (print_debug_str_section): Likewise. --- src/ChangeLog | 6 ++++++ src/readelf.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6281756..30be3e1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2012-03-28 Mark Wielaard <[email protected]> + + * readelf.c (print_debug_abbrev_section): Check there is Dwarf + section data. + (print_debug_str_section): Likewise. + 2012-03-21 Mark Wielaard <[email protected]> * readelf.c (print_gdb_index_section): Accept version 6. diff --git a/src/readelf.c b/src/readelf.c index f9f56aa..b70779d 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -4566,13 +4566,16 @@ print_debug_abbrev_section (Dwfl_Module *dwflmod __attribute__ ((unused)), Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg) { + const size_t sh_size = (dbg->sectiondata[IDX_debug_abbrev] ? + dbg->sectiondata[IDX_debug_abbrev]->d_size : 0); + printf (gettext ("\nDWARF section [%2zu] '%s' at offset %#" PRIx64 ":\n" " [ Code]\n"), elf_ndxscn (scn), section_name (ebl, ehdr, shdr), (uint64_t) shdr->sh_offset); Dwarf_Off offset = 0; - while (offset < dbg->sectiondata[IDX_debug_abbrev]->d_size) + while (offset < sh_size) { printf (gettext ("\nAbbreviation section at offset %" PRIu64 ":\n"), offset); @@ -6781,7 +6784,8 @@ print_debug_str_section (Dwfl_Module *dwflmod __attribute__ ((unused)), Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg) { - const size_t sh_size = dbg->sectiondata[IDX_debug_str]->d_size; + const size_t sh_size = (dbg->sectiondata[IDX_debug_str] ? + dbg->sectiondata[IDX_debug_str]->d_size : 0); /* Compute floor(log16(shdr->sh_size)). */ GElf_Addr tmp = sh_size; -- 1.7.7.6
From 342eb23d0f9cca93ac1e42e2ff78bc034ec4aa27 Mon Sep 17 00:00:00 2001 From: Mark Wielaard <[email protected]> Date: Wed, 28 Mar 2012 11:38:34 +0200 Subject: [PATCH 2/2] relocate.c (relocate_section): Don't touch compressed sections. Compressed section can only be relocated after decompression, don't touch it or we will corrupt it. --- libdwfl/ChangeLog | 4 ++++ libdwfl/relocate.c | 6 ++++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 87a0555..bbd51d7 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2012-03-28 Mark Wielaard <[email protected]> + + * relocate.c (relocate_section): Don't touch compressed sections. + 2011-12-02 Roland McGrath <[email protected]> * elf-from-memory.c (elf_from_remote_memory): Fix ELFCLASS64 case diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c index 95206f4..effef44 100644 --- a/libdwfl/relocate.c +++ b/libdwfl/relocate.c @@ -319,6 +319,12 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, if (tdata == NULL) return DWFL_E_LIBELF; + if (tname[0] == '.' && tname[1] == 'z' && tdata->d_size >= 4 + 8 + && memcmp (tdata->d_buf, "ZLIB", 4) == 0) + /* Compressed section can only be relocated after decompression, + don't touch it or we will corrupt it. */ + return DWFL_E_NOERROR; + /* Apply one relocation. Returns true for any invalid data. */ Dwfl_Error relocate (GElf_Addr offset, const GElf_Sxword *addend, int rtype, int symndx) -- 1.7.7.6
_______________________________________________ elfutils-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/elfutils-devel
