linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated
@ 2016-12-19 16:18 Markus Trippelsdorf
  2016-12-19 16:52 ` Markus Trippelsdorf
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Trippelsdorf @ 2016-12-19 16:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arnaldo Carvalho de Melo, Ingo Molnar

Running the latest kernel git tree, I get buffer overflow warnings when
I try to run "perf top":

*** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated        

__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51      }
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff5f29cbb in __GI_abort () at abort.c:89
#2  0x00007ffff5f6f553 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff6056455 "*** %s ***: %s terminated\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff600d8c7 in __GI___fortify_fail (msg=msg@entry=0x7ffff60563ec "buffer overflow detected") at fortify_fail.c:30
#4  0x00007ffff600b790 in __GI___chk_fail () at chk_fail.c:28
#5  0x00007ffff600bc35 in __read_chk (fd=fd@entry=3, buf=buf@entry=0x7fffffff48f0, nbytes=nbytes@entry=1572864, buflen=buflen@entry=8192) at read_chk.c:30
#6  0x00000000004fafc4 in read (__nbytes=1572864, __buf=0x7fffffff48f0, __fd=3) at /usr/include/bits/unistd.h:39
#7  sysfs__read_build_id (filename=filename@entry=0x7fffffff6940 "/sys/kernel/notes", build_id=build_id@entry=0x1db5e34, size=size@entry=20) at util/symbol-elf.c:540
#8  0x00000000004a8c22 in dso__read_running_kernel_build_id (dso=dso@entry=0x1db5d70, machine=machine@entry=0x1db5ab8) at util/dso.c:1152
#9  0x00000000004b875a in machine__get_kernel (machine=machine@entry=0x1db5ab8) at util/machine.c:715
#10 0x00000000004ba0ab in machine__create_kernel_maps (machine=machine@entry=0x1db5ab8) at util/machine.c:1127
#11 0x00000000004bf169 in perf_session__create_kernel_maps (session=session@entry=0x1db59d0) at util/session.c:70
#12 0x00000000004bf43b in perf_session__new (file=file@entry=0x0, repipe=repipe@entry=false, tool=tool@entry=0x0) at util/session.c:154
#13 0x0000000000441eca in __cmd_top (top=0x7fffffff8a70) at builtin-top.c:925
#14 cmd_top (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-top.c:1330
#15 0x0000000000487481 in run_builtin (p=p@entry=0x679d78 <commands+312>, argc=argc@entry=2, argv=argv@entry=0x7fffffffe4c0) at perf.c:358
#16 0x0000000000487722 in handle_internal_command (argc=2, argv=0x7fffffffe4c0) at perf.c:420
#17 0x0000000000487982 in run_argv (argv=0x7fffffffe250, argcp=0x7fffffffe25c) at perf.c:466
#18 main (argc=<optimized out>, argv=<optimized out>) at perf.c:610

(gdb) up
#7  sysfs__read_build_id (filename=filename@entry=0x7fffffff6940 "/sys/kernel/notes", build_id=build_id@entry=0x1db5e34, size=size@entry=20) at util/symbol-elf.c:540
540                             if (read(fd, bf, n) != n)
(gdb) l
535                                     }
536                             } else if (read(fd, bf, descsz) != (ssize_t)descsz)
537                                     break;
538                     } else {
539                             int n = namesz + descsz;
540                             if (read(fd, bf, n) != n)
541                                     break;
542                     }
543             }
544             close(fd);

(gdb) p n
$4 = 1572864
(gdb) p BUFSIZ
$5 = 8192


-- 
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated
  2016-12-19 16:18 *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated Markus Trippelsdorf
@ 2016-12-19 16:52 ` Markus Trippelsdorf
  2016-12-19 17:28   ` Markus Trippelsdorf
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Trippelsdorf @ 2016-12-19 16:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arnaldo Carvalho de Melo, Ingo Molnar

On 2016.12.19 at 17:18 +0100, Markus Trippelsdorf wrote:
> Running the latest kernel git tree, I get buffer overflow warnings when
> I try to run "perf top":
> 
> *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated        
> 
> __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
> 51      }
> (gdb) bt
> #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
> #1  0x00007ffff5f29cbb in __GI_abort () at abort.c:89
> #2  0x00007ffff5f6f553 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff6056455 "*** %s ***: %s terminated\n") at ../sysdeps/posix/libc_fatal.c:175
> #3  0x00007ffff600d8c7 in __GI___fortify_fail (msg=msg@entry=0x7ffff60563ec "buffer overflow detected") at fortify_fail.c:30
> #4  0x00007ffff600b790 in __GI___chk_fail () at chk_fail.c:28
> #5  0x00007ffff600bc35 in __read_chk (fd=fd@entry=3, buf=buf@entry=0x7fffffff48f0, nbytes=nbytes@entry=1572864, buflen=buflen@entry=8192) at read_chk.c:30
> #6  0x00000000004fafc4 in read (__nbytes=1572864, __buf=0x7fffffff48f0, __fd=3) at /usr/include/bits/unistd.h:39
> #7  sysfs__read_build_id (filename=filename@entry=0x7fffffff6940 "/sys/kernel/notes", build_id=build_id@entry=0x1db5e34, size=size@entry=20) at util/symbol-elf.c:540
> #8  0x00000000004a8c22 in dso__read_running_kernel_build_id (dso=dso@entry=0x1db5d70, machine=machine@entry=0x1db5ab8) at util/dso.c:1152
> #9  0x00000000004b875a in machine__get_kernel (machine=machine@entry=0x1db5ab8) at util/machine.c:715
> #10 0x00000000004ba0ab in machine__create_kernel_maps (machine=machine@entry=0x1db5ab8) at util/machine.c:1127
> #11 0x00000000004bf169 in perf_session__create_kernel_maps (session=session@entry=0x1db59d0) at util/session.c:70
> #12 0x00000000004bf43b in perf_session__new (file=file@entry=0x0, repipe=repipe@entry=false, tool=tool@entry=0x0) at util/session.c:154
> #13 0x0000000000441eca in __cmd_top (top=0x7fffffff8a70) at builtin-top.c:925
> #14 cmd_top (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-top.c:1330
> #15 0x0000000000487481 in run_builtin (p=p@entry=0x679d78 <commands+312>, argc=argc@entry=2, argv=argv@entry=0x7fffffffe4c0) at perf.c:358
> #16 0x0000000000487722 in handle_internal_command (argc=2, argv=0x7fffffffe4c0) at perf.c:420
> #17 0x0000000000487982 in run_argv (argv=0x7fffffffe250, argcp=0x7fffffffe25c) at perf.c:466
> #18 main (argc=<optimized out>, argv=<optimized out>) at perf.c:610
> 
> (gdb) up
> #7  sysfs__read_build_id (filename=filename@entry=0x7fffffff6940 "/sys/kernel/notes", build_id=build_id@entry=0x1db5e34, size=size@entry=20) at util/symbol-elf.c:540
> 540                             if (read(fd, bf, n) != n)
> (gdb) l
> 535                                     }
> 536                             } else if (read(fd, bf, descsz) != (ssize_t)descsz)
> 537                                     break;
> 538                     } else {
> 539                             int n = namesz + descsz;
> 540                             if (read(fd, bf, n) != n)
> 541                                     break;
> 542                     }
> 543             }
> 544             close(fd);
> 
> (gdb) p n
> $4 = 1572864
> (gdb) p BUFSIZ
> $5 = 8192

It only happens when I link my kernel with gold.

(with ld.bfd)
markus@x4 linux % readelf -n vmlinux

Displaying notes found in: .notes
  Owner                 Data size       Description
  GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: 74b478c2194c0ba07481acf30f6f8781d4ffcdee

(with ld.gold)
markus@x4 linux % readelf -n vmlinux

Displaying notes found in: .note.gnu.build-id
  Owner                 Data size       Description
  GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: 017ef6e6f8ce3b44332d0baa0767526bb3a77bf8

Displaying notes found in: .note.gnu.gold-version
  Owner                 Data size       Description
  GNU                  0x00000009       NT_GNU_GOLD_VERSION (gold version)
    Version: gold 1.12

And perf than chokes when parsing /sys/kernel/notes.

-- 
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated
  2016-12-19 16:52 ` Markus Trippelsdorf
