linux/tools/perf/tests
Leo Yan af8490eb2b perf tests: Fix out of bounds memory access
The test case 'Read backward ring buffer' failed on 32-bit architectures
which were found by LKFT perf testing.  The test failed on arm32 x15
device, qemu_arm32, qemu_i386, and found intermittent failure on i386;
the failure log is as below:

  50: Read backward ring buffer                  :
  --- start ---
  test child forked, pid 510
  Using CPUID GenuineIntel-6-9E-9
  mmap size 1052672B
  mmap size 8192B
  Finished reading overwrite ring buffer: rewind
  free(): invalid next size (fast)
  test child interrupted
  ---- end ----
  Read backward ring buffer: FAILED!

The log hints there have issue for memory usage, thus free() reports
error 'invalid next size' and directly exit for the case.  Finally, this
issue is root caused as out of bounds memory access for the data array
'evsel->id'.

The backward ring buffer test invokes do_test() twice.  'evsel->id' is
allocated at the first call with the flow:

  test__backward_ring_buffer()
    `-> do_test()
	  `-> evlist__mmap()
	        `-> evlist__mmap_ex()
	              `-> perf_evsel__alloc_id()

So 'evsel->id' is allocated with one item, and it will be used in
function perf_evlist__id_add():

   evsel->id[0] = id
   evsel->ids   = 1

At the second call for do_test(), it skips to initialize 'evsel->id'
and reuses the array which is allocated in the first call.  But
'evsel->ids' contains the stale value.  Thus:

   evsel->id[1] = id    -> out of bound access
   evsel->ids   = 2

To fix this issue, we will use evlist__open() and evlist__close() pair
functions to prepare and cleanup context for evlist; so 'evsel->id' and
'evsel->ids' can be initialized properly when invoke do_test() and avoid
the out of bounds memory access.

Fixes: ee74701ed8 ("perf tests: Add test to check backward ring buffer")
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naresh Kamboju <naresh.kamboju@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: stable@vger.kernel.org # v4.10+
Link: http://lore.kernel.org/lkml/20191107020244.2427-1-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-07 09:04:22 -03:00
..
attr perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
shell perf tests: Fixes hang in zstd compression test by changing the source of random data 2019-08-26 11:58:29 -03:00
.gitignore perf test: Add libbpf relocation checker 2016-01-26 12:10:55 -03:00
attr.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
attr.py perf script python: Add Python3 support to tests/attr.py 2019-02-05 10:31:08 -03:00
backward-ring-buffer.c perf tests: Fix out of bounds memory access 2019-11-07 09:04:22 -03:00
bitmap.c perf env: Remove needless cpumap.h header 2019-09-20 09:19:21 -03:00
bp_account.c perf tests bp_account: Add dedicated checking helper is_supported() 2019-10-19 15:35:01 -03:00
bp_signal_overflow.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
bp_signal.c perf tests: Fix a typo 2019-11-06 15:43:05 -03:00
bpf-script-example.c perf tests: Add missing SPDX headers 2019-06-17 15:57:19 -03:00
bpf-script-test-kbuild.c perf tests: Add missing SPDX headers 2019-06-17 15:57:19 -03:00
bpf-script-test-prologue.c perf tests: Add missing SPDX headers 2019-06-17 15:57:19 -03:00
bpf-script-test-relocation.c perf tests: Add missing SPDX headers 2019-06-17 15:57:19 -03:00
bpf.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
Build perf tests: Add missing SPDX headers 2019-06-17 15:57:19 -03:00
builtin-test.c perf tests bp_account: Add dedicated checking helper is_supported() 2019-10-19 15:35:01 -03:00
clang.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
code-reading.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
cpumap.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
dso-data.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
dwarf-unwind.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
event_update.c libperf: Add perf_evlist__id_add() function 2019-09-25 09:51:48 -03:00
event-times.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
evsel-roundtrip-name.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
evsel-tp-sched.c perf evsel: Rename perf_evsel__delete() to evsel__delete() 2019-07-29 18:34:43 -03:00
expr.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
fdarray.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hists_common.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
hists_common.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hists_cumulate.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
hists_filter.c perf tools: Remove needless thread.h include directives 2019-08-31 22:24:10 -03:00
hists_link.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
hists_output.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
is_printable_array.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
keep-tracking.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
kmod-path.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
llvm.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
llvm.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
make perf tests: Fix static build test 2019-09-20 14:37:28 -03:00
map_groups.c perf map_groups: Introduce for_each_entry() and for_each_entry_safe() iterators 2019-11-06 15:49:39 -03:00
mem2node.c perf env: Remove needless cpumap.h header 2019-09-20 09:19:21 -03:00
mem.c perf symbols: Move mem_info and branch_info out of symbol.h 2019-08-31 22:27:48 -03:00
mmap-basic.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
mmap-thread-lookup.c libperf: Move 'page_size' global variable to libperf 2019-09-25 09:51:48 -03:00
openat-syscall-all-cpus.c perf env: Remove needless cpumap.h header 2019-09-20 09:19:21 -03:00
openat-syscall-tp-fields.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
openat-syscall.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
parse-events.c libperf: Add perf_evlist__first()/last() functions 2019-09-25 09:51:48 -03:00
parse-no-sample-id-all.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
perf-hooks.c perf tests: Avoid raising SEGV using an obvious NULL dereference 2019-09-27 09:26:14 -03:00
perf-record.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
perf-targz-src-pkg License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pmu.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
python-use.c perf test: Use header file util/debug.h 2018-06-04 10:28:53 -03:00
sample-parsing.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
sdt.c perf tools: No need to include internal/lib.h from util/util.h 2019-09-25 09:51:48 -03:00
stat.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
sw-clock.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
switch-tracking.c libperf: Adopt perf_mmap__read_event() from tools/perf 2019-10-10 11:49:46 -03:00
task-exit.c perf test: Avoid infinite loop for task exit case 2019-10-15 08:36:22 -03:00
tests.h perf tests bp_account: Add dedicated checking helper is_supported() 2019-10-19 15:35:01 -03:00
thread-map.c perf tools: Move event synthesizing routines to separate header 2019-09-20 09:19:22 -03:00
thread-mg-share.c perf tools: Remove needless map.h include directives 2019-08-31 22:24:10 -03:00
time-utils-test.c perf evlist: Rename struct perf_evlist to struct evlist 2019-07-29 18:34:42 -03:00
topology.c perf session: Return error code for perf_session__new() function on failure 2019-09-20 15:58:11 -03:00
unit_number__scnprintf.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
vmlinux-kallsyms.c perf maps: Add for_each_entry()/_safe() iterators 2019-11-06 15:49:25 -03:00
wp.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00