• Arnaldo Carvalho de Melo's avatar
    perf evsel: Do not access outside hw cache name arrays · c53412ee
    Arnaldo Carvalho de Melo authored
    We have to check if the values are >= *_MAX, not just >, fix it.
    
    From the bugzilla report:
    
    ''In file /tools/perf/util/evsel.c  function __perf_evsel__hw_cache_name
    it appears that there is a bug that reads beyond the end of the buffer.
    The statement "if (type > PERF_COUNT_HW_CACHE_MAX)" allows type to be
    equal to the maximum value. Later, when statement "if
    (!perf_evsel__is_cache_op_valid(type, op))" is executed, the function
    can access array perf_evsel__hw_cache_stat[type] beyond the end of the
    buffer.
    
    It appears to me that the statement "if (type > PERF_COUNT_HW_CACHE_MAX)"
    should be "if (type >= PERF_COUNT_HW_CACHE_MAX)"
    
    Bug found with Coverity and manual code review. No attempts were made to
    execute the code with a maximum type value.''
    
    Committer note:
    
    Testing it:
    
      $ perf record -e $(echo $(perf list cache | cut -d \[ -f1) | sed 's/ /,/g') usleep 1
      [ perf record: Woken up 16 times to write data ]
      [ perf record: Captured and wrote 0.023 MB perf.data (34 samples) ]
      $ perf evlist
      L1-dcache-load-misses
      L1-dcache-loads
      L1-dcache-stores
      L1-icache-load-misses
      LLC-load-misses
      LLC-loads
      LLC-store-misses
      LLC-stores
      branch-load-misses
      branch-loads
      dTLB-load-misses
      dTLB-loads
      dTLB-store-misses
      dTLB-stores
      iTLB-load-misses
      iTLB-loads
      node-load-misses
      node-loads
      node-store-misses
      node-stores
      $ perf list cache
    
      List of pre-defined events (to be used in -e):
    
        L1-dcache-load-misses        [Hardware cache event]
        L1-dcache-loads              [Hardware cache event]
        L1-dcache-stores             [Hardware cache event]
        L1-icache-load-misses        [Hardware cache event]
        LLC-load-misses              [Hardware cache event]
        LLC-loads                    [Hardware cache event]
        LLC-store-misses             [Hardware cache event]
        LLC-stores                   [Hardware cache event]
        branch-load-misses           [Hardware cache event]
        branch-loads                 [Hardware cache event]
        dTLB-load-misses             [Hardware cache event]
        dTLB-loads                   [Hardware cache event]
        dTLB-store-misses            [Hardware cache event]
        dTLB-stores                  [Hardware cache event]
        iTLB-load-misses             [Hardware cache event]
        iTLB-loads                   [Hardware cache event]
        node-load-misses             [Hardware cache event]
        node-loads                   [Hardware cache event]
        node-store-misses            [Hardware cache event]
        node-stores                  [Hardware cache event]
      $
    Reported-by: default avatarBrian Sweeney <bsweeney@lgsinnovations.com>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=153351Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    c53412ee
Name
Last commit
Last update
..
include Loading commit data...
intel-pt-decoder Loading commit data...
libunwind Loading commit data...
scripting-engines Loading commit data...
Build Loading commit data...
PERF-VERSION-GEN Loading commit data...
alias.c Loading commit data...
annotate.c Loading commit data...
annotate.h Loading commit data...
auxtrace.c Loading commit data...
auxtrace.h Loading commit data...
bpf-loader.c Loading commit data...
bpf-loader.h Loading commit data...
bpf-prologue.c Loading commit data...
bpf-prologue.h Loading commit data...
build-id.c Loading commit data...
build-id.h Loading commit data...
cache.h Loading commit data...
call-path.c Loading commit data...
call-path.h Loading commit data...
callchain.c Loading commit data...
callchain.h Loading commit data...
cgroup.c Loading commit data...
cgroup.h Loading commit data...
cloexec.c Loading commit data...
cloexec.h Loading commit data...
color.c Loading commit data...
color.h Loading commit data...
comm.c Loading commit data...
comm.h Loading commit data...
config.c Loading commit data...
config.h Loading commit data...
counts.c Loading commit data...
counts.h Loading commit data...
cpumap.c Loading commit data...
cpumap.h Loading commit data...
ctype.c Loading commit data...
data-convert-bt.c Loading commit data...
data-convert-bt.h Loading commit data...
data-convert.h Loading commit data...
data.c Loading commit data...
data.h Loading commit data...
db-export.c Loading commit data...
db-export.h Loading commit data...
debug.c Loading commit data...
debug.h Loading commit data...
demangle-java.c Loading commit data...
demangle-java.h Loading commit data...
demangle-rust.c Loading commit data...
demangle-rust.h Loading commit data...
dso.c Loading commit data...
dso.h Loading commit data...
dwarf-aux.c Loading commit data...
dwarf-aux.h Loading commit data...
env.c Loading commit data...
env.h Loading commit data...
event.c Loading commit data...
event.h Loading commit data...
evlist.c Loading commit data...
evlist.h Loading commit data...
evsel.c Loading commit data...
evsel.h Loading commit data...
evsel_fprintf.c Loading commit data...
find-vdso-map.c Loading commit data...
genelf.c Loading commit data...
genelf.h Loading commit data...
genelf_debug.c Loading commit data...
generate-cmdlist.sh Loading commit data...
group.h Loading commit data...
header.c Loading commit data...
header.h Loading commit data...
help-unknown-cmd.c Loading commit data...
help-unknown-cmd.h Loading commit data...
hist.c Loading commit data...
hist.h Loading commit data...
intel-bts.c Loading commit data...
intel-bts.h Loading commit data...
intel-pt.c Loading commit data...
intel-pt.h Loading commit data...
intlist.c Loading commit data...
intlist.h Loading commit data...
jit.h Loading commit data...
jitdump.c Loading commit data...
jitdump.h Loading commit data...
kvm-stat.h Loading commit data...
levenshtein.c Loading commit data...
levenshtein.h Loading commit data...
llvm-utils.c Loading commit data...
llvm-utils.h Loading commit data...
lzma.c Loading commit data...
machine.c Loading commit data...
machine.h Loading commit data...
map.c Loading commit data...
map.h Loading commit data...
mem-events.c Loading commit data...
mem-events.h Loading commit data...
ordered-events.c Loading commit data...
ordered-events.h Loading commit data...
parse-branch-options.c Loading commit data...
parse-branch-options.h Loading commit data...
parse-events.c Loading commit data...
parse-events.h Loading commit data...
parse-events.l Loading commit data...
parse-events.y Loading commit data...
parse-regs-options.c Loading commit data...
parse-regs-options.h Loading commit data...
path.c Loading commit data...
perf_regs.c Loading commit data...
perf_regs.h Loading commit data...
pmu.c Loading commit data...
pmu.h Loading commit data...
pmu.l Loading commit data...
pmu.y Loading commit data...
probe-event.c Loading commit data...
probe-event.h Loading commit data...
probe-file.c Loading commit data...
probe-file.h Loading commit data...
probe-finder.c Loading commit data...
probe-finder.h Loading commit data...
pstack.c Loading commit data...
pstack.h Loading commit data...
python-ext-sources Loading commit data...
python.c Loading commit data...
quote.c Loading commit data...
quote.h Loading commit data...
rb_resort.h Loading commit data...
rblist.c Loading commit data...
rblist.h Loading commit data...
record.c Loading commit data...
session.c Loading commit data...
session.h Loading commit data...
setup.py Loading commit data...
sort.c Loading commit data...
sort.h Loading commit data...
srcline.c Loading commit data...
stat-shadow.c Loading commit data...
stat.c Loading commit data...
stat.h Loading commit data...
strbuf.c Loading commit data...
strbuf.h Loading commit data...
strfilter.c Loading commit data...
strfilter.h Loading commit data...
string.c Loading commit data...
strlist.c Loading commit data...
strlist.h Loading commit data...
svghelper.c Loading commit data...
svghelper.h Loading commit data...
symbol-elf.c Loading commit data...
symbol-minimal.c Loading commit data...
symbol.c Loading commit data...
symbol.h Loading commit data...
symbol_fprintf.c Loading commit data...
syscalltbl.c Loading commit data...
syscalltbl.h Loading commit data...
target.c Loading commit data...
target.h Loading commit data...
term.c Loading commit data...
term.h Loading commit data...
thread-stack.c Loading commit data...
thread-stack.h Loading commit data...
thread.c Loading commit data...
thread.h Loading commit data...
thread_map.c Loading commit data...
thread_map.h Loading commit data...
tool.h Loading commit data...
top.c Loading commit data...
top.h Loading commit data...
trace-event-info.c Loading commit data...
trace-event-parse.c Loading commit data...
trace-event-read.c Loading commit data...
trace-event-scripting.c Loading commit data...
trace-event.c Loading commit data...
trace-event.h Loading commit data...
trigger.h Loading commit data...
tsc.c Loading commit data...
tsc.h Loading commit data...
unwind-libdw.c Loading commit data...
unwind-libdw.h Loading commit data...
unwind-libunwind-local.c Loading commit data...
unwind-libunwind.c Loading commit data...
unwind.h Loading commit data...
usage.c Loading commit data...
util.c Loading commit data...
util.h Loading commit data...
values.c Loading commit data...
values.h Loading commit data...
vdso.c Loading commit data...
vdso.h Loading commit data...
xyarray.c Loading commit data...
xyarray.h Loading commit data...
zlib.c Loading commit data...