@ 2016-12-19 17:28   ` Markus Trippelsdorf
  2016-12-19 18:37     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Trippelsdorf @ 2016-12-19 17:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arnaldo Carvalho de Melo, Ingo Molnar

On 2016.12.19 at 17:52 +0100, Markus Trippelsdorf wrote:
> On 2016.12.19 at 17:18 +0100, Markus Trippelsdorf wrote:
> > Running the latest kernel git tree, I get buffer overflow warnings when
> > I try to run "perf top":
> > 
> > *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated        
> 
> It only happens when I link my kernel with gold.
> 
> (with ld.bfd)
> markus@x4 linux % readelf -n vmlinux
> 
> Displaying notes found in: .notes
>   Owner                 Data size       Description
>   GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
>     Build ID: 74b478c2194c0ba07481acf30f6f8781d4ffcdee
> 
> (with ld.gold)
> markus@x4 linux % readelf -n vmlinux
> 
> Displaying notes found in: .note.gnu.build-id
>   Owner                 Data size       Description
>   GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
>     Build ID: 017ef6e6f8ce3b44332d0baa0767526bb3a77bf8
> 
> Displaying notes found in: .note.gnu.gold-version
>   Owner                 Data size       Description
>   GNU                  0x00000009       NT_GNU_GOLD_VERSION (gold version)
>     Version: gold 1.12
> 
> And perf than chokes when parsing /sys/kernel/notes.

Started with gold commit:

 commit bfbf34de2f27672282d4fa4c0916cc41890dcc6c
 Author: Cary Coutant <ccoutant@gmail.com>
 Date:   Mon Dec 12 18:51:29 2016 -0800

    When using linker scripts, place linker-generated sections by the output section name.

I've opened a gold bug:
https://sourceware.org/bugzilla/show_bug.cgi?id=20983

-- 
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated
  2016-12-19 17:28   ` Markus Trippelsdorf
