]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf: arm_spe: Prevent overflow in PERF_IDX2OFF()
authorLeo Yan <leo.yan@arm.com>
Wed, 17 Sep 2025 17:41:39 +0000 (18:41 +0100)
committerWill Deacon <will@kernel.org>
Thu, 18 Sep 2025 14:23:59 +0000 (15:23 +0100)
Cast nr_pages to unsigned long to avoid overflow when handling large
AUX buffer sizes (>= 2 GiB).

Fixes: d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension")
Signed-off-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
drivers/perf/arm_spe_pmu.c

index 591f72fa032760b011ab88949744c4069485a493..fa50645feddadbea5dc1e404f80f62cf5aa96fd4 100644 (file)
@@ -99,7 +99,8 @@ struct arm_spe_pmu {
 #define to_spe_pmu(p) (container_of(p, struct arm_spe_pmu, pmu))
 
 /* Convert a free-running index from perf into an SPE buffer offset */
-#define PERF_IDX2OFF(idx, buf) ((idx) % ((buf)->nr_pages << PAGE_SHIFT))
+#define PERF_IDX2OFF(idx, buf) \
+       ((idx) % ((unsigned long)(buf)->nr_pages << PAGE_SHIFT))
 
 /* Keep track of our dynamic hotplug state */
 static enum cpuhp_state arm_spe_pmu_online;