Skip to contentSkip to conversation

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

DISCUSSION Markus Trippelsdorf 2 participants 4 messages Dec 19, 2016 perf events

lore
Share & tools
lore
#0 lore raw

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

Signature · 1 line
Markus
#1 lore raw
Quoted 43 lines · Markus Trippelsdorf

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);

Quoted 4 lines

(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.

Signature · 1 line
Markus
#2 lore raw
Quoted 22 lines · Markus Trippelsdorf
Quoted 4 lines · Markus Trippelsdorf

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)

Quoted 8 lines
    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 <[email protected]>
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

Signature · 1 line
Markus
#3 lore raw

Em Mon, Dec 19, 2016 at 06:28:42PM +0100, Markus Trippelsdorf escreveu:

Quoted 8 lines · Markus Trippelsdorf
Quoted 7 lines · Markus Trippelsdorf
Quoted 4 lines

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>

Quoted 4 lines
Quoted 1 line

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

Started with gold commit:

Quoted 8 lines

commit bfbf34de2f27672282d4fa4c0916cc41890dcc6c
Author: Cary Coutant <[email protected]>
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

tools/perf/util/symbol-elf.c +6 -0
index 99400b0e8f2a..adbc6c02c3aa 100644
@@ -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;
 		}