@ 2016-12-19 18:37     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-12-19 18:37 UTC (permalink / raw)
  To: Markus Trippelsdorf; +Cc: linux-kernel, Ingo Molnar

Em Mon, Dec 19, 2016 at 06:28:42PM +0100, Markus Trippelsdorf escreveu:
> On 2016.12.19 at 17:52 +0100, Markus Trippelsdorf wrote:
> > On 2016.12.19 at 17:18 +0100, Markus Trippelsdorf wrote:
> > > Running the latest kernel git tree, I get buffer overflow warnings when
> > > I try to run "perf top":
> > > 
> > > *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated        
> > 
> > It only happens when I link my kernel with gold.
<SNIP>
> > And perf than chokes when parsing /sys/kernel/notes.
> 
> Started with gold commit:
> 
>  commit bfbf34de2f27672282d4fa4c0916cc41890dcc6c
>  Author: Cary Coutant <ccoutant@gmail.com>
>  Date:   Mon Dec 12 18:51:29 2016 -0800
> 
>     When using linker scripts, place linker-generated sections by the output section name.
> 
> I've opened a gold bug:
> https://sourceware.org/bugzilla/show_bug.cgi?id=20983

I guess we need something along the lines of below, but I think the max
should be set to the filesize, have to spend some more time here, using
stat() in such case, etc, wdyt?

- Arnaldo

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 99400b0e8f2a..adbc6c02c3aa 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -537,6 +537,12 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
 				break;
 		} else {
 			int n = namesz + descsz;
+
+			if (n > (int)sizeof(bf)) {
+				n = sizeof(bf);
+				pr_debug("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n",
+					 __func__, filename, nhdr.n_namesz, nhdr.n_descsz);
+			}
 			if (read(fd, bf, n) != n)
 				break;
 		}

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-19 18:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19 16:18 *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated Markus Trippelsdorf
2016-12-19 16:52 ` Markus Trippelsdorf
2016-12-19 17:28   ` Markus Trippelsdorf
2016-12-19 18:37     ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).