]> www.infradead.org Git - users/hch/misc.git/commitdiff
libperf mmap: In user mmap rdpmc avoid undefined behavior
authorIan Rogers <irogers@google.com>
Sun, 14 Sep 2025 18:24:37 +0000 (11:24 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Oct 2025 18:02:47 +0000 (15:02 -0300)
A shift left of a signed 64-bit s64 may overflow and result in
undefined behavior caught by ubsan. Switch to a u64 instead.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/mmap.c

index c1a51d925e0e02b38a6a83e2a3f834979902fe02..ec124eb0ec0abbcc4a395eca7478129a74309965 100644 (file)
@@ -508,7 +508,7 @@ int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count
                idx = READ_ONCE(pc->index);
                cnt = READ_ONCE(pc->offset);
                if (pc->cap_user_rdpmc && idx) {
-                       s64 evcnt = read_perf_counter(idx - 1);
+                       u64 evcnt = read_perf_counter(idx - 1);
                        u16 width = READ_ONCE(pc->pmc_width);
 
                        evcnt <<= 64 - width;