Blame SOURCES/gdb-rhbz1190506-segv-in-ko-ppc64.patch

2c2fa1
commit 80c570537e380c1b8e48754c0ddbce2abcde2d00
2c2fa1
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
2c2fa1
Date:   Thu Feb 26 14:08:01 2015 +0100
2c2fa1
2c2fa1
    SEGV in ppc64_elf_get_synthetic_symtab reading a separate debug file
2c2fa1
    
2c2fa1
    The attached patch fixes the SEGV and lets GDB successfully
2c2fa1
    load all kernel modules installed by default on RHEL 7.
2c2fa1
    
2c2fa1
    Valgrind on F-21 x86_64 host has shown me more clear what is the problem:
2c2fa1
    
2c2fa1
    Reading symbols from /home/jkratoch/t/cordic.ko...Reading symbols from
2c2fa1
    /home/jkratoch/t/cordic.ko.debug...=================================================================
2c2fa1
    ==22763==ERROR: AddressSanitizer: heap-use-after-free on address 0x6120000461c8 at pc 0x150cdbd bp 0x7fffffffc7e0 sp 0x7fffffffc7d0
2c2fa1
    READ of size 8 at 0x6120000461c8 thread T0
2c2fa1
        #0 0x150cdbc in ppc64_elf_get_synthetic_symtab /home/jkratoch/redhat/gdb-test-asan/bfd/elf64-ppc.c:3282
2c2fa1
        #1 0x8c5274 in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1205
2c2fa1
        #2 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
2c2fa1
    [...]
2c2fa1
    0x6120000461c8 is located 264 bytes inside of 288-byte region [0x6120000460c0,0x6120000461e0)
2c2fa1
    freed by thread T0 here:
2c2fa1
        #0 0x7ffff715454f in __interceptor_free (/lib64/libasan.so.1+0x5754f)
2c2fa1
        #1 0xde9cde in xfree common/common-utils.c:98
2c2fa1
        #2 0x9a04f7 in do_my_cleanups common/cleanups.c:155
2c2fa1
        #3 0x9a05d3 in do_cleanups common/cleanups.c:177
2c2fa1
        #4 0x8c538a in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1229
2c2fa1
        #5 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
2c2fa1
    [...]
2c2fa1
    previously allocated by thread T0 here:
2c2fa1
        #0 0x7ffff71547c7 in malloc (/lib64/libasan.so.1+0x577c7)
2c2fa1
        #1 0xde9b95 in xmalloc common/common-utils.c:41
2c2fa1
        #2 0x8c4da2 in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1147
2c2fa1
        #3 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
2c2fa1
    [...]
2c2fa1
    SUMMARY: AddressSanitizer: heap-use-after-free /home/jkratoch/redhat/gdb-test-asan/bfd/elf64-ppc.c:3282 ppc64_elf_get_synthetic_symtab
2c2fa1
    [...]
2c2fa1
    ==22763==ABORTING
2c2fa1
    
2c2fa1
    A similar case a few lines later I have fixed in 2010 by:
2c2fa1
            https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=3f1eff0a2c7f0e7078f011f55b8e7f710aae0cc2
2c2fa1
    
2c2fa1
    My testcase does not always reproduce it but at least a bit:
2c2fa1
     * GDB without ppc64 target (even as a secondary one) is reported as "untested"
2c2fa1
     * ASAN-built GDB with ppc64 target always crashes (and PASSes with this fix)
2c2fa1
     * unpatched non-ASAN-built GDB with ppc64 target crashes from commandline
2c2fa1
     * unpatched non-ASAN-built GDB with ppc64 target PASSes from runtest (?)
2c2fa1
    
2c2fa1
    gdb/ChangeLog
2c2fa1
    2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
2c2fa1
    
2c2fa1
    	* elfread.c (elf_read_minimal_symbols): Use bfd_alloc for
2c2fa1
    	bfd_canonicalize_symtab.
2c2fa1
    
2c2fa1
    gdb/testsuite/ChangeLog
2c2fa1
    2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
2c2fa1
    
2c2fa1
    	* gdb.arch/cordic.ko.bz2: New file.
2c2fa1
    	* gdb.arch/cordic.ko.debug.bz2: New file.
