root/trunk/binutils/binutils-2.16.1-pt_pax-1.patch

Revision 1182, 12.6 KB (checked in by archaic, 3 years ago)

Round 2 of hlfs patches reorganization.

  • bfd/elf-bfd.h

    Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
    Date: 2005-05-19
    Initial Package Version: binutils-2.16
    Upstream Status: Not submitted - PaX specific; will not be accepted upstream.
    Origin:	http://pax.grsecurity.net/\
    	binutils-2.15.92.0.2-pt-pax-flags-200411061615.patch
    Description: This is needed for Grsec. http://www.grsecurity.net/
    Also see:
    http://pax.grsecurity.net/
    http://www.linuxfromscratch.org/hlfs/
    
    diff -Naur binutils-2.16.orig/bfd/elf-bfd.h binutils-2.16/bfd/elf-bfd.h
    old new  
    12811281  /* Should the PT_GNU_RELRO segment be emitted?  */ 
    12821282  bfd_boolean relro; 
    12831283 
     1284  /* Segment flags for the PT_PAX_FLAGS segment.  */ 
     1285  unsigned int pax_flags; 
     1286 
    12841287  /* Symbol version definitions in external objects.  */ 
    12851288  Elf_Internal_Verdef *verdef; 
    12861289 
  • binutils-2.16

    diff -Naur binutils-2.16.orig/bfd/elf.c binutils-2.16/bfd/elf.c
    old new  
    10281028            case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break; 
    10291029            case PT_GNU_STACK: pt = "STACK"; break; 
    10301030            case PT_GNU_RELRO: pt = "RELRO"; break; 
     1031            case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break; 
    10311032            default: sprintf (buf, "0x%lx", p->p_type); pt = buf; break; 
    10321033            } 
    10331034          fprintf (f, "%8s off    0x", pt); 
     
    23762377    case PT_GNU_RELRO: 
    23772378      return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro"); 
    23782379 
     2380    case PT_PAX_FLAGS: 
     2381      return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags"); 
     2382 
    23792383    default: 
    23802384      /* Check for any processor-specific program segment types.  */ 
    23812385      bed = get_elf_backend_data (abfd); 
     
    37203724      pm = &m->next; 
    37213725    } 
    37223726 
     3727    { 
     3728      amt = sizeof (struct elf_segment_map); 
     3729      m = bfd_zalloc (abfd, amt); 
     3730      if (m == NULL) 
     3731        goto error_return; 
     3732      m->next = NULL; 
     3733      m->p_type = PT_PAX_FLAGS; 
     3734      m->p_flags = elf_tdata (abfd)->pax_flags; 
     3735      m->p_flags_valid = 1; 
     3736 
     3737      *pm = m; 
     3738      pm = &m->next; 
     3739    } 
     3740 
    37233741  free (sections); 
    37243742  sections = NULL; 
    37253743 
     
    44244442      ++segs; 
    44254443    } 
    44264444 
     4445    { 
     4446      /* We need a PT_PAX_FLAGS segment.  */ 
     4447      ++segs; 
     4448    } 
     4449 
    44274450  for (s = abfd->sections; s != NULL; s = s->next) 
    44284451    { 
    44294452      if ((s->flags & SEC_LOAD) != 0 
     
    49594982       6. PT_TLS segment includes only SHF_TLS sections. 
    49604983       7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments. 
    49614984       8. PT_DYNAMIC should not contain empty sections at the beginning 
    4962           (with the possible exception of .dynamic).  */ 
     4985          (with the possible exception of .dynamic). 
     4986       9. PT_PAX_FLAGS segments do not include any sections. */ 
     4987 
    49634988#define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed)               \ 
    49644989  ((((segment->p_paddr                                                  \ 
    49654990      ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)        \ 
     
    49684993    || IS_COREFILE_NOTE (segment, section))                             \ 
    49694994   && section->output_section != NULL                                   \ 
    49704995   && segment->p_type != PT_GNU_STACK                                   \ 
     4996   && segment->p_type != PT_PAX_FLAGS                                   \ 
    49714997   && (segment->p_type != PT_TLS                                        \ 
    49724998       || (section->flags & SEC_THREAD_LOCAL))                          \ 
    49734999   && (segment->p_type == PT_LOAD                                       \ 
  • bfd/elflink.c

    diff -Naur binutils-2.16.orig/bfd/elflink.c binutils-2.16/bfd/elflink.c
    old new  
    49414941  if (!is_elf_hash_table (info->hash)) 
    49424942    return TRUE; 
    49434943 
     4944  elf_tdata (output_bfd)->pax_flags = PF_NORANDEXEC; 
     4945 
     4946  if (info->execheap) 
     4947    elf_tdata (output_bfd)->pax_flags |= PF_NOMPROTECT; 
     4948  else if (info->noexecheap) 
     4949    elf_tdata (output_bfd)->pax_flags |= PF_MPROTECT; 
     4950 
    49444951  elf_tdata (output_bfd)->relro = info->relro; 
    49454952  if (info->execstack) 
    4946     elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X; 
     4953    { 
     4954      elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X; 
     4955      elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP; 
     4956    } 
    49474957  else if (info->noexecstack) 
    4948     elf_tdata (output_bfd)->stack_flags = PF_R | PF_W; 
     4958    { 
     4959      elf_tdata (output_bfd)->stack_flags = PF_R | PF_W; 
     4960      elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP; 
     4961    } 
    49494962  else 
    49504963    { 
    49514964      bfd *inputobj; 
    49524965      asection *notesec = NULL; 
    49534966      int exec = 0; 
    49544967 
     4968      elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP; 
    49554969      for (inputobj = info->input_bfds; 
    49564970           inputobj; 
    49574971           inputobj = inputobj->link_next) 
     
    49644978          if (s) 
    49654979            { 
    49664980              if (s->flags & SEC_CODE) 
    4967                 exec = PF_X; 
     4981                { 
     4982                  elf_tdata (output_bfd)->pax_flags &= ~PF_NOEMUTRAMP; 
     4983                  elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP; 
     4984                  exec = PF_X; 
     4985                } 
    49684986              notesec = s; 
    49694987            } 
    49704988          else 
  • binutils/readelf.c

    diff -Naur binutils-2.16.orig/binutils/readelf.c binutils-2.16/binutils/readelf.c
    old new  
    23302330                        return "GNU_EH_FRAME"; 
    23312331    case PT_GNU_STACK:  return "GNU_STACK"; 
    23322332    case PT_GNU_RELRO:  return "GNU_RELRO"; 
     2333    case PT_PAX_FLAGS:  return "PAX_FLAGS"; 
    23332334 
    23342335    default: 
    23352336      if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) 
  • include/bfdlink.h

    diff -Naur binutils-2.16.orig/include/bfdlink.h binutils-2.16/include/bfdlink.h
    old new  
    318318     flags.  */ 
    319319  unsigned int noexecstack: 1; 
    320320 
     321  /* TRUE if PT_PAX_FLAGS segment should be created with PF_NOMPROTECT 
     322     flags.  */ 
     323  unsigned int execheap: 1; 
     324 
     325  /* TRUE if PT_PAX_FLAGS segment should be created with PF_MPROTECT 
     326     flags.  */ 
     327  unsigned int noexecheap: 1; 
     328 
    321329  /* TRUE if PT_GNU_RELRO segment should be created.  */ 
    322330  unsigned int relro: 1; 
    323331 
  • include/elf/common.h

    diff -Naur binutils-2.16.orig/include/elf/common.h binutils-2.16/include/elf/common.h
    old new  
    293293#define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME      /* Solaris uses the same value */ 
    294294#define PT_GNU_STACK    (PT_LOOS + 0x474e551) /* Stack flags */ 
    295295#define PT_GNU_RELRO    (PT_LOOS + 0x474e552) /* Read-only after relocation */ 
     296#define PT_PAX_FLAGS    (PT_LOOS + 0x5041580) /* PaX flags */ 
    296297 
    297298/* Program segment permissions, in program header p_flags field.  */ 
    298299 
    299300#define PF_X            (1 << 0)        /* Segment is executable */ 
    300301#define PF_W            (1 << 1)        /* Segment is writable */ 
    301302#define PF_R            (1 << 2)        /* Segment is readable */ 
     303 
     304#define PF_PAGEEXEC     (1 << 4)        /* Enable  PAGEEXEC */ 
     305#define PF_NOPAGEEXEC   (1 << 5)        /* Disable PAGEEXEC */ 
     306#define PF_SEGMEXEC     (1 << 6)        /* Enable  SEGMEXEC */ 
     307#define PF_NOSEGMEXEC   (1 << 7)        /* Disable SEGMEXEC */ 
     308#define PF_MPROTECT     (1 << 8)        /* Enable  MPROTECT */ 
     309#define PF_NOMPROTECT   (1 << 9)        /* Disable MPROTECT */ 
     310#define PF_RANDEXEC     (1 << 10)       /* Enable  RANDEXEC */ 
     311#define PF_NORANDEXEC   (1 << 11)       /* Disable RANDEXEC */ 
     312#define PF_EMUTRAMP     (1 << 12)       /* Enable  EMUTRAMP */ 
     313#define PF_NOEMUTRAMP   (1 << 13)       /* Disable EMUTRAMP */ 
     314#define PF_RANDMMAP     (1 << 14)       /* Enable  RANDMMAP */ 
     315#define PF_NORANDMMAP   (1 << 15)       /* Disable RANDMMAP */ 
     316 
    302317/* #define PF_MASKOS    0x0F000000    *//* OS-specific reserved bits */ 
    303318#define PF_MASKOS       0x0FF00000      /* New value, Oct 4, 1999 Draft */ 
    304319#define PF_MASKPROC     0xF0000000      /* Processor-specific reserved bits */ 
  • ld/emultempl/elf32.em

    diff -Naur binutils-2.16.orig/ld/emultempl/elf32.em binutils-2.16/ld/emultempl/elf32.em
    old new  
    17251725          link_info.noexecstack = TRUE; 
    17261726          link_info.execstack = FALSE; 
    17271727        } 
     1728       else if (strcmp (optarg, "execheap") == 0) 
     1729        { 
     1730          link_info.execheap = TRUE; 
     1731          link_info.noexecheap = FALSE; 
     1732        } 
     1733      else if (strcmp (optarg, "noexecheap") == 0) 
     1734        { 
     1735          link_info.noexecheap = TRUE; 
     1736          link_info.execheap = FALSE; 
     1737        } 
    17281738      else if (strcmp (optarg, "relro") == 0) 
    17291739        link_info.relro = TRUE; 
    17301740      else if (strcmp (optarg, "norelro") == 0) 
     
    17651775  fprintf (file, _("  -z combreloc\t\tMerge dynamic relocs into one section and sort\n")); 
    17661776  fprintf (file, _("  -z defs\t\tReport unresolved symbols in object files.\n")); 
    17671777  fprintf (file, _("  -z execstack\t\tMark executable as requiring executable stack\n")); 
     1778  fprintf (file, _("  -z execheap\t\tMark executable as requiring executable heap\n")); 
    17681779  fprintf (file, _("  -z initfirst\t\tMark DSO to be initialized first at runtime\n")); 
    17691780  fprintf (file, _("  -z interpose\t\tMark object to interpose all DSOs but executable\n")); 
    17701781  fprintf (file, _("  -z loadfltr\t\tMark object requiring immediate process\n")); 
     
    17761787  fprintf (file, _("  -z nodlopen\t\tMark DSO not available to dlopen\n")); 
    17771788  fprintf (file, _("  -z nodump\t\tMark DSO not available to dldump\n")); 
    17781789  fprintf (file, _("  -z noexecstack\tMark executable as not requiring executable stack\n")); 
     1790  fprintf (file, _("  -z noexecheap\tMark executable as not requiring executable heap\n")); 
    17791791  fprintf (file, _("  -z norelro\t\tDon't create RELRO program header\n")); 
    17801792  fprintf (file, _("  -z now\t\tMark object non-lazy runtime binding\n")); 
    17811793  fprintf (file, _("  -z origin\t\tMark object requiring immediate \$ORIGIN processing\n\t\t\t  at runtime\n")); 
  • binutils-2.16

    diff -Naur binutils-2.16.orig/ld/ldgram.y binutils-2.16/ld/ldgram.y
    old new  
    10851085                            $$ = exp_intop (0x6474e550); 
    10861086                          else if (strcmp (s, "PT_GNU_STACK") == 0) 
    10871087                            $$ = exp_intop (0x6474e551); 
     1088                          else if (strcmp (s, "PT_PAX_FLAGS") == 0) 
     1089                            $$ = exp_intop (0x65041580); 
    10881090                          else 
    10891091                            { 
    10901092                              einfo (_("\ 
  • ld/testsuite/ld-i386/tlsbin.rd

    diff -Naur binutils-2.16.orig/ld/testsuite/ld-i386/tlsbin.rd binutils-2.16/ld/testsuite/ld-i386/tlsbin.rd
    old new  
    3535 
    3636Elf file type is EXEC \(Executable file\) 
    3737Entry point 0x8049178 
    38 There are 6 program headers, starting at offset [0-9]+ 
     38There are 7 program headers, starting at offset [0-9]+ 
    3939 
    4040Program Headers: 
    4141  Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align 
     
    4646  LOAD.* 
    4747  DYNAMIC.* 
    4848  TLS +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x0+60 0x0+a0 R +0x1000 
     49  PAX_FLAGS      0x000000 0x00000000 0x00000000 0x00000 0x00000     0x4 
    4950 
    5051 Section to Segment mapping: 
    5152  Segment Sections... 
     
    5556   03 +.tdata .dynamic .got .got.plt * 
    5657   04 +.dynamic * 
    5758   05 +.tdata .tbss * 
     59   06      
    5860 
    5961Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 9 entries: 
    6062 Offset +Info +Type +Sym.Value +Sym. Name 
  • ld/testsuite/ld-i386/tlsnopic.rd

    diff -Naur binutils-2.16.orig/ld/testsuite/ld-i386/tlsnopic.rd binutils-2.16/ld/testsuite/ld-i386/tlsnopic.rd
    old new  
    3232 
    3333Elf file type is DYN \(Shared object file\) 
    3434Entry point 0x1000 
    35 There are 4 program headers, starting at offset [0-9]+ 
     35There are 5 program headers, starting at offset [0-9]+ 
    3636 
    3737Program Headers: 
    3838  Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align 
     
    4040  LOAD.* 
    4141  DYNAMIC.* 
    4242  TLS +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x0+ 0x0+24 R +0x1 
     43  PAX_FLAGS      0x000000 0x00000000 0x00000000 0x00000 0x00000     0x4 
    4344 
    4445 Section to Segment mapping: 
    4546  Segment Sections... 
     
    4748   01 +.dynamic .got .got.plt * 
    4849   02 +.dynamic * 
    4950   03 +.tbss * 
     51   04      
    5052 
    5153Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 20 entries: 
    5254 Offset +Info +Type +Sym.Value +Sym. Name 
  • ld/testsuite/ld-i386/tlspic.rd

    diff -Naur binutils-2.16.orig/ld/testsuite/ld-i386/tlspic.rd binutils-2.16/ld/testsuite/ld-i386/tlspic.rd
    old new  
    4242  LOAD.* 
    4343  DYNAMIC.* 
    4444  TLS +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x0+60 0x0+80 R +0x1 
     45  PAX_FLAGS      0x000000 0x00000000 0x00000000 0x00000 0x00000     0x4 
    4546 
    4647 Section to Segment mapping: 
    4748  Segment Sections... 
     
    4950   01 +.tdata .dynamic .got .got.plt * 
    5051   02 +.dynamic * 
    5152   03 +.tdata .tbss * 
     53   04      
    5254 
    5355Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 26 entries: 
    5456 Offset +Info +Type +Sym.Value +Sym. Name 
Note: See TracBrowser for help on using the browser.