From af382177a323f1f4a8703d5567a67e7b4a7cdcf6 Mon Sep 17 00:00:00 2001 From: liqingqing_1229 Date: Mon, 25 Oct 2021 16:54:09 +0800 Subject: [PATCH] fix mtrace output and valgrind check failed for tunables_strdup. -mtrace fix output with PIE and ASLR. -elf: rtld copy terminating null in tunables strdup. (cherry picked from commit 88a66f7a0c88f2b58ab82a670ff1d671c5cbfb68) --- glibc.spec | 8 +- ...ix-output-with-PIE-and-ASLR-BZ-22716.patch | 77 +++++++++++++++++++ ...ating-null-in-tunables_strdup-bug-28.patch | 28 +++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 mtrace-Fix-output-with-PIE-and-ASLR-BZ-22716.patch create mode 100644 rtld-copy-terminating-null-in-tunables_strdup-bug-28.patch diff --git a/glibc.spec b/glibc.spec index 7919f7f..edc7cc4 100644 --- a/glibc.spec +++ b/glibc.spec @@ -63,7 +63,7 @@ ############################################################################## Name: glibc Version: 2.34 -Release: 13 +Release: 14 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -112,6 +112,8 @@ Patch27: x86_64-Simplify-elf_machine_-load_address-dynamic.patch Patch28: x86-fix-Autoconf-caching-of-instruction-support-chec.patch Patch29: Update-string-test-memmove.c-to-cover-16KB-copy.patch Patch30: x86-64-Optimize-load-of-all-bits-set-into-ZMM-regist.patch +Patch31: mtrace-Fix-output-with-PIE-and-ASLR-BZ-22716.patch +Patch32: rtld-copy-terminating-null-in-tunables_strdup-bug-28.patch #Patch9000: turn-REP_STOSB_THRESHOLD-from-2k-to-1M.patch Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch @@ -1272,6 +1274,10 @@ fi %doc hesiod/README.hesiod %changelog +* Mon Oct 25 2021 Qingqing Li - 2.34-14 +- mtrace fix output with PIE and ASLR. +- elf: rtld copy terminating null in tunables strdup. + * Mon Oct 25 2021 Qingqing Li - 2.34-13 - fpu: x86-64 optimize load of all bits set into ZMM register. diff --git a/mtrace-Fix-output-with-PIE-and-ASLR-BZ-22716.patch b/mtrace-Fix-output-with-PIE-and-ASLR-BZ-22716.patch new file mode 100644 index 0000000..10622da --- /dev/null +++ b/mtrace-Fix-output-with-PIE-and-ASLR-BZ-22716.patch @@ -0,0 +1,77 @@ +From f2e33c3268db9adf8e57e991676ed0d5ac74e8a8 Mon Sep 17 00:00:00 2001 +From: Siddhesh Poyarekar +Date: Mon, 23 Aug 2021 08:11:54 +0530 +Subject: [PATCH] mtrace: Fix output with PIE and ASLR [BZ #22716] + +Record only the relative address of the caller in mtrace file. Use +LD_TRACE_PRELINKING to get the executable as well as binary vs +executable load offsets so that we may compute a base to add to the +relative address in the mtrace file. This allows us to get a valid +address to pass to addr2line in all cases. + +Fixes BZ #22716. + +Co-authored-by: John Ogness +Reviewed-by: Andreas Schwab +Reviewed-by: DJ Delorie +--- + malloc/mtrace-impl.c | 6 +++--- + malloc/mtrace.pl | 15 +++++++-------- + 2 files changed, 10 insertions(+), 11 deletions(-) + +diff --git a/malloc/mtrace-impl.c b/malloc/mtrace-impl.c +index 83008ca..f5f19c2 100644 +--- a/malloc/mtrace-impl.c ++++ b/malloc/mtrace-impl.c +@@ -65,9 +65,9 @@ tr_where (const void *caller, Dl_info *info) + offset); + } + +- fprintf (mallstream, "@ %s%s%s[%p] ", info->dli_fname ? : "", +- info->dli_fname ? ":" : "", +- buf, caller); ++ fprintf (mallstream, "@ %s%s%s[0x%" PRIxPTR "] ", ++ info->dli_fname ? : "", info->dli_fname ? ":" : "", buf, ++ caller - info->dli_fbase); + } + else + fprintf (mallstream, "@ [%p] ", caller); +diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl +index 6f49c83..b1073a1 100644 +--- a/malloc/mtrace.pl ++++ b/malloc/mtrace.pl +@@ -75,11 +75,15 @@ if ($#ARGV == 0) { + } else { + $prog = "./$binary"; + } +- if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) { ++ # Set the environment variable LD_TRACE_PRELINKING to an empty string so ++ # that we trigger tracing but do not match with the executable or any of ++ # its dependencies. ++ if (open (LOCS, "env LD_TRACE_PRELINKING= $prog |")) { + while () { + chop; +- if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { ++ if (/^.*=> (.*) \((0x[0123456789abcdef]*), (0x[0123456789abcdef]*).*/) { + $locs{$1} = $2; ++ $rel{$1} = hex($2) - hex($3); + } + } + close (LOCS); +@@ -110,12 +114,7 @@ sub location { + my $addr = $2; + my $searchaddr; + return $cache{$addr} if (exists $cache{$addr}); +- if ($locs{$prog} ne "") { +- $searchaddr = sprintf "%#x", $addr - $locs{$prog}; +- } else { +- $searchaddr = $addr; +- $prog = $binary; +- } ++ $searchaddr = sprintf "%#x", hex($addr) + $rel{$prog}; + if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) { + my $line = ; + chomp $line; +-- +1.8.3.1 + diff --git a/rtld-copy-terminating-null-in-tunables_strdup-bug-28.patch b/rtld-copy-terminating-null-in-tunables_strdup-bug-28.patch new file mode 100644 index 0000000..6f73106 --- /dev/null +++ b/rtld-copy-terminating-null-in-tunables_strdup-bug-28.patch @@ -0,0 +1,28 @@ +From a4f5a3103fc3e7974dbe35b411cba9f670807cde Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Mon, 23 Aug 2021 10:19:52 +0200 +Subject: [PATCH] rtld: copy terminating null in tunables_strdup (bug 28256) + +Avoid triggering a false positive from valgrind by copying the terminating +null in tunables_strdup. At this point the heap is still clean, but +valgrind is stricter here. +--- + elf/dl-tunables.c | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c +index 8009e54..1666736 100644 +--- a/elf/dl-tunables.c ++++ b/elf/dl-tunables.c +@@ -56,8 +56,6 @@ tunables_strdup (const char *in) + if (out == (void *)-1) + _dl_fatal_printf ("sbrk() failure while processing tunables\n"); + +- i--; +- + while (i-- > 0) + out[i] = in[i]; + +-- +1.8.3.1 + -- Gitee