2c2fa1
    	* gdb.arch/ppc64-symtab-cordic.exp: New file.
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/elfread.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/elfread.c
2c2fa1
+++ gdb-7.6.1/gdb/elfread.c
2c2fa1
@@ -2308,8 +2308,10 @@ elf_symfile_read (struct objfile *objfil
2c2fa1
 
2c2fa1
   if (storage_needed > 0)
2c2fa1
     {
2c2fa1
-      symbol_table = (asymbol **) xmalloc (storage_needed);
2c2fa1
-      make_cleanup (xfree, symbol_table);
2c2fa1
+      /* Memory gets permanently referenced from ABFD after
2c2fa1
+	 bfd_canonicalize_symtab so it must not get freed before ABFD gets.  */
2c2fa1
+
2c2fa1
+      symbol_table = bfd_alloc (abfd, storage_needed);
2c2fa1
       symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
2c2fa1
 
2c2fa1
       if (symcount < 0)
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
2c2fa1
@@ -0,0 +1,51 @@
2c2fa1
+# Copyright 2015 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+# This program is free software; you can redistribute it and/or modify
2c2fa1
+# it under the terms of the GNU General Public License as published by
2c2fa1
+# the Free Software Foundation; either version 3 of the License, or
2c2fa1
+# (at your option) any later version.
2c2fa1
+#
2c2fa1
+# This program is distributed in the hope that it will be useful,
2c2fa1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+# GNU General Public License for more details.
2c2fa1
+#
2c2fa1
+# You should have received a copy of the GNU General Public License
2c2fa1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2c2fa1
+
2c2fa1
+standard_testfile
2c2fa1
+
2c2fa1
+set kobz2uufile ${srcdir}/${subdir}/cordic.ko.bz2.uu
2c2fa1
+set kofile ${objdir}/${subdir}/cordic.ko
2c2fa1
+set kodebugbz2uufile ${srcdir}/${subdir}/cordic.ko.debug.bz2.uu
2c2fa1
+set kodebugfile ${objdir}/${subdir}/cordic.ko.debug
2c2fa1
+
2c2fa1
+if {[catch "system \"uudecode -o - ${kobz2uufile} | bzip2 -dc >${kofile}\""] != 0} {
2c2fa1
+    untested "failed bzip2 for ${kobz2uufile}"
2c2fa1
+    return -1
2c2fa1
+}
2c2fa1
+if {[catch "system \"uudecode -o - ${kodebugbz2uufile} | bzip2 -dc >${kodebugfile}\""] != 0} {
2c2fa1
+    untested "failed bzip2 for ${kodebugbz2uufile}"
2c2fa1
+    return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+gdb_exit
2c2fa1
+gdb_start
2c2fa1
+gdb_reinitialize_dir $srcdir/$subdir
2c2fa1
+
2c2fa1
+# This test won't work properly if system debuginfo is installed.
2c2fa1
+# Test message is suppressed by "" as otherwise we could print PASS+UNTESTED
2c2fa1
+# result to gdb.sum making a false feeling the issue has been tested.
2c2fa1
+gdb_test_no_output "set debug-file-directory" ""
2c2fa1
+
2c2fa1
+gdb_load ${kofile}
2c2fa1
+
2c2fa1
+set test "show architecture"
2c2fa1
+gdb_test_multiple $test $test {
2c2fa1
+    -re "\r\nThe target architecture is set automatically \\(currently powerpc:common64\\)\r\n$gdb_prompt $" {
2c2fa1
+	pass $test
2c2fa1
+    }
2c2fa1
+    -re "\r\nThe target architecture is set automatically \\(currently .*\\)\r\n$gdb_prompt $" {
2c2fa1
+	untested "powerpc:common64 is not supported"
2c2fa1
+    }
2c2fa1
+}
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.bz2.uu
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.bz2.uu
2c2fa1
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`CL3%A?;_(NKY1#S-PYZ#Q/58AEZZY4LG'0B(3B$`4$0P0_XNY(IPH2%8
2c2fa1
+#Y"5.
2c2fa1
+`
2c2fa1
+end
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.debug.bz2.uu
2c2fa1
===================================================================
2c2fa1
--- /dev/null
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.debug.bz2.uu
2c2fa1
@@ -0,0 +1,24 @@
2c2fa1
+begin 664 cordic.ko.debug.bz2.uu
2c2fa1
+M0EIH.3%!62936;;3U;4``^=______^==:W]63^U^1+_O_V"H4V#`)$A@F@90
2c2fa1
+M"D$!"""2P`,!Q0-*1AHB-4])ZGI-#3U`T:8C0``-``-`:-#0`:#T@!IH-&@-
2c2fa1
+M!HA$\D](])E)Z(V@)A#30TT,1@`C-`)@(!H8"8!,--!!@``````````$P```
2c2fa1
+M`$8``F``2)$FF@FDVIZGJ>BFF1A-/-)HVJ'J8`#U3,H:#"-D@'H:@8CT&("]
2c2fa1
+M???6F=%1'FNGCPP"I4HL6ZE@2>=E(>L$@&5?>9ZJAI%`&%I2P2MAW226F58=
2c2fa1
+M!Z[0:D$@C,S$%$*-\ZZF[U##1Q9M=6V$MAXS#$,A5@8IA,-^8#:S#*JAEJUA
2c2fa1
+M.ZJWN+EH.Z>`5$02]B/^B\^*GMP%%$,#,BH!`%2&""YD(Z$``3/9]@Y;'/LR
2c2fa1
+M6_C%]&YT&1HR5[H(&VQ`9U[/&/_IX]&CA3,4BW\%WK:>,KF?AA?;I0M)HJHA
2c2fa1
+M))0E$!$-PFTDHB!1$`@;;*T0".1!";2&QM!L,.,TDA*LQ:G*A?T5HS.EQQ-^
2c2fa1
+MXX9F.PV"$H]V,TTRF$T%@NHPIQ2[]T6@8*!#(2$CYW1@8Y(S,WQ[.UM[GKY.
2c2fa1
+M"Y^V=].A
2c2fa1
+MLR"24H($(R60S'.$.0^K9F@,AZ&K`@I92T5.3:4H@=-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