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

7b26da
commit 80c570537e380c1b8e48754c0ddbce2abcde2d00
7b26da
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
7b26da
Date:   Thu Feb 26 14:08:01 2015 +0100
7b26da
7b26da
    SEGV in ppc64_elf_get_synthetic_symtab reading a separate debug file
7b26da
    
7b26da
    The attached patch fixes the SEGV and lets GDB successfully
7b26da
    load all kernel modules installed by default on RHEL 7.
7b26da
    
7b26da
    Valgrind on F-21 x86_64 host has shown me more clear what is the problem:
7b26da
    
7b26da
    Reading symbols from /home/jkratoch/t/cordic.ko...Reading symbols from
7b26da
    /home/jkratoch/t/cordic.ko.debug...=================================================================
7b26da
    ==22763==ERROR: AddressSanitizer: heap-use-after-free on address 0x6120000461c8 at pc 0x150cdbd bp 0x7fffffffc7e0 sp 0x7fffffffc7d0
7b26da
    READ of size 8 at 0x6120000461c8 thread T0
7b26da
        #0 0x150cdbc in ppc64_elf_get_synthetic_symtab /home/jkratoch/redhat/gdb-test-asan/bfd/elf64-ppc.c:3282
7b26da
        #1 0x8c5274 in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1205
7b26da
        #2 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
7b26da
    [...]
7b26da
    0x6120000461c8 is located 264 bytes inside of 288-byte region [0x6120000460c0,0x6120000461e0)
7b26da
    freed by thread T0 here:
7b26da
        #0 0x7ffff715454f in __interceptor_free (/lib64/libasan.so.1+0x5754f)
7b26da
        #1 0xde9cde in xfree common/common-utils.c:98
7b26da
        #2 0x9a04f7 in do_my_cleanups common/cleanups.c:155
7b26da
        #3 0x9a05d3 in do_cleanups common/cleanups.c:177
7b26da
        #4 0x8c538a in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1229
7b26da
        #5 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
7b26da
    [...]
7b26da
    previously allocated by thread T0 here:
7b26da
        #0 0x7ffff71547c7 in malloc (/lib64/libasan.so.1+0x577c7)
7b26da
        #1 0xde9b95 in xmalloc common/common-utils.c:41
7b26da
        #2 0x8c4da2 in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1147
7b26da
        #3 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
7b26da
    [...]
7b26da
    SUMMARY: AddressSanitizer: heap-use-after-free /home/jkratoch/redhat/gdb-test-asan/bfd/elf64-ppc.c:3282 ppc64_elf_get_synthetic_symtab
7b26da
    [...]
7b26da
    ==22763==ABORTING
7b26da
    
7b26da
    A similar case a few lines later I have fixed in 2010 by:
7b26da
            https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=3f1eff0a2c7f0e7078f011f55b8e7f710aae0cc2
7b26da
    
7b26da
    My testcase does not always reproduce it but at least a bit:
7b26da
     * GDB without ppc64 target (even as a secondary one) is reported as "untested"
7b26da
     * ASAN-built GDB with ppc64 target always crashes (and PASSes with this fix)
7b26da
     * unpatched non-ASAN-built GDB with ppc64 target crashes from commandline
7b26da
     * unpatched non-ASAN-built GDB with ppc64 target PASSes from runtest (?)
7b26da
    
7b26da
    gdb/ChangeLog
7b26da
    2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
7b26da
    
7b26da
    	* elfread.c (elf_read_minimal_symbols): Use bfd_alloc for
7b26da
    	bfd_canonicalize_symtab.
7b26da
    
7b26da
    gdb/testsuite/ChangeLog
7b26da
    2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
7b26da
    
7b26da
    	* gdb.arch/cordic.ko.bz2: New file.
7b26da
    	* gdb.arch/cordic.ko.debug.bz2: New file.
7b26da
    	* gdb.arch/ppc64-symtab-cordic.exp: New file.
