diff --git a/binutils-2.24-corrupt-elf.patch b/binutils-2.24-corrupt-elf.patch new file mode 100644 index 0000000..0b5d5f8 --- /dev/null +++ b/binutils-2.24-corrupt-elf.patch @@ -0,0 +1,868 @@ +diff -rcp ../binutils-2.24.orig/bfd/elf.c bfd/elf.c +*** ../binutils-2.24.orig/bfd/elf.c 2014-10-28 09:39:29.505064397 +0000 +--- bfd/elf.c 2014-10-28 09:45:17.973958424 +0000 +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1582,1619 **** + Elf_Internal_Ehdr *ehdr; + const struct elf_backend_data *bed; + const char *name; + + if (shindex >= elf_numsections (abfd)) + return FALSE; + + hdr = elf_elfsections (abfd)[shindex]; + ehdr = elf_elfheader (abfd); + name = bfd_elf_string_from_elf_section (abfd, ehdr->e_shstrndx, + hdr->sh_name); + if (name == NULL) +! return FALSE; + + bed = get_elf_backend_data (abfd); + switch (hdr->sh_type) + { + case SHT_NULL: + /* Inactive section. Throw it away. */ +! return TRUE; + +! case SHT_PROGBITS: /* Normal section with contents. */ +! case SHT_NOBITS: /* .bss section. */ +! case SHT_HASH: /* .hash section. */ +! case SHT_NOTE: /* .note section. */ + case SHT_INIT_ARRAY: /* .init_array section. */ + case SHT_FINI_ARRAY: /* .fini_array section. */ + case SHT_PREINIT_ARRAY: /* .preinit_array section. */ + case SHT_GNU_LIBLIST: /* .gnu.liblist section. */ + case SHT_GNU_HASH: /* .gnu.hash section. */ +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + + case SHT_DYNAMIC: /* Dynamic linking information. */ + if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) +! return FALSE; + if (hdr->sh_link > elf_numsections (abfd)) + { + /* PR 10478: Accept Solaris binaries with a sh_link +--- 1582,1648 ---- + Elf_Internal_Ehdr *ehdr; + const struct elf_backend_data *bed; + const char *name; ++ bfd_boolean ret = TRUE; ++ static bfd_boolean * sections_being_created = NULL; ++ static unsigned int nesting = 0; + + if (shindex >= elf_numsections (abfd)) + return FALSE; + ++ if (++ nesting > 3) ++ { ++ /* PR17512: A corrupt ELF binary might contain a recursive group of ++ sections, each the string indicies pointing to the next in the ++ loop. Detect this here, by refusing to load a section that we are ++ already in the process of loading. We only trigger this test if ++ we have nested at least three sections deep as normal ELF binaries ++ can expect to recurse at least once. */ ++ ++ if (sections_being_created == NULL) ++ { ++ /* FIXME: It would be more efficient to attach this array to the bfd somehow. */ ++ sections_being_created = (bfd_boolean *) ++ bfd_zalloc (abfd, elf_numsections (abfd) * sizeof (bfd_boolean)); ++ } ++ if (sections_being_created [shindex]) ++ { ++ (*_bfd_error_handler) ++ (_("%B: warning: loop in section dependencies detected"), abfd); ++ return FALSE; ++ } ++ sections_being_created [shindex] = TRUE; ++ } ++ + hdr = elf_elfsections (abfd)[shindex]; + ehdr = elf_elfheader (abfd); + name = bfd_elf_string_from_elf_section (abfd, ehdr->e_shstrndx, + hdr->sh_name); + if (name == NULL) +! goto fail; + + bed = get_elf_backend_data (abfd); + switch (hdr->sh_type) + { + case SHT_NULL: + /* Inactive section. Throw it away. */ +! goto success; + +! case SHT_PROGBITS: /* Normal section with contents. */ +! case SHT_NOBITS: /* .bss section. */ +! case SHT_HASH: /* .hash section. */ +! case SHT_NOTE: /* .note section. */ + case SHT_INIT_ARRAY: /* .init_array section. */ + case SHT_FINI_ARRAY: /* .fini_array section. */ + case SHT_PREINIT_ARRAY: /* .preinit_array section. */ + case SHT_GNU_LIBLIST: /* .gnu.liblist section. */ + case SHT_GNU_HASH: /* .gnu.hash section. */ +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; + + case SHT_DYNAMIC: /* Dynamic linking information. */ + if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) +! goto fail; +! + if (hdr->sh_link > elf_numsections (abfd)) + { + /* PR 10478: Accept Solaris binaries with a sh_link +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1627,1637 **** + break; + /* Otherwise fall through. */ + default: +! return FALSE; + } + } + else if (elf_elfsections (abfd)[hdr->sh_link] == NULL) +! return FALSE; + else if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB) + { + Elf_Internal_Shdr *dynsymhdr; +--- 1656,1666 ---- + break; + /* Otherwise fall through. */ + default: +! goto fail; + } + } + else if (elf_elfsections (abfd)[hdr->sh_link] == NULL) +! goto fail; + else if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB) + { + Elf_Internal_Shdr *dynsymhdr; +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1660,1683 **** + } + } + } +! break; + +! case SHT_SYMTAB: /* A symbol table */ + if (elf_onesymtab (abfd) == shindex) +! return TRUE; + + if (hdr->sh_entsize != bed->s->sizeof_sym) +! return FALSE; + if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size) + { + if (hdr->sh_size != 0) +! return FALSE; + /* Some assemblers erroneously set sh_info to one with a + zero sh_size. ld sees this as a global symbol count + of (unsigned) -1. Fix it here. */ + hdr->sh_info = 0; +! return TRUE; + } + BFD_ASSERT (elf_onesymtab (abfd) == 0); + elf_onesymtab (abfd) = shindex; + elf_tdata (abfd)->symtab_hdr = *hdr; +--- 1689,1714 ---- + } + } + } +! goto success; + +! case SHT_SYMTAB: /* A symbol table. */ + if (elf_onesymtab (abfd) == shindex) +! goto success; + + if (hdr->sh_entsize != bed->s->sizeof_sym) +! goto fail; +! + if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size) + { + if (hdr->sh_size != 0) +! goto fail; + /* Some assemblers erroneously set sh_info to one with a + zero sh_size. ld sees this as a global symbol count + of (unsigned) -1. Fix it here. */ + hdr->sh_info = 0; +! goto success; + } ++ + BFD_ASSERT (elf_onesymtab (abfd) == 0); + elf_onesymtab (abfd) = shindex; + elf_tdata (abfd)->symtab_hdr = *hdr; +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1694,1700 **** + && (abfd->flags & DYNAMIC) != 0 + && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name, + shindex)) +! return FALSE; + + /* Go looking for SHT_SYMTAB_SHNDX too, since if there is one we + can't read symbols without that section loaded as well. It +--- 1725,1731 ---- + && (abfd->flags & DYNAMIC) != 0 + && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name, + shindex)) +! goto fail; + + /* Go looking for SHT_SYMTAB_SHNDX too, since if there is one we + can't read symbols without that section loaded as well. It +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1720,1745 **** + break; + } + if (i != shindex) +! return bfd_section_from_shdr (abfd, i); + } +! return TRUE; + +! case SHT_DYNSYM: /* A dynamic symbol table */ + if (elf_dynsymtab (abfd) == shindex) +! return TRUE; + + if (hdr->sh_entsize != bed->s->sizeof_sym) +! return FALSE; + if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size) + { + if (hdr->sh_size != 0) +! return FALSE; + /* Some linkers erroneously set sh_info to one with a + zero sh_size. ld sees this as a global symbol count + of (unsigned) -1. Fix it here. */ + hdr->sh_info = 0; +! return TRUE; + } + BFD_ASSERT (elf_dynsymtab (abfd) == 0); + elf_dynsymtab (abfd) = shindex; + elf_tdata (abfd)->dynsymtab_hdr = *hdr; +--- 1751,1779 ---- + break; + } + if (i != shindex) +! ret = bfd_section_from_shdr (abfd, i); + } +! goto success; + +! case SHT_DYNSYM: /* A dynamic symbol table. */ + if (elf_dynsymtab (abfd) == shindex) +! goto success; + + if (hdr->sh_entsize != bed->s->sizeof_sym) +! goto fail; +! + if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size) + { + if (hdr->sh_size != 0) +! goto fail; +! + /* Some linkers erroneously set sh_info to one with a + zero sh_size. ld sees this as a global symbol count + of (unsigned) -1. Fix it here. */ + hdr->sh_info = 0; +! goto success; + } ++ + BFD_ASSERT (elf_dynsymtab (abfd) == 0); + elf_dynsymtab (abfd) = shindex; + elf_tdata (abfd)->dynsymtab_hdr = *hdr; +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1748,1781 **** + + /* Besides being a symbol table, we also treat this as a regular + section, so that objcopy can handle it. */ +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + +! case SHT_SYMTAB_SHNDX: /* Symbol section indices when >64k sections */ + if (elf_symtab_shndx (abfd) == shindex) +! return TRUE; + + BFD_ASSERT (elf_symtab_shndx (abfd) == 0); + elf_symtab_shndx (abfd) = shindex; + elf_tdata (abfd)->symtab_shndx_hdr = *hdr; + elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->symtab_shndx_hdr; +! return TRUE; + +! case SHT_STRTAB: /* A string table */ + if (hdr->bfd_section != NULL) +! return TRUE; + if (ehdr->e_shstrndx == shindex) + { + elf_tdata (abfd)->shstrtab_hdr = *hdr; + elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr; +! return TRUE; + } + if (elf_elfsections (abfd)[elf_onesymtab (abfd)]->sh_link == shindex) + { + symtab_strtab: + elf_tdata (abfd)->strtab_hdr = *hdr; + elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->strtab_hdr; +! return TRUE; + } + if (elf_elfsections (abfd)[elf_dynsymtab (abfd)]->sh_link == shindex) + { + dynsymtab_strtab: +--- 1782,1819 ---- + + /* Besides being a symbol table, we also treat this as a regular + section, so that objcopy can handle it. */ +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; + +! case SHT_SYMTAB_SHNDX: /* Symbol section indices when >64k sections. */ + if (elf_symtab_shndx (abfd) == shindex) +! goto success; + + BFD_ASSERT (elf_symtab_shndx (abfd) == 0); + elf_symtab_shndx (abfd) = shindex; + elf_tdata (abfd)->symtab_shndx_hdr = *hdr; + elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->symtab_shndx_hdr; +! goto success; + +! case SHT_STRTAB: /* A string table. */ + if (hdr->bfd_section != NULL) +! goto success; +! + if (ehdr->e_shstrndx == shindex) + { + elf_tdata (abfd)->shstrtab_hdr = *hdr; + elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr; +! goto success; + } ++ + if (elf_elfsections (abfd)[elf_onesymtab (abfd)]->sh_link == shindex) + { + symtab_strtab: + elf_tdata (abfd)->strtab_hdr = *hdr; + elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->strtab_hdr; +! goto success; + } ++ + if (elf_elfsections (abfd)[elf_dynsymtab (abfd)]->sh_link == shindex) + { + dynsymtab_strtab: +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1784,1791 **** + elf_elfsections (abfd)[shindex] = hdr; + /* We also treat this as a regular section, so that objcopy + can handle it. */ +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); + } + + /* If the string table isn't one of the above, then treat it as a +--- 1822,1830 ---- + elf_elfsections (abfd)[shindex] = hdr; + /* We also treat this as a regular section, so that objcopy + can handle it. */ +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); +! goto success; + } + + /* If the string table isn't one of the above, then treat it as a +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1803,1811 **** + { + /* Prevent endless recursion on broken objects. */ + if (i == shindex) +! return FALSE; + if (! bfd_section_from_shdr (abfd, i)) +! return FALSE; + if (elf_onesymtab (abfd) == i) + goto symtab_strtab; + if (elf_dynsymtab (abfd) == i) +--- 1842,1850 ---- + { + /* Prevent endless recursion on broken objects. */ + if (i == shindex) +! goto fail; + if (! bfd_section_from_shdr (abfd, i)) +! goto fail; + if (elf_onesymtab (abfd) == i) + goto symtab_strtab; + if (elf_dynsymtab (abfd) == i) +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1813,1819 **** + } + } + } +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + + case SHT_REL: + case SHT_RELA: +--- 1852,1859 ---- + } + } + } +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; + + case SHT_REL: + case SHT_RELA: +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1828,1834 **** + if (hdr->sh_entsize + != (bfd_size_type) (hdr->sh_type == SHT_REL + ? bed->s->sizeof_rel : bed->s->sizeof_rela)) +! return FALSE; + + /* Check for a bogus link to avoid crashing. */ + if (hdr->sh_link >= num_sec) +--- 1868,1874 ---- + if (hdr->sh_entsize + != (bfd_size_type) (hdr->sh_type == SHT_REL + ? bed->s->sizeof_rel : bed->s->sizeof_rela)) +! goto fail; + + /* Check for a bogus link to avoid crashing. */ + if (hdr->sh_link >= num_sec) +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1836,1843 **** + ((*_bfd_error_handler) + (_("%B: invalid link %lu for reloc section %s (index %u)"), + abfd, hdr->sh_link, name, shindex)); +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); + } + + /* For some incomprehensible reason Oracle distributes +--- 1876,1884 ---- + ((*_bfd_error_handler) + (_("%B: invalid link %lu for reloc section %s (index %u)"), + abfd, hdr->sh_link, name, shindex)); +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); +! goto success; + } + + /* For some incomprehensible reason Oracle distributes +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1878,1884 **** + if ((elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB + || elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_DYNSYM) + && ! bfd_section_from_shdr (abfd, hdr->sh_link)) +! return FALSE; + + /* If this reloc section does not use the main symbol table we + don't treat it as a reloc section. BFD can't adequately +--- 1919,1925 ---- + if ((elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB + || elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_DYNSYM) + && ! bfd_section_from_shdr (abfd, hdr->sh_link)) +! goto fail; + + /* If this reloc section does not use the main symbol table we + don't treat it as a reloc section. BFD can't adequately +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1893,1906 **** + || hdr->sh_info >= num_sec + || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL + || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA) +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); + + if (! bfd_section_from_shdr (abfd, hdr->sh_info)) +! return FALSE; + target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info); + if (target_sect == NULL) +! return FALSE; + + esdt = elf_section_data (target_sect); + if (hdr->sh_type == SHT_RELA) +--- 1934,1951 ---- + || hdr->sh_info >= num_sec + || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL + || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA) +! { +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); +! goto success; +! } + + if (! bfd_section_from_shdr (abfd, hdr->sh_info)) +! goto fail; +! + target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info); + if (target_sect == NULL) +! goto fail; + + esdt = elf_section_data (target_sect); + if (hdr->sh_type == SHT_RELA) +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1912,1918 **** + amt = sizeof (*hdr2); + hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt); + if (hdr2 == NULL) +! return FALSE; + *hdr2 = *hdr; + *p_hdr = hdr2; + elf_elfsections (abfd)[shindex] = hdr2; +--- 1957,1963 ---- + amt = sizeof (*hdr2); + hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt); + if (hdr2 == NULL) +! goto fail; + *hdr2 = *hdr; + *p_hdr = hdr2; + elf_elfsections (abfd)[shindex] = hdr2; +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1928,1961 **** + target_sect->use_rela_p = 1; + } + abfd->flags |= HAS_RELOC; +! return TRUE; + } + + case SHT_GNU_verdef: + elf_dynverdef (abfd) = shindex; + elf_tdata (abfd)->dynverdef_hdr = *hdr; +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + + case SHT_GNU_versym: + if (hdr->sh_entsize != sizeof (Elf_External_Versym)) +! return FALSE; + elf_dynversym (abfd) = shindex; + elf_tdata (abfd)->dynversym_hdr = *hdr; +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + + case SHT_GNU_verneed: + elf_dynverref (abfd) = shindex; + elf_tdata (abfd)->dynverref_hdr = *hdr; +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + + case SHT_SHLIB: +! return TRUE; + + case SHT_GROUP: + if (! IS_VALID_GROUP_SECTION_HEADER (hdr, GRP_ENTRY_SIZE)) +! return FALSE; + if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) +! return FALSE; + if (hdr->contents != NULL) + { + Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents; +--- 1973,2012 ---- + target_sect->use_rela_p = 1; + } + abfd->flags |= HAS_RELOC; +! goto success; + } + + case SHT_GNU_verdef: + elf_dynverdef (abfd) = shindex; + elf_tdata (abfd)->dynverdef_hdr = *hdr; +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; + + case SHT_GNU_versym: + if (hdr->sh_entsize != sizeof (Elf_External_Versym)) +! goto fail; +! + elf_dynversym (abfd) = shindex; + elf_tdata (abfd)->dynversym_hdr = *hdr; +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; + + case SHT_GNU_verneed: + elf_dynverref (abfd) = shindex; + elf_tdata (abfd)->dynverref_hdr = *hdr; +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; + + case SHT_SHLIB: +! goto success; + + case SHT_GROUP: + if (! IS_VALID_GROUP_SECTION_HEADER (hdr, GRP_ENTRY_SIZE)) +! goto fail; +! + if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) +! goto fail; +! + if (hdr->contents != NULL) + { + Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents; +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1981,1987 **** + } + } + } +! break; + + default: + /* Possibly an attributes section. */ +--- 2032,2038 ---- + } + } + } +! goto success; + + default: + /* Possibly an attributes section. */ +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 1989,2002 **** + || hdr->sh_type == bed->obj_attrs_section_type) + { + if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) +! return FALSE; + _bfd_elf_parse_attributes (abfd, hdr); +! return TRUE; + } + + /* Check for any processor-specific section types. */ + if (bed->elf_backend_section_from_shdr (abfd, hdr, name, shindex)) +! return TRUE; + + if (hdr->sh_type >= SHT_LOUSER && hdr->sh_type <= SHT_HIUSER) + { +--- 2040,2053 ---- + || hdr->sh_type == bed->obj_attrs_section_type) + { + if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) +! goto fail; + _bfd_elf_parse_attributes (abfd, hdr); +! goto success; + } + + /* Check for any processor-specific section types. */ + if (bed->elf_backend_section_from_shdr (abfd, hdr, name, shindex)) +! goto success; + + if (hdr->sh_type >= SHT_LOUSER && hdr->sh_type <= SHT_HIUSER) + { +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 2008,2016 **** + "specific section `%s' [0x%8x]"), + abfd, name, hdr->sh_type); + else +! /* Allow sections reserved for applications. */ +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); + } + else if (hdr->sh_type >= SHT_LOPROC + && hdr->sh_type <= SHT_HIPROC) +--- 2059,2070 ---- + "specific section `%s' [0x%8x]"), + abfd, name, hdr->sh_type); + else +! { +! /* Allow sections reserved for applications. */ +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, +! shindex); +! goto success; +! } + } + else if (hdr->sh_type >= SHT_LOPROC + && hdr->sh_type <= SHT_HIPROC) +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 2031,2038 **** + "`%s' [0x%8x]"), + abfd, name, hdr->sh_type); + else +! /* Otherwise it should be processed. */ +! return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); + } + else + /* FIXME: We should handle this section. */ +--- 2085,2095 ---- + "`%s' [0x%8x]"), + abfd, name, hdr->sh_type); + else +! { +! /* Otherwise it should be processed. */ +! ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex); +! goto success; +! } + } + else + /* FIXME: We should handle this section. */ +*************** bfd_section_from_shdr (bfd *abfd, unsign +*** 2040,2049 **** + (_("%B: don't know how to handle section `%s' [0x%8x]"), + abfd, name, hdr->sh_type); + +! return FALSE; + } + +! return TRUE; + } + + /* Return the local symbol specified by ABFD, R_SYMNDX. */ +--- 2097,2113 ---- + (_("%B: don't know how to handle section `%s' [0x%8x]"), + abfd, name, hdr->sh_type); + +! goto fail; + } + +! fail: +! ret = FALSE; +! success: +! if (sections_being_created) +! sections_being_created [shindex] = FALSE; +! if (-- nesting == 0) +! sections_being_created = NULL; +! return ret; + } + + /* Return the local symbol specified by ABFD, R_SYMNDX. */ +diff -rcp ../binutils-2.24.orig/bfd/peXXigen.c bfd/peXXigen.c +*** ../binutils-2.24.orig/bfd/peXXigen.c 2014-10-28 09:39:31.656075721 +0000 +--- bfd/peXXigen.c 2014-10-28 09:43:31.011370536 +0000 +*************** _bfd_XXi_swap_aouthdr_in (bfd * abfd, +*** 460,465 **** +--- 460,476 ---- + { + int idx; + ++ /* PR 17512: Corrupt PE binaries can cause seg-faults. */ ++ if (a->NumberOfRvaAndSizes > 16) ++ { ++ (*_bfd_error_handler) ++ (_("%B: aout header specifies an invalid number of data-directory entries: %d"), ++ abfd, a->NumberOfRvaAndSizes); ++ /* Paranoia: If the number is corrupt, then assume that the ++ actual entries themselves might be corrupt as well. */ ++ a->NumberOfRvaAndSizes = 0; ++ } ++ + for (idx = 0; idx < a->NumberOfRvaAndSizes; idx++) + { + /* If data directory is empty, rva also should be 0. */ +*************** pe_print_edata (bfd * abfd, void * vfile +*** 1364,1370 **** + bfd_size_type datasize = 0; + bfd_size_type dataoff; + bfd_size_type i; +! bfd_signed_vma adj; + struct EDT_type + { + long export_flags; /* Reserved - should be zero. */ +--- 1375,1381 ---- + bfd_size_type datasize = 0; + bfd_size_type dataoff; + bfd_size_type i; +! bfd_vma adj; + struct EDT_type + { + long export_flags; /* Reserved - should be zero. */ +*************** pe_print_edata (bfd * abfd, void * vfile +*** 1414,1419 **** +--- 1425,1437 ---- + _("\nThere is an export table, but the section containing it could not be found\n")); + return TRUE; + } ++ else if (!(section->flags & SEC_HAS_CONTENTS)) ++ { ++ fprintf (file, ++ _("\nThere is an export table in %s, but that section has no contents\n"), ++ section->name); ++ return TRUE; ++ } + + dataoff = addr - section->vma; + datasize = extra->DataDirectory[PE_EXPORT_TABLE].Size; +*************** pe_print_edata (bfd * abfd, void * vfile +*** 1469,1476 **** + fprintf (file, + _("Name \t\t\t\t")); + bfd_fprintf_vma (abfd, file, edt.name); +! fprintf (file, +! " %s\n", data + edt.name - adj); + + fprintf (file, + _("Ordinal Base \t\t\t%ld\n"), edt.base); +--- 1487,1497 ---- + fprintf (file, + _("Name \t\t\t\t")); + bfd_fprintf_vma (abfd, file, edt.name); +! +! if ((edt.name >= adj) && (edt.name < adj + datasize)) +! fprintf (file, " %s\n", data + edt.name - adj); +! else +! fprintf (file, "(outside .edata section)\n"); + + fprintf (file, + _("Ordinal Base \t\t\t%ld\n"), edt.base); +*************** pe_print_edata (bfd * abfd, void * vfile +*** 1516,1522 **** + _("\nExport Address Table -- Ordinal Base %ld\n"), + edt.base); + +! for (i = 0; i < edt.num_functions; ++i) + { + bfd_vma eat_member = bfd_get_32 (abfd, + data + edt.eat_addr + (i * 4) - adj); +--- 1537,1548 ---- + _("\nExport Address Table -- Ordinal Base %ld\n"), + edt.base); + +! /* PR 17512: Handle corrupt PE binaries. */ +! if (edt.eat_addr + (edt.num_functions * 4) - adj >= datasize) +! fprintf (file, _("\tInvalid Export Address Table rva (0x%lx) or entry count (0x%lx)\n"), +! (long) edt.eat_addr, +! (long) edt.num_functions); +! else for (i = 0; i < edt.num_functions; ++i) + { + bfd_vma eat_member = bfd_get_32 (abfd, + data + edt.eat_addr + (i * 4) - adj); +*************** pe_print_edata (bfd * abfd, void * vfile +*** 1552,1558 **** + fprintf (file, + _("\n[Ordinal/Name Pointer] Table\n")); + +! for (i = 0; i < edt.num_names; ++i) + { + bfd_vma name_ptr = bfd_get_32 (abfd, + data + +--- 1578,1593 ---- + fprintf (file, + _("\n[Ordinal/Name Pointer] Table\n")); + +! /* PR 17512: Handle corrupt PE binaries. */ +! if (edt.npt_addr + (edt.num_names * 4) - adj >= datasize) +! fprintf (file, _("\tInvalid Name Pointer Table rva (0x%lx) or entry count (0x%lx)\n"), +! (long) edt.npt_addr, +! (long) edt.num_names); +! else if (edt.ot_addr + (edt.num_names * 2) - adj >= datasize) +! fprintf (file, _("\tInvalid Ordinal Table rva (0x%lx) or entry count (0x%lx)\n"), +! (long) edt.ot_addr, +! (long) edt.num_names); +! else for (i = 0; i < edt.num_names; ++i) + { + bfd_vma name_ptr = bfd_get_32 (abfd, + data + +diff -rcp ../binutils-2.24.orig/bfd/srec.c bfd/srec.c +*** ../binutils-2.24.orig/bfd/srec.c 2014-10-28 09:39:30.762071014 +0000 +--- bfd/srec.c 2014-10-28 09:40:54.769513267 +0000 +*************** srec_bad_byte (bfd *abfd, +*** 248,254 **** + } + else + { +! char buf[10]; + + if (! ISPRINT (c)) + sprintf (buf, "\\%03o", (unsigned int) c); +--- 248,254 ---- + } + else + { +! char buf[40]; + + if (! ISPRINT (c)) + sprintf (buf, "\\%03o", (unsigned int) c); +*************** srec_scan (bfd *abfd) +*** 454,460 **** + case 'S': + { + file_ptr pos; +! char hdr[3]; + unsigned int bytes, min_bytes; + bfd_vma address; + bfd_byte *data; +--- 454,460 ---- + case 'S': + { + file_ptr pos; +! unsigned char hdr[3]; + unsigned int bytes, min_bytes; + bfd_vma address; + bfd_byte *data; diff --git a/binutils.spec b/binutils.spec index 4f19f93..3d370ec 100644 --- a/binutils.spec +++ b/binutils.spec @@ -17,7 +17,7 @@ Summary: A GNU collection of binary utilities Name: %{?cross}binutils%{?_with_debug:-debug} Version: 2.24 -Release: 24%{?dist} +Release: 25%{?dist} License: GPLv3+ Group: Development/Tools URL: http://sources.redhat.com/binutils @@ -72,6 +72,7 @@ Patch29: binutils-2.24-aarch64-fix-ie-relax.patch Patch30: binutils-HEAD-change-ld-notice-interface.patch Patch31: binutils-2.24-corrupt-srec.patch Patch32: binutils-2.24-corrupt-groups.patch +Patch33: binutils-2.24-corrupt-elf.patch Provides: bundled(libiberty) @@ -206,8 +207,9 @@ using libelf instead of BFD. %patch28 -p1 -b .aa64-2~ %patch29 -p1 -b .aa64-3~ %patch30 -p1 -b .ldplugin~ -%patch31 -p0 -b .srec~ -%patch32 -p0 -b .groups~ +%patch31 -p0 -b .corrupt-srec~ +%patch32 -p0 -b .corrupt-groups~ +%patch33 -p0 -b .corrupt-elf~ # We cannot run autotools as there is an exact requirement of autoconf-2.59. @@ -519,6 +521,10 @@ exit 0 %endif # %{isnative} %changelog +* Tue Oct 28 2014 Nick Clifton - 2.24-25 +- Import patches for PR/17510 and PR/17512 to fix reading corrupt ELF binaries. + Resolves: BZ #1157276, #1157277 + * Mon Oct 27 2014 Nick Clifton - 2.24-24 - Import patch from mainline to fix seg-fault when reading corrupt group headers. Resolves: BZ #1157276, #11527277