Blame SOURCES/binutils-CVE-2020-35448.patch

61bcc6
diff -rup binutils.orig/bfd/elf.c binutils-2.35/bfd/elf.c
61bcc6
--- binutils.orig/bfd/elf.c	2021-04-19 10:49:21.757290990 +0100
61bcc6
+++ binutils-2.35/bfd/elf.c	2021-04-19 10:50:28.309839285 +0100
61bcc6
@@ -12534,7 +12534,9 @@ _bfd_elf_slurp_secondary_reloc_section (
61bcc6
       Elf_Internal_Shdr * hdr = & elf_section_data (relsec)->this_hdr;
61bcc6
 
61bcc6
       if (hdr->sh_type == SHT_SECONDARY_RELOC
61bcc6
-	  && hdr->sh_info == (unsigned) elf_section_data (sec)->this_idx)
61bcc6
+	  && hdr->sh_info == (unsigned) elf_section_data (sec)->this_idx
61bcc6
+	  && (hdr->sh_entsize == ebd->s->sizeof_rel
61bcc6
+	      || hdr->sh_entsize == ebd->s->sizeof_rela))
61bcc6
 	{
61bcc6
 	  bfd_byte * native_relocs;
61bcc6
 	  bfd_byte * native_reloc;
61bcc6
diff -rup binutils.orig/bfd/elfcode.h binutils-2.35/bfd/elfcode.h
61bcc6
--- binutils.orig/bfd/elfcode.h	2021-04-19 10:49:21.767290922 +0100
61bcc6
+++ binutils-2.35/bfd/elfcode.h	2021-04-19 10:52:22.196066303 +0100
61bcc6
@@ -568,7 +568,7 @@ elf_object_p (bfd *abfd)
61bcc6
 
61bcc6
   /* If this is a relocatable file and there is no section header
61bcc6
      table, then we're hosed.  */
61bcc6
-  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
61bcc6
+  if (i_ehdrp->e_shoff < sizeof (x_ehdr) && i_ehdrp->e_type == ET_REL)
61bcc6
     goto got_wrong_format_error;
61bcc6
 
61bcc6
   /* As a simple sanity check, verify that what BFD thinks is the
61bcc6
@@ -578,7 +578,7 @@ elf_object_p (bfd *abfd)
61bcc6
     goto got_wrong_format_error;
61bcc6
 
61bcc6
   /* Further sanity check.  */
61bcc6
-  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_shnum != 0)
61bcc6
+  if (i_ehdrp->e_shoff < sizeof (x_ehdr) && i_ehdrp->e_shnum != 0)
61bcc6
     goto got_wrong_format_error;
61bcc6
 
61bcc6
   ebd = get_elf_backend_data (abfd);
61bcc6
@@ -615,7 +615,7 @@ elf_object_p (bfd *abfd)
61bcc6
       && ebd->elf_osabi != ELFOSABI_NONE)
61bcc6
     goto got_wrong_format_error;
61bcc6
 
61bcc6
-  if (i_ehdrp->e_shoff != 0)
61bcc6
+  if (i_ehdrp->e_shoff >= sizeof (x_ehdr))
61bcc6
     {
61bcc6
       file_ptr where = (file_ptr) i_ehdrp->e_shoff;
61bcc6
 
61bcc6
@@ -807,7 +807,7 @@ elf_object_p (bfd *abfd)
61bcc6
 	}
61bcc6
     }
61bcc6
 
61bcc6
-  if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff != 0)
61bcc6
+  if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff >= sizeof (x_ehdr))
61bcc6
     {
61bcc6
       unsigned int num_sec;
61bcc6