root/trunk/binutils/binutils-2.16.1-pt_pax-1.patch
| Revision 1182, 12.6 KB (checked in by archaic, 3 years ago) |
|---|
-
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 1281 1281 /* Should the PT_GNU_RELRO segment be emitted? */ 1282 1282 bfd_boolean relro; 1283 1283 1284 /* Segment flags for the PT_PAX_FLAGS segment. */ 1285 unsigned int pax_flags; 1286 1284 1287 /* Symbol version definitions in external objects. */ 1285 1288 Elf_Internal_Verdef *verdef; 1286 1289 -
binutils-2.16
diff -Naur binutils-2.16.orig/bfd/elf.c binutils-2.16/bfd/elf.c
old new 1028 1028 case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break; 1029 1029 case PT_GNU_STACK: pt = "STACK"; break; 1030 1030 case PT_GNU_RELRO: pt = "RELRO"; break; 1031 case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break; 1031 1032 default: sprintf (buf, "0x%lx", p->p_type); pt = buf; break; 1032 1033 } 1033 1034 fprintf (f, "%8s off 0x", pt); … … 2376 2377 case PT_GNU_RELRO: 2377 2378 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro"); 2378 2379 2380 case PT_PAX_FLAGS: 2381 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags"); 2382 2379 2383 default: 2380 2384 /* Check for any processor-specific program segment types. */ 2381 2385 bed = get_elf_backend_data (abfd); … … 3720 3724 pm = &m->next; 3721 3725 } 3722 3726 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 3723 3741 free (sections); 3724 3742 sections = NULL; 3725 3743 … … 4424 4442 ++segs; 4425 4443 } 4426 4444 4445 { 4446 /* We need a PT_PAX_FLAGS segment. */ 4447 ++segs; 4448 } 4449 4427 4450 for (s = abfd->sections; s != NULL; s = s->next) 4428 4451 { 4429 4452 if ((s->flags & SEC_LOAD) != 0 … … 4959 4982 6. PT_TLS segment includes only SHF_TLS sections. 4960 4983 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments. 4961 4984 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 4963 4988 #define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed) \ 4964 4989 ((((segment->p_paddr \ 4965 4990 ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \ … … 4968 4993 || IS_COREFILE_NOTE (segment, section)) \ 4969 4994 && section->output_section != NULL \ 4970 4995 && segment->p_type != PT_GNU_STACK \ 4996 && segment->p_type != PT_PAX_FLAGS \ 4971 4997 && (segment->p_type != PT_TLS \ 4972 4998 || (section->flags & SEC_THREAD_LOCAL)) \ 4973 4999 && (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 4941 4941 if (!is_elf_hash_table (info->hash)) 4942 4942 return TRUE; 4943 4943 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 4944 4951 elf_tdata (output_bfd)->relro = info->relro; 4945 4952 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 } 4947 4957 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 } 4949 4962 else 4950 4963 { 4951 4964 bfd *inputobj; 4952 4965 asection *notesec = NULL; 4953 4966 int exec = 0; 4954 4967 4968 elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP; 4955 4969 for (inputobj = info->input_bfds; 4956 4970 inputobj; 4957 4971 inputobj = inputobj->link_next) … … 4964 4978 if (s) 4965 4979 { 4966 4980 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 } 4968 4986 notesec = s; 4969 4987 } 4970 4988 else -
binutils/readelf.c
diff -Naur binutils-2.16.orig/binutils/readelf.c binutils-2.16/binutils/readelf.c
old new 2330 2330 return "GNU_EH_FRAME"; 2331 2331 case PT_GNU_STACK: return "GNU_STACK"; 2332 2332 case PT_GNU_RELRO: return "GNU_RELRO"; 2333 case PT_PAX_FLAGS: return "PAX_FLAGS"; 2333 2334 2334 2335 default: 2335 2336 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 318 318 flags. */ 319 319 unsigned int noexecstack: 1; 320 320 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 321 329 /* TRUE if PT_GNU_RELRO segment should be created. */ 322 330 unsigned int relro: 1; 323 331 -
include/elf/common.h
diff -Naur binutils-2.16.orig/include/elf/common.h binutils-2.16/include/elf/common.h
old new 293 293 #define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME /* Solaris uses the same value */ 294 294 #define PT_GNU_STACK (PT_LOOS + 0x474e551) /* Stack flags */ 295 295 #define PT_GNU_RELRO (PT_LOOS + 0x474e552) /* Read-only after relocation */ 296 #define PT_PAX_FLAGS (PT_LOOS + 0x5041580) /* PaX flags */ 296 297 297 298 /* Program segment permissions, in program header p_flags field. */ 298 299 299 300 #define PF_X (1 << 0) /* Segment is executable */ 300 301 #define PF_W (1 << 1) /* Segment is writable */ 301 302 #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 302 317 /* #define PF_MASKOS 0x0F000000 *//* OS-specific reserved bits */ 303 318 #define PF_MASKOS 0x0FF00000 /* New value, Oct 4, 1999 Draft */ 304 319 #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 1725 1725 link_info.noexecstack = TRUE; 1726 1726 link_info.execstack = FALSE; 1727 1727 } 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 } 1728 1738 else if (strcmp (optarg, "relro") == 0) 1729 1739 link_info.relro = TRUE; 1730 1740 else if (strcmp (optarg, "norelro") == 0) … … 1765 1775 fprintf (file, _(" -z combreloc\t\tMerge dynamic relocs into one section and sort\n")); 1766 1776 fprintf (file, _(" -z defs\t\tReport unresolved symbols in object files.\n")); 1767 1777 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")); 1768 1779 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); 1769 1780 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); 1770 1781 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n")); … … 1776 1787 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n")); 1777 1788 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n")); 1778 1789 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")); 1779 1791 fprintf (file, _(" -z norelro\t\tDon't create RELRO program header\n")); 1780 1792 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n")); 1781 1793 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 1085 1085 $$ = exp_intop (0x6474e550); 1086 1086 else if (strcmp (s, "PT_GNU_STACK") == 0) 1087 1087 $$ = exp_intop (0x6474e551); 1088 else if (strcmp (s, "PT_PAX_FLAGS") == 0) 1089 $$ = exp_intop (0x65041580); 1088 1090 else 1089 1091 { 1090 1092 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 35 35 36 36 Elf file type is EXEC \(Executable file\) 37 37 Entry point 0x8049178 38 There are 6program headers, starting at offset [0-9]+38 There are 7 program headers, starting at offset [0-9]+ 39 39 40 40 Program Headers: 41 41 Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align … … 46 46 LOAD.* 47 47 DYNAMIC.* 48 48 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 49 50 50 51 Section to Segment mapping: 51 52 Segment Sections... … … 55 56 03 +.tdata .dynamic .got .got.plt * 56 57 04 +.dynamic * 57 58 05 +.tdata .tbss * 59 06 58 60 59 61 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 9 entries: 60 62 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 32 32 33 33 Elf file type is DYN \(Shared object file\) 34 34 Entry point 0x1000 35 There are 4program headers, starting at offset [0-9]+35 There are 5 program headers, starting at offset [0-9]+ 36 36 37 37 Program Headers: 38 38 Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align … … 40 40 LOAD.* 41 41 DYNAMIC.* 42 42 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 43 44 44 45 Section to Segment mapping: 45 46 Segment Sections... … … 47 48 01 +.dynamic .got .got.plt * 48 49 02 +.dynamic * 49 50 03 +.tbss * 51 04 50 52 51 53 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 20 entries: 52 54 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 42 42 LOAD.* 43 43 DYNAMIC.* 44 44 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 45 46 46 47 Section to Segment mapping: 47 48 Segment Sections... … … 49 50 01 +.tdata .dynamic .got .got.plt * 50 51 02 +.dynamic * 51 52 03 +.tdata .tbss * 53 04 52 54 53 55 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 26 entries: 54 56 Offset +Info +Type +Sym.Value +Sym. Name
Note: See TracBrowser
for help on using the browser.
