[PATCH 03/10] clk: tegra: bpmp: Bound num_parents by MRQ_CLK_MAX_PARENTS
From: Lee Jones
Date: Mon Nov 23 2026 - 11:49:44 EST
Both cmd_clk_get_all_info_response and tegra_bpmp_clk_info size their
parents arrays to MRQ_CLK_MAX_PARENTS (16), whereas response.num_parents
is an 8-bit unsigned integer received from BPMP firmware.
tegra_bpmp_clk_get_info() copies response.num_parents entries from the
stack response into the heap info structure without checking against
MRQ_CLK_MAX_PARENTS, and the caller only checks against U8_MAX after the
copy has already overflowed both arrays.
Validate that response.num_parents does not exceed MRQ_CLK_MAX_PARENTS
before copying parent IDs, and drop the redundant U8_MAX check.
Fixes: ca6f2796eef7 ("clk: tegra: Add BPMP clock driver")
Closes: https://sashiko.dev/#/bug/linux-785615f3-ab51-451a-b58c-fe29c7f09bfe
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/clk/tegra/clk-bpmp.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index 0bb28f96274f..3649324e2e1f 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -376,6 +376,13 @@ static int tegra_bpmp_clk_get_info(struct tegra_bpmp *bpmp, unsigned int id,
return -E2BIG;
}
+ if (response.num_parents > MRQ_CLK_MAX_PARENTS) {
+ dev_err(bpmp->dev,
+ "clock %u has too many parents (%u, max: %u)\n",
+ id, response.num_parents, MRQ_CLK_MAX_PARENTS);
+ return -EINVAL;
+ }
+
info->num_parents = response.num_parents;
for (i = 0; i < info->num_parents; i++)
@@ -453,13 +460,6 @@ static int tegra_bpmp_probe_clocks(struct tegra_bpmp *bpmp,
if (err < 0)
continue;
- if (info->num_parents >= U8_MAX) {
- dev_err(bpmp->dev,
- "clock %u has too many parents (%u, max: %u)\n",
- id, info->num_parents, U8_MAX);
- continue;
- }
-
/* clock not exposed by BPMP */
if (info->name[0] == '\0') {
holes++;
--
2.56.1.750.gf70dc682cf-goog