brbinf_get_cycles() computes (mant | 0x100) << (exp - 1) in a u32, but CC_EXP is a 6-bit field, so the shift can reach 62. Shifting by 32 or more is undefined: UBSAN reports it during "perf record -j any", and in practice the shift count wraps, so exp == 33 yields a tiny cycle count instead of a saturated one. UBSAN: shift-out-of-bounds in drivers/perf/arm_brbe.c:200:26 shift exponent 62 is too large for 32-bit type 'unsigned int' Since (mant | 0x100) is 9 bits, the result exceeds U16_MAX once exp >= 9. Return U16_MAX for that case before shifting, which bounds the shift to 7 on the remaining path. The min() clamp is then redundant and is dropped. Decoding for exp < 9 is unchanged. Fixes: 58074a0fce66 ("perf: arm_pmuv3: Add support for the Branch Record Buffer Extension (BRBE)") Cc: stable@vger.kernel.org # 6.17+ Signed-off-by: Sawan H N Reviewed-by: Ashok Raj --- drivers/perf/arm_brbe.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c index 073d14584741..ee096d8eb2e5 100644 --- a/drivers/perf/arm_brbe.c +++ b/drivers/perf/arm_brbe.c @@ -187,9 +187,13 @@ static u16 brbinf_get_cycles(u64 brbinf) if (!exp) return mant; + /* (mant | 0x100) << (exp - 1) exceeds U16_MAX from exp == 9 */ + if (exp >= 9) + return U16_MAX; + cycles = (mant | 0x100) << (exp - 1); - return min(cycles, U16_MAX); + return cycles; } static int brbinf_get_type(u64 brbinf) -- 2.34.1