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

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