* [PATCH] perf/arm_brbe: fix shift-out-of-bounds in brbinf_get_cycles()
@ 2026-11-29 20:02 Sawan H N
2026-11-29 20:05 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Sawan H N @ 2026-11-29 20:02 UTC (permalink / raw)
To: will, mark.rutland, anshuman.khandual, robh
Cc: linux-arm-kernel, linux-perf-users, linux-kernel,
ganapatrao.kulkarni, trilok.soni, ashok.raj, jonathan.cameron,
Sawan H N, stable
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 <sawan.n@oss.qualcomm.com>
Reviewed-by: Ashok Raj <ashok.raj@oss.qualcomm.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] perf/arm_brbe: fix shift-out-of-bounds in brbinf_get_cycles()
2026-11-29 20:02 [PATCH] perf/arm_brbe: fix shift-out-of-bounds in brbinf_get_cycles() Sawan H N
@ 2026-11-29 20:05 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 20:05 UTC (permalink / raw)
To: Sawan H N; +Cc: linux-perf-users
> 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 <sawan.n@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129200217.3193798-1-sawan.n@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 20:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 20:02 [PATCH] perf/arm_brbe: fix shift-out-of-bounds in brbinf_get_cycles() Sawan H N
2026-11-29 20:05 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox