diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-01-03 13:19:21 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-01-03 14:11:13 -0500 |
commit | 7934c98a6e04028eb34c1293bfb5a6b0ab630b66 (patch) | |
tree | ec22e578f2c48c53d41b1e0413cf7b21c6f66749 /tools | |
parent | 30a9c6444810429aa2b7cbfbd453ce339baaadbf (diff) |
perf symbols: Robustify reading of build-id from sysfs
Markus reported that perf segfaults when reading /sys/kernel/notes from
a kernel linked with GNU gold, due to what looks like a gold bug, so do
some bounds checking to avoid crashing in that case.
Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Report-Link: http://lkml.kernel.org/r/20161219161821.GA294@x4
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ryhgs6a6jxvz207j2636w31c@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/symbol-elf.c | 6 |
1 files changed, 6 insertions, 0 deletions
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) | |||
537 | break; | 537 | break; |
538 | } else { | 538 | } else { |
539 | int n = namesz + descsz; | 539 | int n = namesz + descsz; |
540 | |||
541 | if (n > (int)sizeof(bf)) { | ||
542 | n = sizeof(bf); | ||
543 | pr_debug("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n", | ||
544 | __func__, filename, nhdr.n_namesz, nhdr.n_descsz); | ||
545 | } | ||
540 | if (read(fd, bf, n) != n) | 546 | if (read(fd, bf, n) != n) |
541 | break; | 547 | break; |
542 | } | 548 | } |