7b26da
7b26da
Index: gdb-7.6.1/gdb/elfread.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/elfread.c
7b26da
+++ gdb-7.6.1/gdb/elfread.c
7b26da
@@ -2308,8 +2308,10 @@ elf_symfile_read (struct objfile *objfil
7b26da
 
7b26da
   if (storage_needed > 0)
7b26da
     {
7b26da
-      symbol_table = (asymbol **) xmalloc (storage_needed);
7b26da
-      make_cleanup (xfree, symbol_table);
7b26da
+      /* Memory gets permanently referenced from ABFD after
7b26da
+	 bfd_canonicalize_symtab so it must not get freed before ABFD gets.  */
7b26da
+
7b26da
+      symbol_table = bfd_alloc (abfd, storage_needed);
7b26da
       symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
7b26da
 
7b26da
       if (symcount < 0)
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
7b26da
@@ -0,0 +1,51 @@
7b26da
+# Copyright 2015 Free Software Foundation, Inc.
7b26da
+
7b26da
+# This program is free software; you can redistribute it and/or modify
7b26da
+# it under the terms of the GNU General Public License as published by
7b26da
+# the Free Software Foundation; either version 3 of the License, or
7b26da
+# (at your option) any later version.
7b26da
+#
7b26da
+# This program is distributed in the hope that it will be useful,
7b26da
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7b26da
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b26da
+# GNU General Public License for more details.
7b26da
+#
7b26da
+# You should have received a copy of the GNU General Public License
7b26da
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7b26da
+
7b26da
+standard_testfile
7b26da
+
7b26da
+set kobz2uufile ${srcdir}/${subdir}/cordic.ko.bz2.uu
7b26da
+set kofile ${objdir}/${subdir}/cordic.ko
7b26da
+set kodebugbz2uufile ${srcdir}/${subdir}/cordic.ko.debug.bz2.uu
7b26da
+set kodebugfile ${objdir}/${subdir}/cordic.ko.debug
7b26da
+
7b26da
+if {[catch "system \"uudecode -o - ${kobz2uufile} | bzip2 -dc >${kofile}\""] != 0} {
7b26da
+    untested "failed bzip2 for ${kobz2uufile}"
7b26da
+    return -1
7b26da
+}
7b26da
+if {[catch "system \"uudecode -o - ${kodebugbz2uufile} | bzip2 -dc >${kodebugfile}\""] != 0} {
7b26da
+    untested "failed bzip2 for ${kodebugbz2uufile}"
7b26da
+    return -1
7b26da
+}
7b26da
+
7b26da
+gdb_exit
7b26da
+gdb_start
7b26da
+gdb_reinitialize_dir $srcdir/$subdir
7b26da
+
7b26da
+# This test won't work properly if system debuginfo is installed.
7b26da
+# Test message is suppressed by "" as otherwise we could print PASS+UNTESTED
7b26da
+# result to gdb.sum making a false feeling the issue has been tested.
7b26da
+gdb_test_no_output "set debug-file-directory" ""
7b26da
+
7b26da
+gdb_load ${kofile}
7b26da
+
7b26da
+set test "show architecture"
7b26da
+gdb_test_multiple $test $test {
7b26da
+    -re "\r\nThe target architecture is set automatically \\(currently powerpc:common64\\)\r\n$gdb_prompt $" {
7b26da
+	pass $test
7b26da
+    }
7b26da
+    -re "\r\nThe target architecture is set automatically \\(currently .*\\)\r\n$gdb_prompt $" {
7b26da
+	untested "powerpc:common64 is not supported"
7b26da
+    }
7b26da
+}
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.bz2.uu
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.bz2.uu
7b26da
@@ -0,0 +1,53 @@
7b26da
+begin 664 cordic.ko.bz2.uu
7b26da
+M0EIH.3%!62936:QR$J<`!:7____________^___________]__O_U__]_N]]
7b26da
+M__?W__Z[T`88O`VP73FU<
7b26da
+MT`#(!M31B`!H:-J#30R!B&3T@:`TT:#)H::`#$]0T:-&F@Q#3"#330BC14]/
7b26da
+M1&IZ::F:GHGZD-'H-JC":8]0GZD]0&0T\IIZFF)IZ3)Z9(,`C33"`#:@`/4`
7b26da
+M#U-&(TR,`C(8AB-,0&C$TTT`-#U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%PAH1,B+EFDI
7b26da
+M!,)F/LQ1>WRLFH;:IH<2$*#V)$9#%O.HL&6)@RP)U[0)RL9S4(0;B)T#H5"X
7b26da
+M&Z`6P3@'37WRBX^=+*>0?3)D!K;W>WTTBC,"$.MX6MVUWV)^U1P?[LI/6A$8
7b26da
+M#^333)CO]9Z/55B?/R5TR?-./&C+(&A[):L7T-MT:"JPH.M@Z)$TTB$NC^Z1
7b26da
+M$FHE%T(C1-:Y93\]R_U&6A-O.3_)/0K&;LK]9Z%>?Q>4_L&TM>J:2S3BFC/>
7b26da
+MN^\3B,#
7b26da
+MZ-F1!4;VZ*,I9R]E_G.KW;'I]'V58XOT$]I3K#6/S!8NT#`R($`[HXM(SI'G
7b26da
+M-VR6DNW`-506)H:YC&P$2IW-,_-JO^N-]0X[,*V2WP_LXN#R8#C@`#C@YSN2
7b26da
+M!9&`Y*AH4IGB:&=NNOQL5/M+M0V.QH62$W-+B1HD(9$=`BV@*IKV[Q`U/A0>
7b26da
+MA6QOQMY*]TJV12V[4+J+-P=Q?/MV=Q2Y%@*"\<12OVLPHS(E+340BRPFZI/$
7b26da
+M,;[5&:J8,\D"&@9CK"#&OP@<"A!3ND%9S*EA'6D3JLC"T6<9:`!E;3O(&G94
7b26da
+MIT-`CL3%A?;_(NKY1#S-PYZ#Q/58AEZZY4LG'0B(3B$`4$0P0_XNY(IPH2%8
7b26da
+#Y"5.
7b26da
+`
7b26da
+end
7b26da
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.debug.bz2.uu
7b26da
===================================================================
7b26da
--- /dev/null
7b26da
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/cordic.ko.debug.bz2.uu
7b26da
@@ -0,0 +1,24 @@
7b26da
+begin 664 cordic.ko.debug.bz2.uu
7b26da
+M0EIH.3%!62936;;3U;4``^=______^==:W]63^U^1+_O_V"H4V#`)$A@F@90
7b26da
+M"D$!"""2P`,!Q0-*1AHB-4])ZGI-#3U`T:8C0``-``-`:-#0`:#T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