Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf intel-pt: Fix unassigned instruction op (discovered by MemorySanitizer)

MemorySanitizer discovered instances where the instruction op value was
not assigned.:

WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x5581c00a76b3 in intel_pt_sample_flags tools/perf/util/intel-pt.c:1527:17
Uninitialized value was stored to memory at
#0 0x5581c005ddf8 in intel_pt_walk_insn tools/perf/util/intel-pt-decoder/intel-pt-decoder.c:1256:25

The op value is used to set branch flags for branch instructions
encountered when walking the code, so fix by setting op to
INTEL_PT_OP_OTHER in other cases.

Fixes: 4c761d805bb2d2ea ("perf intel-pt: Fix intel_pt_fup_event() assumptions about setting state type")
Reported-by: Ian Rogers <irogers@google.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Closes: https://lore.kernel.org/linux-perf-users/20240320162619.1272015-1-irogers@google.com/
Link: https://lore.kernel.org/r/20240326083223.10883-1-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
e101a05f 7cc72090

+4
+2
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
··· 1319 1319 bool ret = false; 1320 1320 1321 1321 decoder->state.type &= ~INTEL_PT_BRANCH; 1322 + decoder->state.insn_op = INTEL_PT_OP_OTHER; 1323 + decoder->state.insn_len = 0; 1322 1324 1323 1325 if (decoder->set_fup_cfe_ip || decoder->set_fup_cfe) { 1324 1326 bool ip = decoder->set_fup_cfe_ip;
+2
tools/perf/util/intel-pt.c
··· 764 764 765 765 addr_location__init(&al); 766 766 intel_pt_insn->length = 0; 767 + intel_pt_insn->op = INTEL_PT_OP_OTHER; 767 768 768 769 if (to_ip && *ip == to_ip) 769 770 goto out_no_cache; ··· 899 898 900 899 if (to_ip && *ip == to_ip) { 901 900 intel_pt_insn->length = 0; 901 + intel_pt_insn->op = INTEL_PT_OP_OTHER; 902 902 goto out_no_cache; 903 903 } 904 904