[PATCH 3/3] clk: zynqmp: Fix unchecked type index into clock topology tables
Radhey Shyam Pandey
radhey.shyam.pandey at amd.com
Mon Nov 30 22:43:53 PST 2026
From: Beesam Sridhar Sagar <sagar.beesamsridhar at amd.com>
The topology 'type' value received from firmware is stored without
validation and later used as an index into the clk_topology[]
function-pointer table and clk_type_postfix[] string table in
zynqmp_register_clk_topology().
CLK_TOPOLOGY_TYPE is a 4-bit field, allowing values in the range
0..15, while enum topology_type and the corresponding tables contain
only 7 entries. Values outside the valid range can therefore lead to
out-of-bounds accesses, including a function-pointer dereference.
Validate the topology type while parsing the firmware response and
return an error when an invalid value is detected.
Fixes: 3fde0e16d016 ("drivers: clk: Add ZynqMP clock driver")
Signed-off-by: Beesam Sridhar Sagar <sagar.beesamsridhar at amd.com>
Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey at amd.com>
---
drivers/clk/zynqmp/clkc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
index 5d827b2bb0ad..4ce376023d7f 100644
--- a/drivers/clk/zynqmp/clkc.c
+++ b/drivers/clk/zynqmp/clkc.c
@@ -418,6 +418,8 @@ static int __zynqmp_clock_get_topology(struct clock_topology *topology,
type = FIELD_GET(CLK_TOPOLOGY_TYPE, response->topology[i]);
if (type == TYPE_INVALID)
return END_OF_TOPOLOGY_NODE;
+ if (type >= ARRAY_SIZE(clk_topology))
+ return -EINVAL;
topology[*nnodes].type = type;
topology[*nnodes].flag = FIELD_GET(CLK_TOPOLOGY_FLAGS,
response->topology[i]);
@@ -459,6 +461,8 @@ static int zynqmp_clock_get_topology(u32 clk_id,
num_nodes);
if (ret == END_OF_TOPOLOGY_NODE)
return 0;
+ if (ret < 0)
+ return ret;
}
return 0;
--
2.43.0
More information about the linux-arm-kernel
mailing list