Blame SOURCES/glibc-rh1440250.patch

147e83
commit 9637d8a253493be471d9a71640e91349f7a8a050
147e83
Author: H.J. Lu <hjl.tools@gmail.com>
147e83
Date:   Wed Jul 29 11:57:54 2015 -0700
147e83
147e83
    Extend local PLT reference check
147e83
147e83
    On x86, linker in binutils 2.26 and newer consolidates R_*_JUMP_SLOT with
147e83
    R_*_GLOB_DAT relocation against the same symbol.  This patch extends
147e83
    local PLT reference check to support alternate relocations.
147e83
147e83
        [BZ #18078]
147e83
        * scripts/check-localplt.awk: Support alternate relocations.
147e83
        * scripts/localplt.awk: Also check relocations in DT_RELA/DT_REL
147e83
        sections.
147e83
        * sysdeps/unix/sysv/linux/i386/localplt.data: Mark free and
147e83
        malloc entries with + REL R_386_GLOB_DAT.
147e83
        * sysdeps/x86_64/localplt.data: New file.
147e83
147e83
147e83
commit da53d6dbc28d2a90d6e14dd661e68611c3b741cf
147e83
Author: Carlos O'Donell <carlos@redhat.com>
147e83
Date:   Thu Nov 6 15:48:44 2014 -0500
147e83
147e83
    Run check-localpltk/textrel/execstack over ld.so.
147e83
147e83
    For maximum paranoia we run ld.so through the normal set
147e83
    of tests for all of the shared libraries. This includes
147e83
    running ld.so through check-localplt, check-textrel, and
147e83
    check-execstack. While none of these should trigger any
147e83
    failures given the way ld.so is built, it might possibly
147e83
    fail if a developer does something wrong. This paranoia
147e83
    was triggered by a discussion over the use of __strcpy
147e83
    vs. strcpy [1] and if the symbol could leak and use the
147e83
    libc.so version.
147e83
147e83
    The check-localplt test fails right away because localplt.data
147e83
    needs updating for all arches. By default we add 6 new symbols:
147e83
    __tls_get_addr, __libc_memalign, malloc, calloc, realloc and
147e83
    free. Other machines like i386, power, and s390 require some
147e83
    different symbol sets e.g. ___tls_get_addr vs. __tls_get_addr
147e83
    for i386.
147e83
147e83
commit d3d9c95aefded7716d037e241f9d23a1cccab45a
147e83
Author: H.J. Lu <hjl.tools@gmail.com>
147e83
Date:   Wed Oct 14 05:59:50 2015 -0700
147e83
147e83
    Support PLT and GOT references in local PIC check
147e83
147e83
commit a0af371c25ac1f215cf0db64e54cbb9a1b51f78c
147e83
Author: Alan Modra <amodra@gmail.com>
147e83
Date:   Fri Feb 20 15:23:28 2015 +1030
147e83
147e83
    Fix localplt test breakage with new readelf
147e83
147e83
    Since 2014-11-24 binutils git commit bb4d2ac2, readelf has appended
147e83
    the symbol version to symbols shown in reloc dumps.
147e83
147e83
        [BZ #16512]
147e83
        * scripts/localplt.awk: Strip off symbol version.
147e83
        * NEWS: Mention bug fix.
147e83
147e83
diff -Nrup a/elf/Makefile b/elf/Makefile
147e83
--- a/elf/Makefile	2017-10-22 09:16:02.451399056 -0400
147e83
+++ b/elf/Makefile	2017-10-22 09:16:39.217285466 -0400
147e83
@@ -915,7 +915,7 @@ $(objpfx)tst-pie1: $(objpfx)tst-piemod1.
147e83
 ifeq (yes,$(build-shared))
147e83
 tests: $(objpfx)check-textrel.out $(objpfx)check-execstack.out
147e83
 
147e83
-all-built-dso := $(common-objpfx)libc.so \
147e83
+all-built-dso := $(common-objpfx)elf/ld.so $(common-objpfx)libc.so \
147e83
 		 $(filter-out $(common-objpfx)linkobj/libc.so, \
147e83
 			      $(sort $(wildcard $(addprefix $(common-objpfx), \
147e83
 							    */lib*.so \
147e83
@@ -974,6 +974,7 @@ tests: $(objpfx)check-localplt.out
147e83
 
147e83
 localplt-built-dso := $(addprefix $(common-objpfx),\
147e83
 				  libc.so \
147e83
+                                  elf/ld.so \
147e83
 				  math/libm.so \
147e83
 				  rt/librt.so \
147e83
 				  dlfcn/libdl.so \
147e83
diff -Nrup a/ports/sysdeps/unix/sysv/linux/aarch64/nptl/localplt.data b/ports/sysdeps/unix/sysv/linux/aarch64/nptl/localplt.data
147e83
--- a/ports/sysdeps/unix/sysv/linux/aarch64/nptl/localplt.data	2017-10-22 09:16:01.379402341 -0400
147e83
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/nptl/localplt.data	2017-10-22 09:16:39.217285466 -0400
147e83
@@ -12,3 +12,15 @@ libm.so: matherr
147e83
 libm.so: __signbit
147e83
 libm.so: __signbitf
147e83
 libm.so: __signbitl
147e83
+# The dynamic loader needs __tls_get_addr for TLS.
147e83
+ld.so: __tls_get_addr
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign + RELA R_X86_64_GLOB_DAT
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc
147e83
+ld.so: calloc
147e83
+ld.so: realloc
147e83
+ld.so: free
147e83
diff -Nrup a/scripts/check-localplt.awk b/scripts/check-localplt.awk
147e83
--- a/scripts/check-localplt.awk	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/scripts/check-localplt.awk	2017-10-22 09:16:39.218285463 -0400
147e83
@@ -3,9 +3,16 @@
147e83
 # Each line is either a comment starting with # or it looks like:
147e83
 #	libfoo.so: function
147e83
 # or
147e83
+#      libfoo.so: function + {RELA|REL} RELOC
147e83
+# or
147e83
 #	libfoo.so: function ?
147e83
 # The latter means that a PLT entry for function is optional in libfoo.so.
147e83
 # The former means one is required.
147e83
+# The first entry means that one is required.
147e83
+# The second entry means that one is required and relocation may also be
147e83
+# {RELA|REL} RELOC.
147e83
+# The third entry means that a PLT entry for function is optional in
147e83
+# libfoo.so.
147e83
 # The second file argument is - and this (stdin) receives the output
147e83
 # of the check-localplt program.
147e83
 
147e83
@@ -14,7 +21,10 @@ BEGIN { result = 0 }
147e83
 FILENAME != "-" && /^#/ { next }
147e83
 
147e83
 FILENAME != "-" {
147e83
-  if (NF != 2 && !(NF == 3 && $3 == "?")) {
147e83
+  if (NF == 5 && $3 == "+" && ($4 == "RELA" || $4 == "REL")) {
147e83
+    accept_type[$1 " " $2] = $4;
147e83
+    accept_reloc[$1 " " $2] = $5;
147e83
+  } else if (NF != 2 && !(NF == 3 && $3 == "?")) {
147e83
     printf "%s:%d: bad data line: %s\n", FILENAME, FNR, $0 > "/dev/stderr";
147e83
     result = 2;
147e83
   } else {
147e83
@@ -23,7 +33,7 @@ FILENAME != "-" {
147e83
   next;
147e83
 }
147e83
 
147e83
-NF != 2 {
147e83
+NF != 2 && !(NF == 4 && ($3 == "RELA" || $3 == "REL")) {
147e83
   print "Unexpected output from check-localplt:", $0 > "/dev/stderr";
147e83
   result = 2;
147e83
   next
147e83
@@ -31,7 +41,23 @@ NF != 2 {
147e83
 
147e83
 {
147e83
   key = $1 " " $2
147e83
-  if (key in accept) {
147e83
+  if ($3 == "RELA" || $3 == "REL") {
147e83
+    # Entries like:
147e83
+    # libc.so: free + RELA R_X86_64_GLOB_DAT
147e83
+    # may be ignored.
147e83
+    if (key in accept_type && accept_type[key] == $3 && accept_reloc[key] == $4) {
147e83
+      # Match
147e83
+      # libc.so: free + RELA R_X86_64_GLOB_DAT
147e83
+      delete accept_type[key]
147e83
+    }
147e83
+  } else if (NF == 2 && key in accept_reloc) {
147e83
+    # Match
147e83
+    # libc.so: free
147e83
+    # against
147e83
+    # libc.so: free + RELA R_X86_64_GLOB_DAT
147e83
+    if (key in accept_type)
147e83
+      delete accept_type[key]
147e83
+  } else if (key in accept) {
147e83
     delete accept[key]
147e83
   } else {
147e83
     print "Extra PLT reference:", $0;
147e83
@@ -49,5 +75,11 @@ END {
147e83
     }
147e83
   }
147e83
 
147e83
+  for (key in accept_type) {
147e83
+    # It's mandatory.
147e83
+    print "Missing required PLT or " accept_reloc[key] " reference:", key;
147e83
+    result = 1;
147e83
+  }
147e83
+
147e83
   exit(result);
147e83
 }
147e83
diff -Nrup a/scripts/localplt.awk b/scripts/localplt.awk
147e83
--- a/scripts/localplt.awk	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/scripts/localplt.awk	2017-10-22 09:16:39.218285463 -0400
147e83
@@ -7,12 +7,14 @@
147e83
 BEGIN { result = 0 }
147e83
 
147e83
 FILENAME != lastfile {
147e83
-  if (lastfile && jmprel_offset == 0) {
147e83
+  if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0) {
147e83
     print FILENAME ": *** failed to find expected output (readelf -WSdr)";
147e83
     result = 2;
147e83
   }
147e83
   lastfile = FILENAME;
147e83
   jmprel_offset = 0;
147e83
+  rela_offset = 0;
147e83
+  rel_offset = 0;
147e83
   delete section_offset_by_address;
147e83
 }
147e83
 
147e83
@@ -32,9 +34,39 @@ $1 == "Offset" && $2 == "Info" { in_relo
147e83
 NF == 0 { in_relocs = 0 }
147e83
 
147e83
 in_relocs && relocs_offset == jmprel_offset && NF >= 5 {
147e83
-  symval = strtonum("0x" $4);
147e83
-  if (symval != 0)
147e83
-    print whatfile, $5
147e83
+  # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
147e83
+  # value, but rather as the resolver symbol followed by ().
147e83
+  if ($4 ~ /\(\)/) {
147e83
+    print whatfile, gensub(/@.*/, "", "g", $5)
147e83
+  } else {
147e83
+    symval = strtonum("0x" $4);
147e83
+    if (symval != 0)
147e83
+      print whatfile, gensub(/@.*/, "", "g", $5)
147e83
+  }
147e83
+}
147e83
+
147e83
+in_relocs && relocs_offset == rela_offset && NF >= 5 {
147e83
+  # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
147e83
+  # value, but rather as the resolver symbol followed by ().
147e83
+  if ($4 ~ /\(\)/) {
147e83
+    print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
147e83
+  } else {
147e83
+    symval = strtonum("0x" $4);
147e83
+    if (symval != 0)
147e83
+      print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
147e83
+  }
147e83
+}
147e83
+
147e83
+in_relocs && relocs_offset == rel_offset && NF >= 5 {
147e83
+  # Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
147e83
+  # value, but rather as the resolver symbol followed by ().
147e83
+  if ($4 ~ /\(\)/) {
147e83
+    print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
147e83
+  } else {
147e83
+    symval = strtonum("0x" $4);
147e83
+    if (symval != 0)
147e83
+      print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
147e83
+  }
147e83
 }
147e83
 
147e83
 in_relocs { next }
147e83
@@ -56,4 +88,25 @@ $2 == "(JMPREL)" {
147e83
   next
147e83
 }
147e83
 
147e83
+$2 == "(RELA)" {
147e83
+  rela_addr = strtonum($3);
147e83
+  if (rela_addr in section_offset_by_address) {
147e83
+    rela_offset = section_offset_by_address[rela_addr];
147e83
+  } else {
147e83
+    print FILENAME ": *** DT_RELA does not match any section's address";
147e83
+    result = 2;
147e83
+  }
147e83
+  next
147e83
+}
147e83
+
147e83
+$2 == "(REL)" {
147e83
+  rel_addr = strtonum($3);
147e83
+  if (rel_addr in section_offset_by_address) {
147e83
+    rel_offset = section_offset_by_address[rel_addr];
147e83
+  } else {
147e83
+    print FILENAME ": *** DT_REL does not match any section's address";
147e83
+    result = 2;
147e83
+  }
147e83
+  next
147e83
+}
147e83
 END { exit(result) }
147e83
diff -Nrup a/sysdeps/generic/localplt.data b/sysdeps/generic/localplt.data
147e83
--- a/sysdeps/generic/localplt.data	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/generic/localplt.data	2017-10-22 09:18:03.383023954 -0400
147e83
@@ -7,3 +7,9 @@ libc.so: malloc
147e83
 libc.so: memalign
147e83
 libc.so: realloc
147e83
 libm.so: matherr
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc
147e83
+ld.so: calloc
147e83
+ld.so: realloc
147e83
+ld.so: free
147e83
diff -Nrup a/sysdeps/unix/sysv/linux/i386/nptl/localplt.data b/sysdeps/unix/sysv/linux/i386/nptl/localplt.data
147e83
--- a/sysdeps/unix/sysv/linux/i386/nptl/localplt.data	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/sysv/linux/i386/nptl/localplt.data	2017-10-22 09:16:39.218285463 -0400
147e83
@@ -1,7 +1,21 @@
147e83
-libc.so: _Unwind_Find_FDE
147e83
-libc.so: calloc
147e83
-libc.so: free
147e83
-libc.so: malloc
147e83
-libc.so: memalign
147e83
-libc.so: realloc
147e83
-libm.so: matherr
147e83
+# Linker in binutils 2.26 and newer consolidates R_X86_64_JUMP_SLOT
147e83
+# relocation with R_386_GLOB_DAT relocation against the same symbol.
147e83
+libc.so: _Unwind_Find_FDE + REL R_386_GLOB_DAT
147e83
+libc.so: calloc + REL R_386_GLOB_DAT
147e83
+libc.so: free + REL R_386_GLOB_DAT
147e83
+libc.so: malloc + REL R_386_GLOB_DAT
147e83
+libc.so: memalign + REL R_386_GLOB_DAT
147e83
+libc.so: realloc + REL R_386_GLOB_DAT
147e83
+libm.so: matherr + REL R_386_GLOB_DAT
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign + REL R_386_GLOB_DAT
147e83
+# The dynamic loader needs __tls_get_addr for TLS.
147e83
+ld.so: ___tls_get_addr + REL R_386_GLOB_DAT
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc + REL R_386_GLOB_DAT
147e83
+ld.so: calloc + REL R_386_GLOB_DAT
147e83
+ld.so: realloc + REL R_386_GLOB_DAT
147e83
+ld.so: free + REL R_386_GLOB_DAT
147e83
diff -Nrup a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/localplt.data
147e83
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/localplt.data	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/localplt.data	2017-10-22 09:16:39.218285463 -0400
147e83
@@ -5,3 +5,13 @@ libc.so: malloc
147e83
 libc.so: memalign
147e83
 libc.so: realloc
147e83
 libm.so: matherr
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc
147e83
+ld.so: calloc
147e83
+ld.so: realloc
147e83
+ld.so: free
147e83
diff -Nrup a/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/localplt.data
147e83
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/localplt.data	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/localplt.data	2017-10-22 09:16:39.218285463 -0400
147e83
@@ -4,3 +4,13 @@ libc.so: malloc
147e83
 libc.so: memalign
147e83
 libc.so: realloc
147e83
 libm.so: matherr
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc
147e83
+ld.so: calloc
147e83
+ld.so: realloc
147e83
+ld.so: free
147e83
diff -Nrup a/sysdeps/unix/sysv/linux/s390/s390-32/nptl/localplt.data b/sysdeps/unix/sysv/linux/s390/s390-32/nptl/localplt.data
147e83
--- a/sysdeps/unix/sysv/linux/s390/s390-32/nptl/localplt.data	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/nptl/localplt.data	2017-10-22 09:16:39.219285460 -0400
147e83
@@ -5,3 +5,13 @@ libc.so: malloc
147e83
 libc.so: memalign
147e83
 libc.so: realloc
147e83
 libm.so: matherr
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc
147e83
+ld.so: calloc
147e83
+ld.so: realloc
147e83
+ld.so: free
147e83
diff -Nrup a/sysdeps/unix/sysv/linux/s390/s390-64/nptl/localplt.data b/sysdeps/unix/sysv/linux/s390/s390-64/nptl/localplt.data
147e83
--- a/sysdeps/unix/sysv/linux/s390/s390-64/nptl/localplt.data	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/nptl/localplt.data	2017-10-22 09:16:39.219285460 -0400
147e83
@@ -5,3 +5,13 @@ libc.so: malloc
147e83
 libc.so: memalign
147e83
 libc.so: realloc
147e83
 libm.so: matherr
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc
147e83
+ld.so: calloc
147e83
+ld.so: realloc
147e83
+ld.so: free
147e83
diff -Nrup a/sysdeps/x86_64/nptl/localplt.data b/sysdeps/x86_64/nptl/localplt.data
147e83
--- a/sysdeps/x86_64/nptl/localplt.data	1969-12-31 19:00:00.000000000 -0500
147e83
+++ b/sysdeps/x86_64/nptl/localplt.data	2017-10-22 09:16:39.219285460 -0400
147e83
@@ -0,0 +1,23 @@
147e83
+# See scripts/check-localplt.awk for how this file is processed.
147e83
+# PLT use is required for the malloc family and for matherr because
147e83
+# users can define their own functions and have library internals call them.
147e83
+# Linker in binutils 2.26 and newer consolidates R_X86_64_JUMP_SLOT
147e83
+# relocation with R_X86_64_GLOB_DAT relocation against the same symbol.
147e83
+libc.so: calloc + RELA R_X86_64_GLOB_DAT
147e83
+libc.so: free + RELA R_X86_64_GLOB_DAT
147e83
+libc.so: malloc + RELA R_X86_64_GLOB_DAT
147e83
+libc.so: memalign + RELA R_X86_64_GLOB_DAT
147e83
+libc.so: realloc + RELA R_X86_64_GLOB_DAT
147e83
+libm.so: matherr + RELA R_X86_64_GLOB_DAT
147e83
+# The dynamic loader uses __libc_memalign internally to allocate aligned
147e83
+# TLS storage. The other malloc family of functions are expected to allow
147e83
+# user symbol interposition.
147e83
+ld.so: __libc_memalign + RELA R_X86_64_GLOB_DAT
147e83
+# The dynamic loader needs __tls_get_addr for TLS.
147e83
+ld.so: __tls_get_addr + RELA R_X86_64_GLOB_DAT
147e83
+# The main malloc is interposed into the dynamic linker, for
147e83
+# allocations after the initial link (when dlopen is used).
147e83
+ld.so: malloc + RELA R_X86_64_GLOB_DAT
147e83
+ld.so: calloc + RELA R_X86_64_GLOB_DAT
147e83
+ld.so: realloc + RELA R_X86_64_GLOB_DAT
147e83
+ld.so: free + RELA R_X86_64_GLOB_DAT