From: Sawan H N <sawan.n@oss.qualcomm.com>
To: will@kernel.org, mark.rutland@arm.com, anshuman.khandual@arm.com,
robh@kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
ganapatrao.kulkarni@oss.qualcomm.com,
trilok.soni@oss.qualcomm.com, ashok.raj@oss.qualcomm.com,
jonathan.cameron@oss.qualcomm.com,
Sawan H N <sawan.n@oss.qualcomm.com>,
stable@vger.kernel.org
Subject: [PATCH] perf/arm_brbe: fix shift-out-of-bounds in brbinf_get_cycles()
Date: Mon, 30 Nov 2026 01:32:17 +0530 [thread overview]
Message-ID: <20261129200217.3193798-1-sawan.n@oss.qualcomm.com> (raw)
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
reply other threads:[~2026-11-29 20:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129200217.3193798-1-sawan.n@oss.qualcomm.com \
--to=sawan.n@oss.qualcomm.com \
--cc=anshuman.khandual@arm.com \
--cc=ashok.raj@oss.qualcomm.com \
--cc=ganapatrao.kulkarni@oss.qualcomm.com \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=trilok.soni@oss.qualcomm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®